U ¯Dx`S.ã@s¤ddlmZddlmZmZddlmZddlZddlZdZ dZ dZ dZ d Z d Zd d „ZGd d„dƒZGdd„deƒZGdd„dƒZGdd„dƒZGdd„dƒZdS)é)ÚMBLENGTH)Ú FIELD_TYPEÚ SERVER_STATUS)ÚerréNFéûéüéýéþcsîdd„‰zLtdtˆƒƒtddƒD]&}t |¡}td||jj|jfƒq"tdƒWntk rhYnX‡fdd „td t tˆƒd ƒd ƒDƒ}|D]H}td   dd„|Dƒ¡dd t|ƒdd  ‡fdd„|Dƒ¡ƒq’tdƒtƒdS)NcSs$d|krdkr nnt|ƒSdS)Né éÚ.)Úchr©Údata©rú7/tmp/pip-target-zr53vnty/lib/python/pymysql/protocol.pyÚ printableszdump_packet..printablezpacket length:rézcall[%d]: %s (line %d)zB------------------------------------------------------------------csg|]}ˆ||d…‘qS)ér)Ú.0ÚirrrÚ #szdump_packet..rérú css|]}d |¡VqdS)z{:02X}N)Úformat©rÚxrrrÚ &szdump_packet..z z Úc3s|]}ˆ|ƒVqdS©Nrr)rrrr)s) ÚprintÚlenÚrangeÚsysÚ _getframeÚf_codeÚco_nameÚf_linenoÚ ValueErrorÚminÚjoin)rrÚfZ dump_dataÚdr)rrrÚ dump_packets,  $ÿþýÿr.c@sèeZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d:dd„Z d;dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9S)<Ú MysqlPacketzrRepresentation of a MySQL response packet. Provides an interface for reading/parsing the packet results. ©Ú _positionÚ_datacCsd|_||_dS)Nrr0©ÚselfrÚencodingrrrÚ__init__7szMysqlPacket.__init__cCs|jSr ©r2©r4rrrÚ get_all_data;szMysqlPacket.get_all_datacCsl|j|j|j|…}t|ƒ|krZd|t|ƒ|jt|jƒf}trRt|ƒ| ¡t|ƒ‚|j|7_|S)zCRead the first 'size' bytes in packet and advance cursor past them.z\Result length not requested length: Expected=%s. Actual=%s. Position: %s. Data Length: %s)r2r1r"ÚDEBUGr!ÚdumpÚAssertionError)r4ÚsizeÚresultÚerrorrrrÚread>s þÿzMysqlPacket.readcCs|j|jd…}d|_|S)z`Read all remaining data in the packet. (Subsequent read() will return errors.) N©r2r1©r4r>rrrÚread_allNszMysqlPacket.read_allcCs:|j|}|dks |t|jƒkr0td||fƒ‚||_dS)z1Advance the cursor in data buffer 'length' bytes.rz4Invalid advance amount (%s) for cursor. Position=%sN)r1r"r2Ú Exception)r4ÚlengthZ new_positionrrrÚadvanceWs ÿÿzMysqlPacket.advancercCs,|dks|t|jƒkr"td|ƒ‚||_dS)z9Set the position of the data buffer cursor to 'position'.rz)Invalid position to rewind cursor to: %s.N)r"r2rDr1)r4ÚpositionrrrÚrewindas zMysqlPacket.rewindrcCs|j|||…S)a>Get 'length' bytes starting at 'position'. Position is start of payload (first four packet header bytes are not included) starting at index '0'. No error checking is done. If requesting outside end of buffer an empty string (or string shorter than 'length') may be returned! r7)r4rGrErrrÚ get_bytesgs zMysqlPacket.get_bytescCs|j|j}|jd7_|S©NrrArBrrrÚ read_uint8rs zMysqlPacket.read_uint8cCs(t d|j|j¡d}|jd7_|S)NzS)NzrrrÚ read_string‹s  zMysqlPacket.read_stringcCsT| ¡}|tkrdS|tkr |S|tkr0| ¡S|tkr@| ¡S|tkrP| ¡SdS)z´Read a 'Length Coded Binary' number from the data buffer. Length coded numbers can be anywhere from 1 to 9 bytes depending on the value of the first byte. N) rKÚ NULL_COLUMNÚUNSIGNED_CHAR_COLUMNÚUNSIGNED_SHORT_COLUMNrPÚUNSIGNED_INT24_COLUMNrTÚUNSIGNED_INT64_COLUMNrX)r4ÚcrrrÚread_length_encoded_integer“sz'MysqlPacket.read_length_encoded_integercCs| ¡}|dkrdS| |¡S)aRead a 'Length Coded String' from the data buffer. A 'Length Coded String' consists first of a length coded (unsigned, positive) integer represented in 1-9 bytes followed by that many bytes of binary data. (For example "cat" would be "3cat".) N)rbr@)r4rErrrÚread_length_coded_string¥sz$MysqlPacket.read_length_coded_stringcCs.t |¡}| |j|j¡}|j|j7_|Sr )rNÚStructrOr2r1r=)r4ÚfmtÚsr>rrrÚ read_struct±s zMysqlPacket.read_structcCs|jddkot|jƒdkS)Nrr©r2r"r8rrrÚ is_ok_packet·szMysqlPacket.is_ok_packetcCs|jddkot|jƒdkS)Nrr é rhr8rrrÚ is_eof_packet»szMysqlPacket.is_eof_packetcCs|jddkS)Nrr r7r8rrrÚis_auth_switch_requestÁsz"MysqlPacket.is_auth_switch_requestcCs|jddkS)Nrrr7r8rrrÚis_extra_auth_dataÅszMysqlPacket.is_extra_auth_datacCs"|jd}d|kodkSS)Nrréúr7)r4Z field_countrrrÚis_resultset_packetÉs zMysqlPacket.is_resultset_packetcCs|jddkS)Nrrr7r8rrrÚis_load_local_packetÍsz MysqlPacket.is_load_local_packetcCs|jddkS)Nréÿr7r8rrrÚis_error_packetÐszMysqlPacket.is_error_packetcCs| ¡r| ¡dSr )rrÚraise_for_errorr8rrrÚ check_errorÓszMysqlPacket.check_errorcCs8| ¡| d¡| ¡}tr(td|ƒt |j¡dS)Nrzerrno =)rHrFrPr:r!rZraise_mysql_exceptionr2)r4Úerrnorrrrs×s   zMysqlPacket.raise_for_errorcCst|jƒdSr )r.r2r8rrrr;ßszMysqlPacket.dumpN)r)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__r6r9r@rCrFrHrIrKrPrTrVrXr[rbrcrgrirkrlrmrorprrrtrsr;rrrrr//s8    r/c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚFieldDescriptorPacketzçA MysqlPacket that represents a specific column's metadata in the result. Parsing is automatically done and the results are exported via public attributes on the class such as: db, table_name, name, length, type_code. cCst |||¡| |¡dSr )r/r6Ú_parse_field_descriptorr3rrrr6êszFieldDescriptorPacket.__init__cCsv| ¡|_| ¡|_| ¡ |¡|_| ¡ |¡|_| ¡ |¡|_| ¡ |¡|_| d¡\|_ |_ |_ |_ |_ dS)z…Parse the 'Field Descriptor' (Metadata) packet. This is compatible with MySQL 4.1+ (not compatible with MySQL 4.0). z s"  5=