ó ·\c@s#ddlmZddlmZddlmZmZddlmZm Z ddl m Z ddl m Z ddlZddlZeZd Zd Zd Zd Zd Zd „Zdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(iÿÿÿÿ(tprint_functioni(tMBLENGTH(tPY2t range_type(t FIELD_TYPEt SERVER_STATUS(terr(tbyte2intNiûiüiýiþcsDd„‰yntdt|ƒƒxFtddƒD]5}tj|ƒ}td||jj|jfƒq/WtddƒWntk rŠnXgt dt t|ƒd ƒd ƒD]}|||d !^q­}x^|D]V}td j d „|Dƒƒd d t|ƒddj ‡fd†|DƒƒƒqÑWtddƒtƒdS(NcSsCdt|ƒkodknr?t|tƒr;t|ƒS|SdS(Ni it.(Rt isinstancetinttchr(tdata((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt printables " spacket length:iiscall[%d]: %s (line %d)t-iBiiit css$|]}djt|ƒƒVqdS(s{:02X}N(tformatR(t.0tx((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pys *ss itc3s|]}ˆ|ƒVqdS(N((RR(R (s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pys ,ss ( tprinttlentrangetsyst _getframetf_codetco_nametf_linenot ValueErrorRtmintjoin(R titft dump_datatd((R s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt dump_packets  $ ? ,%t MysqlPacketcBs eZdZdZd„Zd„Zd„Zd„Zd„Zdd „Z d d „Z e rid „Z n d „Z d„Z d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS( srRepresentation of a MySQL response packet. Provides an interface for reading/parsing the packet results. t _positiont_datacCsd|_||_dS(Ni(R%R&(tselfR tencoding((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt__init__8s cCs|jS(N(R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt get_all_data<scCs“|j|j|j|!}t|ƒ|kr€d|t|ƒ|jt|jƒf}trqt|ƒ|jƒnt|ƒ‚n|j|7_|S(sCRead the first 'size' bytes in packet and advance cursor past them.s\Result length not requested length: Expected=%s. Actual=%s. Position: %s. Data Length: %s(R&R%RtDEBUGRtdumptAssertionError(R'tsizetresultterror((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytread?s%  cCs|j|j}d|_|S(s`Read all remaining data in the packet. (Subsequent read() will return errors.) N(R&R%tNone(R'R/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytread_allMs cCsT|j|}|dks.|t|jƒkrGtd||fƒ‚n||_dS(s1Advance the cursor in data buffer 'length' bytes.is4Invalid advance amount (%s) for cursor. Position=%sN(R%RR&t Exception(R'tlengtht new_position((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytadvanceVs  !icCsA|dks!|t|jƒkr4td|ƒ‚n||_dS(s9Set the position of the data buffer cursor to 'position'.is)Invalid position to rewind cursor to: %s.N(RR&R4R%(R'tposition((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytrewind^s!icCs|j|||!S(s>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! (R&(R'R8R5((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt get_bytesds cCs)t|j|jƒ}|jd7_|S(Ni(tordR&R%(R'R/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_uint8pscCs#|j|j}|jd7_|S(Ni(R&R%(R'R/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyR<uscCs2tjd|j|jƒd}|jd7_|S(NsS(NsR&R%(R'tlowthigh((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_uint24s!cCs2tjd|j|jƒd}|jd7_|S(NsR&R%(R'R/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_uint32„scCs2tjd|j|jƒd}|jd7_|S(NsR&R%(R'R/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_uint64‰scCsL|jjd|jƒ}|dkr(dS|j|j|!}|d|_|S(Nsii(R&tfindR%R2(R'tend_posR/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_stringŽs   cCsr|jƒ}|tkrdS|tkr,|S|tkrB|jƒS|tkrX|jƒS|tkrn|j ƒSdS(s´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( R<t NULL_COLUMNR2tUNSIGNED_CHAR_COLUMNtUNSIGNED_SHORT_COLUMNR?tUNSIGNED_INT24_COLUMNRBtUNSIGNED_INT64_COLUMNRD(R'tc((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytread_length_encoded_integer–s        cCs)|jƒ}|dkrdS|j|ƒS(sRead 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(RNR2R1(R'R5((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytread_length_coded_string¨s  cCs=tj|ƒ}|j|j|jƒ}|j|j7_|S(N(R=tStructR>R&R%R.(R'tfmttsR/((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt read_struct´scCs)|jdd!dko(t|jƒdkS(Niisi(R&R(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt is_ok_packetºscCs)|jdd!dko(t|jƒdkS(Niisþi (R&R(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt is_eof_packet¾scCs|jdd!dkS(Niisþ(R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytis_auth_switch_requestÄscCs|jdd!dkS(Niis(R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytis_extra_auth_dataÈscCs.t|jdd!ƒ}d|ko+dkSS(Niiiú(R;R&(R't field_count((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytis_resultset_packetÌscCs|jdd!dkS(Niisû(R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytis_load_local_packetÐscCs|jdd!dkS(Niisÿ(R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pytis_error_packetÓscCs\|jƒrX|jƒ|jdƒ|jƒ}trEtd|ƒntj|jƒndS(Niserrno =( R[R9R7R?R+RRtraise_mysql_exceptionR&(R'terrno((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyt check_errorÖs    cCst|jƒdS(N(R#R&(R'((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyR,Þs(R%R&(t__name__t __module__t__doc__t __slots__R)R*R1R3R7R9R:RR<R?RBRCRDRGRNRORSRTRURVRWRYRZR[R^R,(((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyR$1s:                       tFieldDescriptorPacketcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sç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. cCs$tj|||ƒ|j|ƒdS(N(R$R)t_parse_field_descriptor(R'R R(((s1/tmp/pip-build-7KIPgS/PyMySQL/pymysql/protocol.pyR)éscCs¯|jƒ|_|jƒ|_|jƒj|ƒ|_|jƒj|ƒ|_|jƒj|ƒ|_|jƒj|ƒ|_|jdƒ\|_ |_ |_ |_ |_ dS(s…Parse the 'Field Descriptor' (Metadata) packet. This is compatible with MySQL 4.1+ (not compatible with MySQL 4.0). s s&   ±2