
    ,h\                     P   U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% erddl&m'Z' dd	l(m)Z) dd
l*m+Z+m,Z, ddl-m.Z. dZ/e0e1d<   e2e3e
e)fZ4e#e$e2   e$e3   e$e
   e$e)   f   e1d<   de%e2e5f   de2fdZ6de2de5fdZ7de2de5fdZ8de2de5fdZ9de2de5fdZ:de2de5fdZ;de2de5fdZ<de2de5fdZ=de5de2de#e5e5f   fdZ>de5de#e5e"e5   f   fdZ?de5de"e#e"e5   df      fdZ@	 	 d?de5de"e5   de"e2   de#e5e5f   fd ZAde5de2de#e5e2f   fd!ZBde5de#e5e"e2   f   fd"ZCde.deDfd#ZE	 d@d$e.d%e"eD   d&e2ddfd'ZFde eDeDf   fd(ZGde eDeDf   fd)ZHde"e eDeDf      fd*ZIde#eDeDeDf   fd+ZJd,eDdeDfd-ZKd,eDde eDeeDge0f   f   fd.ZLd/eDde"e#eDeDf      fd0ZMd1eDdeDfd2ZN	 dAd3e%e2e.f   d4eDdeOfd5ZP e       de eDe%eDe#eDeDf   f   f   fd6       ZQd7eDdefd8ZRd9eDd:eDddfd;ZSd:eDddfd<ZT G d= d>      ZUy)Bz
Utilities.    N)Decimal)	lru_cache)in_table_a1in_table_b1in_table_c3in_table_c4in_table_c5in_table_c6in_table_c7in_table_c8in_table_c9in_table_c11in_table_c12in_table_c21_c22in_table_d1in_table_d2)	TYPE_CHECKINGAnyCallableDictListOptionalTupleTypeUnion)MySQLConnectionAbstract   )
HexLiteral)DEPRECATED_TLS_CIPHERSUITESDEPRECATED_TLS_VERSIONS)
StrOrBytesF__MYSQL_DEBUG__NUMERIC_TYPESbufreturnc                 .   t        | t              r| S t        |       t               }}|dk(  r| d   S |dk  r0|| dd|z
  z  z   z  }t        t	        j
                  d|      d         S || dd|z
  z  z   z  }t        t	        j
                  d|      d         S )z&Unpacks the given buffer to an integerr   r          <I   <Q)
isinstanceintlen	bytearraystructunpack)r$   lengthtmps      W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/mysql/connector/utils.pyintreadr5   W   s    #s
c(IKCF{1v{sWF
+++6==s+A.//3AJ'''Cv}}T3'*++    ic                 X    | dk  s| dkD  rt        d      t        j                  d|       S )z^
    Takes an unsigned byte (1 byte) and packs it as a bytes-object.

    Returns string.
    r      z int1store requires 0 <= i <= 255<B
ValueErrorr0   packr7   s    r4   	int1storer?   e   s.     	1uC;<<;;tQr6   c                 X    | dk  s| dkD  rt        d      t        j                  d|       S )z`
    Takes an unsigned short (2 bytes) and packs it as a bytes-object.

    Returns string.
    r     z"int2store requires 0 <= i <= 65535<Hr;   r>   s    r4   	int2storerC   p   s.     	1uE	=>>;;tQr6   c                 ^    | dk  s| dkD  rt        d      t        j                  d|       dd S )zb
    Takes an unsigned integer (3 bytes) and packs it as a bytes-object.

    Returns string.
    r    z%int3store requires 0 <= i <= 16777215r)      r;   r>   s    r4   	int3storerG   {   s5     	1uH@AA;;tQ!$$r6   c                 X    | dk  s| dkD  rt        d      t        j                  d|       S )zb
    Takes an unsigned integer (4 bytes) and packs it as a bytes-object.

    Returns string.
    r       z'int4store requires 0 <= i <= 4294967295r)   r;   r>   s    r4   	int4storerJ      s.     	1uJBCC;;tQr6   c                 X    | dk  s| dkD  rt        d      t        j                  d|       S )zZ
    Takes an unsigned integer (8 bytes) and packs it as string.

    Returns string.
    r               z!int8store requires 0 <= i <= 2^64r+   r;   r>   s    r4   	int8storerM      s0     	1u((<==;;tQr6   c                     | dk  s| dkD  rt        d      | dk  rt        }n*| dk  rt        }n| dk  rt        }n| dk  rt        }nt
        } ||       S )z
    Takes an unsigned integers and packs it as a bytes-object.

    This function uses int1store, int2store, int3store,
    int4store or int8store depending on the integer value.

    returns string.
    r   rL   z!intstore requires 0 <= i <=  2^64r9   rA   rE   rI   )r<   r?   rC   rG   rJ   rM   )r7   formed_strings     r4   intstorerP      s_     	1u((<==Cx!	
e!	
h!	
j!!r6   c                    | dk  s| dkD  rt        d      | dk  rt        j                  d|       S | dk  rdt        j                  d|       z   S | d	k  rd
t        j                  d|       dd z   S dt        j                  d|       z   S )z|
    Takes an unsigned integer and packs it as bytes,
    with the information of how much bytes the encoded int takes.
    r   rL   zRequires 0 <= i <= 2^64   r:   rA      rB   rE      r)   rF      r+   r;   r>   s    r4   lc_intrV      s    
 	1u((2333w{{4##EzT1---H}T1-a222V[[q)))r6   sizec                     | d| }| |d |fS )zi
    Reads bytes from a buffer.

    Returns a tuple with buffer less the read bytes, and the bytes.
    r   N r$   rW   ress      r4   
read_bytesr\      s      a+CJr6   c                     | d   dk(  r| dd dfS dx}}| d   }|dk  r|}| d|z   d | d|dz    fS |dk(  rd}n|dk(  rd	}n|d
k(  rd}t        | d|dz          }| ||z   dz   d | |dz   ||z   dz    fS )u  
    Takes a buffer and reads a length coded string from the start.

    This is how Length coded strings work

    If the string is 250 bytes long or smaller, then it looks like this:

      <-- 1b  -->
      +----------+-------------------------
      |  length  | a string goes here
      +----------+-------------------------

    If the string is bigger than 250, then it looks like this:

      <- 1b -><- 2/3/8 ->
      +------+-----------+-------------------------
      | type |  length   | a string goes here
      +------+-----------+-------------------------

      if type == ü:
          length is code in next 2 bytes
      elif type == ý:
          length is code in next 3 bytes
      elif type == þ:
          length is code in next 8 bytes

    NULL has a special value. If the buffer starts with û then
    it's a NULL and we return None as value.

    Returns a tuple (trucated buffer, bytes).
    r   rR   r   N            rF      r*   r5   )r$   r2   lsizefsts       r4   read_lc_stringrf      s    @ 1v}ABFU
a&C
czAJL!3q6A:#677
cz		SUQY'(F"$%s519v~7I'JKKr6   .c                    g }dddd}t        |       }d}||k  r| |   }|dk(  ry|dk(  r|j                  d       |d	z  }nz|d
k  r(|}|j                  | |d	z   ||d	z   z           |d	|z   z  }nMd}	 ||   }t        | |d	z   ||d	z   z          }|j                  | |d	z   |z   ||z   |d	z   z           |d	|z   |z   z  }||k  rt	        |      S # t        $ r Y yw xY w)zXReads all length encoded strings from the given buffer

    Returns a list of bytes
    r`   rF   r*   )r_   ra   rb   r   r9   NrR   r   r^   )r.   appendKeyErrorr5   tuple)r$   byteslstsizesbuf_lenposfirstr2   rd   s           r4   read_lc_string_listrp     s,   
 ')H!!$E#hG
C
-CC< C<OOD!1HC|S1W#'0B CDq6z! !%LE !cAg#'1B!CDC!GeOfuna6P QRq5y6))/ -2 ?     s   2C 	CCendc                     ||t        d      |	 | j                  |      }| |dz   d | d| fS |t        | |      S t        d      # t         $ r}t        d      |d}~ww xY w)zr
    Reads a string up until a character or for a given size.

    Returns a tuple (trucated buffer, string).
    Nz&read_string() needs either end or sizezend byte not present in bufferr   r   z.read_string() needs either end or size (weird))r<   indexr\   )r$   rq   rW   idxerrs        r4   read_stringrv   /  s     {t|ABB
	H))C.C C!GIAc
++#t$$
E
FF  	H=>CG	Hs   A
 
	A$AA$c                 ,    t        | d|       }| |d |fS )zMRead an integer from buffer

    Returns a tuple (truncated buffer, int)
    r   Nrc   rZ   s      r4   read_intrx   H  s%    
 #a+
CJr6   c                 h   | st        d      | d   }|dk(  r| dd dfS |dk  r| dd t        |      fS |dk(  r!| dd t        j                  d| dd       d   fS |d	k(  r$| d
d t        j                  d| dd
 dz         d   fS |dk(  r!| dd t        j                  d| dd       d   fS t        d      )z
    Takes a buffer and reads an length code string from the start.

    Returns a tuple with buffer less the integer and the integer read.
    zEmpty buffer.r   rR   r   Nr_   rF   z<xHra   r'   r)   r(   rb   	   z<xQz%Failed reading length encoded integer)r<   r-   r0   r1   )r$   lcbytes     r4   read_lc_intr|   Q  s     ))VF}AB|ABV%%}ABuc!Ah7:;;}ABtS1X-?@CDD}ABuc!Ah7:;;
<
==r6   c           	          t        | t              s#dj                  | D cg c]  }d|d
 c}      S dj                  | D cg c]  }dt        |      d c}      S c c}w c c}w )z"Debug function for showing buffers z\x02x)r,   strjoinord)r$   cs     r4   _digest_bufferr   k  s]    c3wws3!#aW3447741c#a&&455 44s   A A%abufferprefixlimitc                     |r3|r|dkD  rt        | d|       }nt        |       }t        |dz   |z          yt        t        |              y)z2Debug function printing output of _digest_buffer()r   z: N)r   print)r   r   r   digests       r4   print_bufferr   r  sI     UQY#GAe$45F#G,Fftmf$%nW%&r6   c                     i } t         j                  j                  dd      }t         j                  j                  |      s| S t	        |d      5 }|D ]]  }|j                  d      }t        |      dk7  r#|d   j                         }|d   j                  d	      j                  d
      }|| |<   _ 	 ddd       | S # 1 sw Y   | S xY w)zsParse the contents of /etc/os-release file.

    Returns:
        A dictionary containing release information.
    /etcz
os-releaseutf-8encoding=r`   r   r   
"N
ospathr   existsopensplitr.   lowerrstripstrip)distroos_release_filefile_objline	key_valuekeyvalues          r4   _parse_os_releaser     s      Fggll6<8O77>>/*	o	0  H 	 D

3I9~"A,$$&CaL''-33C8EF3K	   M  Ms   A#B??C	c                     i } t         j                  j                  dd      }t         j                  j                  |      r{t	        |d      5 }|D ]]  }|j                  d      }t        |      dk7  r#|d   j                         }|d   j                  d	      j                  d
      }|| |<   _ 	 ddd       | S | S # 1 sw Y   | S xY w)ztParse the contents of /etc/lsb-release file.

    Returns:
        A dictionary containing release information.
    r   zlsb-releaser   r   r   r`   r   r   r   r   Nr   )r   lsb_release_filer   r   r   r   r   s          r4   _parse_lsb_releaser     s     Fww||FM:	ww~~&'"W5 	$  $ JJsO	y>Q&l((*!!++D177<#s$	$ M6M	$ Ms   A#B??C	c                     i } t        t        j                  dd      5 }	 t        j                  d|      }|j                  t        j                               j                         }|D ]^  }|j                  d      }t        |      dk7  r#|d	   j                  d
d      j                         }|d   j                  d      }|| |<   ` 	 ddd       | S # t
        $ r Y ddd       yw xY w# 1 sw Y   | S xY w)ztParse the output of the lsb_release command.

    Returns:
        A dictionary containing release information.
    wr   r   )lsb_releasez-a)stderrN:r`   r    _r   	)r   r   devnull
subprocesscheck_outputOSErrordecodesysgetfilesystemencoding
splitlinesr   r.   replacer   r   )r   r   stdoutlinesr   r   r   r   s           r4   _parse_lsb_release_commandr     s     F	bjj#	0  G	,,-B7SF c779:EEG 	 D

3I9~"A,&&sC0668CaL&&t,EF3K	   M  		   	  Ms.   C.CBC.	C+ C.*C++C..C8c                     t               } | r5| j                  dd      | j                  dd      | j                  dd      fS t               } | r5| j                  dd      | j                  dd      | j                  dd      fS t               } | r5| j                  dd      | j                  d	d      | j                  d
d      fS y)aN  Tries to determine the name of the Linux OS distribution name.

    First tries to get information from ``/etc/os-release`` file.
    If fails, tries to get the information of ``/etc/lsb-release`` file.
    And finally the information of ``lsb-release`` command.

    Returns:
        A tuple with (`name`, `version`, `codename`)
    
distrib_idr~   distrib_releasedistrib_codenamedistributor_idreleasecodenamename
version_idversion_codename)r~   r~   r~   )r   getr   r   )r   s    r4   linux_distributionr     s     (:';FJJ|R(JJ("-JJ)2.
 	
 ()FJJ',JJy"%JJz2&
 	
  FJJvr"JJ|R(JJ)2.
 	
 r6   unicode_strc                 >    | rt        j                  | d         dv ryy)zGet the readiness direction of the unicode string.

    We assume that the direction is "L-to-R" if the first character does not
    indicate the direction is "R-to-L" or an "AL" (Arabic Letter).
    r   )RALR-to-LzL-to-R)unicodedatabidirectional)r   s    r4   _get_unicode_read_directionr     s+     {00Q@ E  r6   c                     t        |       }|dk(  r/t        | d         rt        | d         st        d      dt        iS dt        iS )at  
    1) The characters in section 5.8 MUST be prohibited.

    2) If a string contains any RandALCat character, the string MUST NOT
       contain any LCat character.

    3) If a string contains any RandALCat character, a RandALCat
       character MUST be the first character of the string, and a
       RandALCat character MUST be the last character of the string.
    r   r   zvInvalid unicode Bidirectional sequence, if the first character is RandALCat, the final charactermust be RandALCat too.z7Bidirectional Characters requirement 2 [StringPrep, d2])r   r   r<   r   )r   read_dirs     r4   _get_unicode_direction_ruler     s]     +;7H 8KN+KO0L)  J;WW F{SSr6   normalized_strc                 h   t         t        t        t        t        t        t
        t        t        t        t        t        d}	 |j                  t        |              | D ]0  }|j                         D ]  \  }} ||      s|dk7  s||fc c S  2 y# t        $ r}| t        |      fcY d}~S d}~ww xY w)a  Check for Prohibited Output according to rfc4013 profile.

    This profile specifies the following characters as prohibited input:

       - Non-ASCII space characters [StringPrep, C.1.2]
       - ASCII control characters [StringPrep, C.2.1]
       - Non-ASCII control characters [StringPrep, C.2.2]
       - Private Use characters [StringPrep, C.3]
       - Non-character code points [StringPrep, C.4]
       - Surrogate code points [StringPrep, C.5]
       - Inappropriate for plain text characters [StringPrep, C.6]
       - Inappropriate for canonical representation characters [StringPrep, C.7]
       - Change display properties or deprecated characters [StringPrep, C.8]
       - Tagging characters [StringPrep, C.9]

    In addition of checking of Bidirectional Characters [StringPrep, Section 6]
    and the Unassigned Code Points [StringPrep, A.1].

    Returns:
        A tuple with ("probited character", "breaked_rule")
    )z4Space characters that contains the ASCII code pointsz&Space characters non-ASCII code pointsz(Unassigned Code Points [StringPrep, A.1]z.Non-ASCII space characters [StringPrep, C.1.2]z,ASCII control characters [StringPrep, C.2.1]z(Private Use characters [StringPrep, C.3]z+Non-character code points [StringPrep, C.4]z'Surrogate code points [StringPrep, C.5]z9Inappropriate for plain text characters [StringPrep, C.6]zGInappropriate for canonical representation characters [StringPrep, C.7]zDChange display properties or deprecated characters [StringPrep, C.8]z$Tagging characters [StringPrep, C.9]Nr   )r   r   r   r   r   r   r	   r
   r   r   r   updater   r<   r   items)r   rulesru   charrulefuncs         r4   "validate_normalized_unicode_stringr     s    2 AM2>4?:F8H4?7B3>EPS^P[0;E(0@A  "++- 	"JD$DzdckTz!	""
   (s3x''(s   B 	B1B,&B1,B1a_stringc                     | D cg c]  }t        |      rdnt        |      rdn|  }}dj                  |      }t        j                  d|      }|sy|S c c}w )a(  normalizes a unicode string according to rfc4013

    Normalization of a unicode string according to rfc4013: The SASLprep profile
    of the "stringprep" algorithm.

    Normalization Unicode equivalence is the specification by the Unicode
    character encoding standard that some sequences of code points represent
    essentially the same character.

    This method normalizes using the Normalization Form Compatibility
    Composition (NFKC), as described in rfc4013 2.2.

    Returns:
        Normalized unicode string according to rfc4013.
    r   r~   NFKC)r   r   r   r   	normalize)r   r   	nstr_listnstrs       r4   normalize_unicode_stringr   C  sj    *  D![->rDHI 
 779D
   .DKs   #Apayloadr   c                    t        | t              r| S t        | t              rt        |       S t        | t              s	 t        | j	                  |            S t        |       S # t
        $ r}t        d      |d}~ww xY w)z(Initialize a bytearray from the payload.r   zpayload must be a str or bytesN)r,   r/   r-   bytesencodeAttributeErrorr<   )r   r   ru   s      r4   init_bytearrayr   h  s}     '9%'3!!gu%	HW^^X^>?? W  	H=>CG	Hs   A% %	A?.A::A?c                     ddd} t         j                  dk(  rtdt        j                         d   v rd| d<   n6dt        j                         d   v rd	| d<   nt        j                         | d<   d
t        j                         d    | d<   | S t        j
                         | d<   t        j                         dk(  rdt        j                         d    | d<   | S dj                  t               dd       | d<   | S )z4Return a dict with the platform arch and OS version.r~   )archversionnt64r   x86_64r   32i386zWindows-r   r   DarwinzmacOS--r`   )
r   r   platformarchitecture	win32_vermachinesystemmac_verr   r   )plats    r4   get_platformr   y  s     =?23ND	ww$8((*1--#DLX**,Q//!DL#002DL$X%7%7%9!%<$=>Y K  '')V??( &x'7'7'9!'<&=>DO K "hh'9';Aa'@ADOKr6   fullpathc                 "   t        | t              st        d      	 | j                  dd      \  }}t	        j
                  |      }t        ||      }|S # t        $ r t        d|  d      dt        t        f$ r}t        |       |d}~ww xY w)a(  Import an object from a fully qualified module path.

    Args:
        obj (str): A string representing the fully qualified name of the object.

    Returns:
        Object: The imported object.

    Raises:
        ValueError: If the object can't be imported.

    .. versionadded:: 8.0.33
    z]'fullpath' should be a str representing the fully qualified name of the object to be imported.r   zNo callable named ''N)	r,   r   r<   rsplit	importlibimport_modulegetattrr   ModuleNotFoundError)r   
module_strcallable_strmoduleobjru   s         r4   import_objectr	    s     h$$
 	
,#+??3#: 
L((4fl+ J  F.xj:;E/0 ,C5"+,s   6A 'B<B		Bcipher_as_ossltls_versionc                     | t        j                  |i       j                         v r!d|  d}t        j                  |t
               yy)aI  Emits a warning if a deprecated cipher is being utilized.

    Args:
        cipher: Must be ingested as OpenSSL name.
        tls_versions: TLS version to check the cipher against.

    Raises:
        DeprecationWarning: If the cipher is flagged as deprecated
                            according to the OSSA cipher list.
    z$This connection is using TLS cipher [ which is now deprecated and will be removed in a future release of MySQL Connector/Python.N)r   r   valueswarningswarnDeprecationWarning)r
  r  warn_msgs      r4   warn_ciphersuites_deprecatedr    sR     488bIPPRR2>2B C& & 	
 	h 23 Sr6   c                 V    | t         v r!d|  d}t        j                  |t               yy)a  Emits a warning if a deprecated TLS version is being utilized.

    Args:
        tls_versions: TLS version to check.

    Raises:
        DeprecationWarning: If the TLS version is flagged as deprecated
                            according to the OSSA cipher list.
    z%This connection is using TLS version r  N)r    r  r  r  )r  r  s     r4   warn_tls_version_deprecatedr    s:     --3K= A& & 	
 	h 23 .r6   c                   \     e Zd ZdZdeddfdZdedefdZded	eddf fd
ZdefdZ	 xZ
S )GenericWrapperz<Base class that provides basic object wrapper functionality.wrappedr%   Nc                     || _         y)zConstructor.N)_wrapped)selfr  s     r4   __init__zGenericWrapper.__init__  s	    $r6   attrc                 b    || j                   v rt        | |      S t        | j                  |      S )zGets an attribute.

        Attributes defined in the wrapper object have higher precedence
        than those wrapped object equivalent. Attributes not found in
        the wrapper are then searched in the wrapped object.
        )__dict__r  r  )r  r  s     r4   __getattr__zGenericWrapper.__getattr__  s.     4== 4&&t}}d++r6   r   r   c                     d| j                   vr|| j                   d<   y|| j                   v rt        | 	  ||       y| j                  j                  ||       y)zSets an attribute.r  N)r  super__setattr__r  )r  r   r   	__class__s      r4   r#  zGenericWrapper.__setattr__  sR    T]]*(-DMM*%4== Ge,!!$.r6   c                 B    | j                   j                  j                  S )zGets the wrapped class name.)r  r$  __name__)r  s    r4   get_wrapped_classz GenericWrapper.get_wrapped_class  s    }}&&///r6   )r&  
__module____qualname____doc__r   r  r   r   r#  r'  __classcell__)r$  s   @r4   r  r    sR    F% % %, , ,/ /C /D /03 0r6   r  )NN)N   )r6   r   )Vr*  r  r   r   r0   r   r   r   r  decimalr   	functoolsr   
stringprepr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   typingr   r   r   r   r   r   r   r   r   mysql.connector.abstractsr   custom_typesr   tls_ciphersr   r    typesr!   r"   bool__annotations__r-   floatr#   r   r5   r?   rC   rG   rJ   rM   rP   rV   r\   rf   rp   rv   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r/   r   r   r	  r  r  r  rY   r6   r4   <module>r8     s  :   	    
        
 
 
 A $ M   		QuT#YUT']D<LLM ,sEz" ,s ,          % % %            4*c *e *$E  ue|)< 2L 2L%x(>"? 2Lj%U %xhuos6J0K'L %T  G	G	%G 3-G 5%<	G2% s uUCZ'8 >U >uUHSM%9: >46
 6s 6 EG''!)#'>A'	'4S> *DcN (HT#s(^$< ."E#sC-0 "JS S TS TT#xt?T:T5U T811eCHo1h"s "s "L <C3
?#58" d3c5c?&: ;;<  *C C >4 43 44 4(4S 4T 4&#0 #0r6   