
    ,h7                         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mZm	Z	 ddl
mZmZmZmZmZmZ ddlmZmZ ddd	Zeeeed
f   f   ed<   deeee   f   deeef   fdZ G d de      Zy)z.Implements parser to parse MySQL option files.    N)ConfigParserMissingSectionHeaderError)AnyDictListOptionalTupleUnion   )CNX_POOL_ARGSDEFAULT_CONFIGURATION)inicnf)r   )ntposix.DEFAULT_EXTENSIONSconfigreturnc                     d| v rn	 t        | d   t              r	| d   g| d<   | d   }| d= t        | d   t              r	| d   g| d<   t        t	        | d         d      }| d=  |j
                  | }i }|D ]o  }	 ||   j                         D ]V  \  }}||fz  }	 |dk(  rd}|j                  |d|d	          |t        vr|d
k7  r	t        |   }||vs||   d   |d   k  r|||<   X q |j                         D ]a  \  }}	|	\  }}}
|| vs|j                  |
      s#|j                  |
|      s6|dv rt        |      | |<   I	 t        j                  |      | |<   c d| v r| j%                  d      | d<   | S # t        $ r ddg}Y [w xY w# t        $ r |dk(  rt        d| d      dY w xY w# t        $ r Y Ew xY w# t        t         t"        f$ r || |<   Y w xY w)z
    Read option files for connection parameters.

    Checks if connection arguments contain option file arguments, and then
    reads option files accordingly.
    option_filesoption_groupsclientconnector_pythonF)keep_dashessocketunix_socketr   failoverr   zUnsupported argument ''N)passwordpasswd)
isinstancestrKeyErrorMySQLOptionsParserlist get_groups_as_dict_with_priorityitemssetr   r   AttributeErrorhas_section
has_optionastliteral_eval
ValueError	TypeErrorSyntaxErrorpop)r   groupsoption_parserconfig_from_fileconfig_optionsgroupoptionvalue_valuessections              ]/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/mysql/connector/optionfiles.pyread_option_filesr=   2   s    	4&137+1/+B*C'O,F' f^,c2&,^&<%=F>"*'(e
 >" ;M::FC 	 ;= 	E%5e%<%B%B%D (MFEeX%E(!X-%2F)--e]E!HM!66Z;O 5f =A #.8-f5a8E!HD5:N62(	2 -224 	/NFF &E1gf$!--g6!,,Wf=33%(ZF6N/),)9)9%)@v	/ v$*JJx$8F=!Mo  	4 23F	4> $ ( $66"0"8 B##'( 7(
   '	;? /).v/sZ   $E6 :F/A
F
$F/F?6FF
F,(F/+F,,F//	F<;F<?GGc            
          e Zd ZdZ	 ddeeee   ef      deddfdZ	dedefdZ
dee   ddfd	Z	 dd
eeee   f   dee   dee   fdZdedeeef   fdZdedeeeeeeef   f   f   fdZdedeeeeef   f   fdZy)r$   z9This class implements methods to parse MySQL option filesNfilesr   r   c                 z   t        j                  d      | _        i | _        t	        j
                  | d       t        t        j                     | _	        || _
        |st        d      t        |t              r|gn|| _        | j                  t!        | j                               | j#                         | _        y)zInitialize

        If defaults is True, default option files are read first

        Raises ValueError if defaults is set to True but defaults files
        cannot be found.
        z>(?P<option>[^:=\s][^:=]*)\s*(?:(?P<vi>[:=])\s*(?P<value>.*))?$F)strictzfiles argument should be givenN)recompileoptcre_options_dictSafeConfigParser__init__r   osnamedefault_extensionr   r.   r!   r"   r?   _parse_optionsr%   get_groups_as_dict	_sections)selfr?   r   s      r<   rG   zMySQLOptionsParser.__init__|   s     #%** #
 EG!!$u52DRWW2M!,=>>+5eS+Au
D,-484K4K4M    	optionstrc                 ^    | j                   s|j                  dd      }|j                         S )zConverts option strings

        Converts option strings to lower case and replaces dashes(-) with
        underscores(_) if keep_dashes variable is set.
        -r9   )r   replacelower)rN   rP   s     r<   optionxformzMySQLOptionsParser.optionxform   s,     !))#s3I  rO   c           
      ^   |dd }g }d}d}|D ]  }	 |||dz   d v rt        d| d      t        |dd	      5 }|j                         D ]G  }|j                  d
      r|j	                  dd      \  }}	|	j                         }	t        j                  |	      D ]  }
t        j                  j                  |	|
      }
|
|v rt        |j                  |
|            t        j                  j                  |
      sb|
j                  | j                        s~|j                  |
        |j                  d      s|j	                  dd      \  }}|j                         }||v rt        |j                  ||            |j                  |       J |dz  }|j                  |       ddd        | j!                  |      }t#        |      t#        |      z
  }|rt        ddj                  |       d      y# 1 sw Y   UxY w# t        $ r}t        d| d|       |d}~ww xY w)aK  Parse options from files given as arguments.
         This method checks for !include or !inculdedir directives and if there
         is any, those files included by these directives are also parsed
         for options.

        Raises ValueError if any of the included or file given in arguments
        is not readable.
        Nr   z4Option file '{0}' being included again in file '{1}'r   zSame option file 'z&' occurring more than once in the listrutf-8encodingz!includedir!includezFailed reading file 'z': zFile(s) z, z could not be read.)r.   open	readlines
startswithsplitstriprH   listdirpathjoinformatisfileendswithrJ   appendIOErrorreadr(   )rN   r?   initial_filesindexerr_msgfile_op_fileliner9   dir_pathentryfilenameerr
read_filesnot_read_filess                  r<   rK   z!MySQLOptionsParser._parse_options   s0    aH" 	SESM%!)+66$,UG 40 0  %w7 (7 ' 1 1 3 3??=9*.**T1*=KAx'/~~'7H)+H)= 8(*Xu(E#(E>*4W^^E55Q*R$R#%77>>%#8U^^$($:$:>" %*LL$78 "__Z8*.**T1*=KAx'/~~'7H'50&0%1P&Q Q!LL2%3( QJELL'-(	SB YYu%
Uc*o5x		.(A'BBUVWW 9( (.  S #8s3%!HIsRSsB   'HCH <H %H >A.H ,H H		H	H,H''H,	filenamesrZ   c                 x   t        |t              r|g}g }t        |      D ]  \  }}	 t        j                         }t        j                  |d      5 }|D ]  }|j                         }|j                  d      r%| j                  j                  |      }	| j                  j                  |      sI|	rG|	j                  ddd      \  }
}}|
r|s|s|j                  | d       |j                  | d       |j                  | d        	 d	d	d	       |j                  d
       	 | j!                  ||       | j"                  j%                         D ]K  }	 | j&                  |    | j"                  |   j+                         D ]  \  }}||f| j&                  |   |<    M | j-                         | _        |j1                          |j3                  |        |S # 1 sw Y   xY w# t        $ r Y w xY w# t(        $ r i | j&                  |<   Y w xY w# t.        $ r | j!                  ||       Y }w xY w)zRead and parse a filename or a list of filenames.

        Overridden from ConfigParser and modified so as to allow options
        which are not inside any section header

        Return list of successfully read files.
        rX   rY   r[   r7   vir8   z=

Nr   )r!   r"   	enumerateioStringIOcodecsr\   r`   r^   rD   matchSECTCREr6   writeseekrh   _readrM   keysrE   r#   r'   _dictr   closerg   )rN   rv   rZ   read_okpriorityrr   out_filein_filero   	match_objoptname	delimiteroptvalr6   r7   r8   s                   r<   ri   zMySQLOptionsParser.read   s+    i%"I"+I"6 '	%Hh;;=[[G< 8 ' 8#zz|??:6$$(KK$5$5d$;	#||11$7I9B ($:6GY  'vi ($s| < ($r{ ;$NNdV2;7!88$ a /

8X.!^^002 NE7**51 *.)>)D)D)F N=BH<M**51&9NN "& NNNN8$O'	%P K8 8&   $ 746**517 - /

8X./sa   +G-B=G!G-,/HG=+AH!G*	&G--	G:9G:=HHHHH98H9argsc                 r   |s#t        | j                  j                               }i }i }|D ]s  }	 | j                  |   j                         D cg c]  \  }}|dk7  r|j	                  d      s||f! c}}D ]%  \  }}||vs||   |d   k  s|d   ||<   |d   ||<   ' u |S c c}}w # t
        $ r Y w xY w)a  Returns options as a dictionary.

        Returns options from all the groups specified as arguments, returns
        the options from all groups if no argument provided. Options are
        overridden when they are found in the next group.

        Returns a dictionary
        __name__!r   r   )tuplerE   r   r'   r^   r#   )rN   r   optionsr   r6   keyr8   r7   s           r<   
get_groupszMySQLOptionsParser.get_groups  s     ++0023D#% 	E '+&8&8&?&E&E&G&
 #Uj(1D	 & 
3MFE W,0@E!H0L+08(*/(
3	  &  s)    B*$B$4B*B*$B**	B65B6c                     |s#t        | j                  j                               }i }|D ]3  }	 t        d | j                  |   j	                         D              ||<   5 |S # t
        $ r Y Cw xY w)a3  Returns options as dictionary of dictionaries.

        Returns options from all the groups specified as arguments. For each
        group the option are contained in a dictionary. The order in which
        the groups are specified is unimportant. Also options are not
        overridden in between the groups.

        The value is a tuple with two elements, first being the actual value
        and second is the priority of the value which is higher for a value
        read from a higher priority file.

        Returns an dictionary of dictionaries
        c              3   V   K   | ]!  \  }}|d k7  r|j                  d      s||f # yw)r   r   Nr^   .0r   r8   s      r<   	<genexpr>zFMySQLOptionsParser.get_groups_as_dict_with_priority.<locals>.<genexpr>H  s9      &
 #Uj(1D	 &s   ')r   rE   r   dictr'   r#   rN   r   r   r6   s       r<   r&   z3MySQLOptionsParser.get_groups_as_dict_with_priority2  s      ++0023D 	E
!% &
 '+&8&8&?&E&E&G& "	      0A""	A.-A.c                     |s#t        | j                  j                               }i }|D ]3  }	 t        d | j                  |   j	                         D              ||<   5 |S # t
        $ r Y Cw xY w)ao  Returns options as dictionary of dictionaries.

        Returns options from all the groups specified as arguments. For each
        group the option are contained in a dictionary. The order in which
        the groups are specified is unimportant. Also options are not
        overridden in between the groups.

        Returns an dictionary of dictionaries
        c              3   \   K   | ]$  \  }}|d k7  r|j                  d      s	||d   f & yw)r   r   r   Nr   r   s      r<   r   z8MySQLOptionsParser.get_groups_as_dict.<locals>.<genexpr>d  s=      &
 #Uj(1D	 a&s   *,r   r   s       r<   rL   z%MySQLOptionsParser.get_groups_as_dictT  s     ++0023D 	E
!% &
 '+&8&8&?&E&E&G& "	   r   )NT)N)r   
__module____qualname____doc__r   r
   r   r"   boolrG   rU   rK   ri   r   r   r	   intr&   rL    rO   r<   r$   r$   y   s   C RVNeDIsN34NJNN	NB!S !S !2XDI 2X$ 2Xj KO5sDI~.5:B3-5	c5n S#X @  	c4U38_,--	. D S$sCx.5H0I rO   r$   )r   r,   r}   r{   rH   rB   configparserr   rF   r   typingr   r   r   r   r	   r
   	constantsr   r   r   r"   __annotations__r=   r$   r   rO   r<   <module>r      s   > 5 
  	 	 	 T : : ; 2 DeCHo-. Dc49n 5 D$sCx. DNv) vrO   