
    2Dh$.                         S SK Jr  S SKJrJr  S SKJr  SSKrSSKrSr	Sr
SrSrS	rS
rS r " S S5      r " S S\5      r " S S5      r " S S5      r " S S5      rg)   )MBLENGTH)
FIELD_TYPESERVER_STATUS)err    NF            c           	      n  ^ S m [        S[        U 5      5        [        SS5       HG  n[        R                  " U5      n[        SXR
                  R                  UR                  4-  5        MI     [        S5        [        S[        [        U 5      S5      S	5       Vs/ s H	  oXS	-    PM     nnU HU  n[        S
R                  S U 5       5      SS	[        U5      -
  -  -   S-   SR                  U4S jU 5       5      -   5        MW     [        S5        [        5         g ! [         a     Nf = fs  snf )Nc                 :    SU s=::  a  S:  a  O  g[        U 5      $ g)N       .)chr)datas    B/var/www/html/env/lib/python3.13/site-packages/pymysql/protocol.py	printabledump_packet.<locals>.printable   s!     t9    zpacket length:r      zcall[%d]: %s (line %d)zB------------------------------------------------------------------r          c              3   (   #    U  H  oS  v   M
     g7f)02XN ).0xs     r   	<genexpr>dump_packet.<locals>.<genexpr>&   s     +A#wZs   z   z   c              3   4   >#    U  H  nT" U5      v   M     g 7fNr   )r   r   r   s     r   r    r!   )   s     .AqillAs   )printlenrangesys	_getframef_codeco_namef_lineno
ValueErrorminjoin)r   if	dump_datadr   s        @r   dump_packetr4      s   
D	*q!Aa A*a1A1A1::-NNO  	h ,1CD	34G+LM+Laab&!+LIMHH+++rCF{#$ gg.A../	
  
(O	G  Ms   A7D" D2"
D/.D/c                       \ rS rSrSrSrS rS rS rS r	S r
S S	 jrS!S
 jrS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSr g)"MysqlPacket/   zjRepresentation of a MySQL response packet.

Provides an interface for reading/parsing the packet results.
	_position_datac                     SU l         Xl        g )Nr   r8   selfr   encodings      r   __init__MysqlPacket.__init__7   s    
r   c                     U R                   $ r$   r:   r=   s    r   get_all_dataMysqlPacket.get_all_data;   s    zzr   c           
      d   U R                   U R                  U R                  U-    n[        U5      U:w  ae  SU S[        U5       SU R                   S[        U R                   5       3n[        (       a  [	        U5        U R                  5         [        U5      eU =R                  U-  sl        U$ )zCRead the first 'size' bytes in packet and advance cursor past them.z-Result length not requested length:
Expected=z
.  Actual=z.  Position: z.  Data Length: )r:   r9   r&   DEBUGr%   dumpAssertionError)r=   sizeresulterrors       r   readMysqlPacket.read>   s    DNNdnnt.CEv;$ 6CK=dnnEUUefijnjtjtfuevx  ue		 ''$r   c                 F    U R                   U R                  S nSU l        U$ )zPRead all remaining data in the packet.

(Subsequent read() will return errors.)
Nr:   r9   r=   rK   s     r   read_allMysqlPacket.read_allM   s%    
 DNN,-r   c                     U R                   U-   nUS:  d  U[        U R                  5      :  a  [        SU SU 35      eX l         g)z1Advance the cursor in data buffer 'length' bytes.r   zInvalid advance amount (z) for cursor.  Position=N)r9   r&   r:   	Exception)r=   lengthnew_positions      r   advanceMysqlPacket.advanceV   sL    ~~.!|c$**o=*6(2J<.Y  &r   c                 j    US:  d  U[        U R                  5      :  a  [        SU-  5      eXl        g)z9Set the position of the data buffer cursor to 'position'.r   z)Invalid position to rewind cursor to: %s.N)r&   r:   rU   r9   )r=   positions     r   rewindMysqlPacket.rewind_   s.    a<8c$**o5G(RSS!r   c                 $    U R                   XU-    $ )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!
rB   )r=   r[   rV   s      r   	get_bytesMysqlPacket.get_bytese   s     zz(&799r   c                 b    U R                   U R                     nU =R                  S-  sl        U$ Nr   rP   rQ   s     r   
read_uint8MysqlPacket.read_uint8p   s'    DNN+!r   c                     [         R                  " SU R                  U R                  5      S   nU =R                  S-  sl        U$ )Nz<Hr      structunpack_fromr:   r9   rQ   s     r   read_uint16MysqlPacket.read_uint16u   6    ##D$**dnnEaH!r   c                     [         R                  " SU R                  U R                  5      u  pU =R                  S-  sl        XS-  -   $ )Nz<HB   r   rg   )r=   lowhighs      r   read_uint24MysqlPacket.read_uint24z   s;    &&udjj$..I	!bj!!r   c                     [         R                  " SU R                  U R                  5      S   nU =R                  S-  sl        U$ )Nz<Ir      rg   rQ   s     r   read_uint32MysqlPacket.read_uint32   rl   r   c                     [         R                  " SU R                  U R                  5      S   nU =R                  S-  sl        U$ )Nz<Qr      rg   rQ   s     r   read_uint64MysqlPacket.read_uint64   rl   r   c                     U R                   R                  SU R                  5      nUS:  a  g U R                   U R                  U nUS-   U l        U$ )N    r   r   )r:   findr9   )r=   end_posrK   s      r   read_stringMysqlPacket.read_string   sH    **//%8Q;DNNW5 1r   c                     U R                  5       nU[        :X  a  gU[        :  a  U$ U[        :X  a  U R	                  5       $ U[
        :X  a  U R                  5       $ U[        :X  a  U R                  5       $ g)zRead 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)	rc   NULL_COLUMNUNSIGNED_CHAR_COLUMNUNSIGNED_SHORT_COLUMNrj   UNSIGNED_INT24_COLUMNrq   UNSIGNED_INT64_COLUMNry   )r=   cs     r   read_length_encoded_integer'MysqlPacket.read_length_encoded_integer   sv     OO##H''##%%''##%%''##%% (r   c                 L    U R                  5       nUc  gU R                  U5      $ )zRead 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)r   rM   )r=   rV   s     r   read_length_coded_string$MysqlPacket.read_length_coded_string   s)     113>yy  r   c                     [         R                  " U5      nUR                  U R                  U R                  5      nU =R                  UR
                  -  sl        U$ r$   )rh   Structri   r:   r9   rJ   )r=   fmtsrK   s       r   read_structMysqlPacket.read_struct   s?    MM#tzz4>>:!&& r   c                 d    U R                   S   S:H  =(       a    [        U R                   5      S:  $ )Nr   r   r:   r&   rC   s    r   is_ok_packetMysqlPacket.is_ok_packet   s'    zz!}!:c$**o&::r   c                 d    U R                   S   S:H  =(       a    [        U R                   5      S:  $ )Nr   r   	   r   rC   s    r   is_eof_packetMysqlPacket.is_eof_packet   s)     zz!}$<TZZ1)<<r   c                 &    U R                   S   S:H  $ )Nr   r   rB   rC   s    r   is_auth_switch_request"MysqlPacket.is_auth_switch_request   s    zz!}$$r   c                 &    U R                   S   S:H  $ )Nr   r   rB   rC   s    r   is_extra_auth_dataMysqlPacket.is_extra_auth_data   s    zz!}!!r   c                 J    U R                   S   nSUs=:*  =(       a    S:*  $ s  $ )Nr   r      rB   )r=   field_counts     r   is_resultset_packetMysqlPacket.is_resultset_packet   s(    jjmK&&3&&&&r   c                 &    U R                   S   S:H  $ )Nr   r   rB   rC   s    r   is_load_local_packet MysqlPacket.is_load_local_packet       zz!}$$r   c                 &    U R                   S   S:H  $ )Nr      rB   rC   s    r   is_error_packetMysqlPacket.is_error_packet   r   r   c                 P    U R                  5       (       a  U R                  5         g g r$   )r   raise_for_errorrC   s    r   check_errorMysqlPacket.check_error   s"    !!  " "r   c                     U R                  5         U R                  S5        U R                  5       n[        (       a  [	        SU5        [
        R                  " U R                  5        g )Nr   zerrno =)r\   rX   rj   rG   r%   r   raise_mysql_exceptionr:   )r=   errnos     r   r   MysqlPacket.raise_for_error   sE    Q  "5)U#!!$**-r   c                 .    [        U R                  5        g r$   )r4   r:   rC   s    r   rH   MysqlPacket.dump   s    DJJr   rP   N)r   )r   )!__name__
__module____qualname____firstlineno____doc__	__slots__r?   rD   rM   rR   rX   r\   r_   rc   rj   rq   ru   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   rH   __static_attributes__r   r   r   r6   r6   /   s    
 'I&"	:

"


&$
!;=%"'%%#. r   r6   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
FieldDescriptorPacket   zA 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.
c                 R    [         R                  XU5        U R                  U5        g r$   )r6   r?   _parse_field_descriptorr<   s      r   r?   FieldDescriptorPacket.__init__   s     T2$$X.r   c                    U R                  5       U l        U R                  5       U l        U R                  5       R                  U5      U l        U R                  5       R                  U5      U l        U R                  5       R                  U5      U l        U R                  5       R                  U5      U l        U R                  S5      u  U l	        U l
        U l        U l        U l        g)zuParse the 'Field Descriptor' (Metadata) packet.

This is compatible with MySQL 4.1+ (not compatible with MySQL 4.0).
z	<xHIBHBxxN)r   catalogdbdecode
table_name	org_tablenameorg_namer   	charsetnrrV   	type_codeflagsscale)r=   r>   s     r   r   -FieldDescriptorPacket._parse_field_descriptor   s    
 446//1779@@J668??I113::8D	557>>xH [)	
NKNJJr   c                     U R                   U R                  SU R                  5       U R                  5       U R                  U R                  S-  S:H  4$ )zBProvides a 7-item tuple compatible with the Python PEP249 DB Spec.Nrf   r   )r   r   get_column_lengthr   r   rC   s    r   description!FieldDescriptorPacket.description  sN     IINN""$""$JJJJNa
 	
r   c                     U R                   [        R                  :X  a0  [        R                  " U R
                  S5      nU R                  U-  $ U R                  $ rb   )r   r   
VAR_STRINGr   getr   rV   )r=   mblens     r   r   'FieldDescriptorPacket.get_column_length  sA    >>Z222LL3E;;%''{{r   c                     SR                  U R                  U R                  U R                  U R                  U R
                  U R                  5      $ )Nz&{} {!r}.{!r}.{!r}, type={}, flags={:x})format	__class__r   r   r   r   r   rC   s    r   __str__FieldDescriptorPacket.__str__  s?    7>>NNGGOOIINNJJ
 	
r   )r   r   r   r   rV   r   r   r   r   r   r   N)r   r   r   r   r   r?   r   r   r   r   r   r   r   r   r   r      s     /**


r   r   c                   $    \ rS rSrSrS rS rSrg)OKPacketWrapperi  z
OK Packet Wrapper. It uses an existing packet object, and wraps
around it, exposing useful variables while still providing access
to the original packet objects variables and methods.
c                    UR                  5       (       d.  [        S[        U R                  R                  5      -   S-   5      eXl        U R
                  R                  S5        U R
                  R                  5       U l        U R
                  R                  5       U l	        U R                  S5      u  U l        U l        U R
                  R                  5       U l        U R                  [        R                   -  U l        g )NzCannot create z  object from invalid packet typer   z<HH)r   r-   strr   r   packetrX   r   affected_rows	insert_idr   server_statuswarning_countrR   messager   SERVER_MORE_RESULTS_EXISTShas_nextr=   from_packets     r   r?   OKPacketWrapper.__init__%  s    '')) dnn--./45  "A![[DDF@@B151A1A%1H.D.{{++-**]-U-UUr   c                 .    [        U R                  U5      $ r$   getattrr   r=   keys     r   __getattr__OKPacketWrapper.__getattr__6      t{{C((r   )r   r   r   r   r   r   r   Nr   r   r   r   r   r?   r   r   r   r   r   r   r     s    V")r   r   c                   $    \ rS rSrSrS rS rSrg)EOFPacketWrapperi:  z
EOF Packet Wrapper. It uses an existing packet object, and wraps
around it, exposing useful variables while still providing access
to the original packet objects variables and methods.
c                 B   UR                  5       (       d  [        SU R                   S35      eXl        U R                  R	                  S5      u  U l        U l        [        (       a  [        SU R                  5        U R                  [        R                  -  U l        g )NCannot create '!' object from invalid packet typez<xhhzserver_status=)r   r-   r   r   r   r   r   rG   r%   r   r   r   r   s     r   r?   EOFPacketWrapper.__init__A  s    ((**!$..!11RS  "151H1H1P.D.5"D$6$67**]-U-UUr   c                 .    [        U R                  U5      $ r$   r   r   s     r   r   EOFPacketWrapper.__getattr__M  r   r   )r   r   r   r   Nr   r   r   r   r   r   :  s    
V)r   r   c                   $    \ rS rSrSrS rS rSrg)LoadLocalPacketWrapperiQ  z
Load Local Packet Wrapper. It uses an existing packet object, and wraps
around it, exposing useful variables while still providing access
to the original packet objects variables and methods.
c                     UR                  5       (       d  [        SU R                   S35      eXl        U R                  R	                  5       SS  U l        [        (       a  [        SU R
                  5        g g )Nr   r   r   z	filename=)r   r-   r   r   rD   filenamerG   r%   r   s     r   r?   LoadLocalPacketWrapper.__init__X  sj    //11!$..!11RS  "0021265+t}}- r   c                 .    [        U R                  U5      $ r$   r   r   s     r   r   "LoadLocalPacketWrapper.__getattr__c  r   r   )r  r   Nr   r   r   r   r  r  Q  s    	.)r   r  )charsetr   	constantsr   r   r"   r   rh   r(   rG   r   r   r   r   r   r4   r6   r   r   r   r  r   r   r   <module>r	     sw     0   
 	    4o  o d:
K :
z) )8) ).) )r   