
    *he=                     @   % S r SSKrSSKrSSKJr  SSKJrJrJr  SSK	J
r
  SSKJr  Sr S	S
SSSSSSSSSSSSS.r \R                  " S\R                   \R"                  -  S9r\R&                  \S'     " S S5      r S#S\S\S\\SS4   4S  jjrS!\S\\   4S" jrg)$z8Classes and methods utilized to work with MySQL Scripts.    N)deque)Deque	GeneratorOptional   )InterfaceError)MySQLScriptPartition   ;s   \$s   \^s   \?s   \(s   \)s   \[s   \]s   \{s   \}s   \.s   \|s   \+s   \-s   \*)$^?()[]{}.|+-*sA   (delimiter\s+)(?=(?:[^"'`]*(?:"[^"]*"|'[^']*'|`[^`]*`))*[^"'`]*$))flagsDELIMITER_PATTERNc                      \ rS rSrSrSrS\SS4S jrS\S	\S\\   4S
 jr	\
S\S\4S j5       r\
S\S\4S j5       r\
S\S\\   4S j5       r\
S\S\4S j5       r\
S\S\4S j5       rSS\S\\   4S jjrS\4S jrSrg)MySQLScriptSplitterE   zBreaks a MySQL script into single statements.

It strips custom delimiters and comments along the way, except for comments
representing a MySQL extension or optimizer hint.
s3   (?=(?:[^"'`]*(?:"[^"]*"|'[^']*'|`[^`]*`))*[^"'`]*$)
sql_scriptreturnNc                 :    Xl         SU l        SU l        0 U l        g)zConstructor.N)_code_single_stmts_mappable_stmts_re_sql_split_stmts)selfr   s     R/var/www/auris/envauris/lib/python3.13/site-packages/mysql/connector/_scripting.py__init__MySQLScriptSplitter.__init__N   s    
486:<>     code	delimiterc                    / nX R                   ;  a  SU;   a  [        S5      eUR                  5        Vs/ s H&  n[        R	                  XDR                  5       5      PM(     nn[        R                  " SR                  U5      U R                  -   5      U R                   U'   U R                   U   R                  U5       H-  nUR                  5       nU(       d  M  UR                  U5        M/     U$ s  snf )z Split code context by delimiter.   \z5The backslash (\) character is not a valid delimiter.r)   )r$   r   decodeDELIMITER_RESERVED_SYMBOLSgetencoderecompilejoin_regex_sql_split_stmtssplitstripappend)r%   r*   r+   snippetschardelimiter_patternsnippetsnippet_strips           r&   _split_statement$MySQLScriptSplitter._split_statementU   s    444	!$L 
 &,,.!.D +..t[[]C.  ! 35***+d.I.II3D$$Y/ //	:@@FG#MMOM}. G
 !s   -C4r:   c                 L    [         R                  " [        U 5      5      S   S;   $ )z;Validates whether `char` is a white-space character or not.r   >   Zunicodedatacategorychrr:   s    r&   is_white_space_char'MySQLScriptSplitter.is_white_space_charm   #     ##CI.q1U::r)   c                 L    [         R                  " [        U 5      5      S   S;   $ )z7Validates whether `char` is a control character or not.r   >   CrB   rF   s    r&   is_control_char#MySQLScriptSplitter.is_control_charr   rI   r)   stringc                 0    [         R                  " SU 5      $ )z6Split `string` by any control character or whitespace.s   [\s\x00-\x1f\x7f-\x9f])r2   r6   )rN   s    r&   $split_by_control_char_or_white_space8MySQLScriptSplitter.split_by_control_char_or_white_spacew   s     xx2F;;r)   c                 <    [         R                  " [        U 5      SL$ )zBValidates whether `code` has the delimiter command pattern or not.N)r2   searchr   r*   s    r&   has_delimiter!MySQLScriptSplitter.has_delimiter|   s     yy*D1==r)   c                    S[         S[        S[        4S jnS[         S[        4S jnS[         S[        S[        4S jn[        S5      nSu  pV[	        S	5      [	        S
5      [	        S5      pnU[        U 5      :  Ga  UGc  Sn
U" USS X   5      (       a  Sn
O(U" USS 5      (       a  Sn
OU" USS X   5      (       a  Sn
U
GbF  U
S;   a6  U[        U 5      :  a&  X   U:w  a  US-  nU[        U 5      :  a
  X   U:w  a  M  OFUS-   [        U 5      :  a/  XUS-    S:w  a$  US-  nUS-   [        U 5      :  a  XUS-    S:w  a  M$  US-  n[        [        U
5      5       H  nUR                  5         M     U(       a  [        R                  US   5      (       d  [        R                  US   5      (       aU  UR                  5         U(       a>  [        R                  US   5      (       a  M6  [        R                  US   5      (       a  MU  GM  Uc  X   X4;   a  X   nOUb  X   Xg1;   a  SnUR                  X   5        US-  nU[        U 5      :  a  GM  [        U5      $ )aP  Remove MySQL comments which include `--`-style, `#`-style
and `C`-style comments.

A `--`-style comment spans from `--` to the end of the line.
It requires the second dash to be
followed by at least one whitespace or control character
(such as a space, tab, newline, and so on).

A `#`-style comment spans from `#` to the end of the line.

A C-style comment spans from a `/*` sequence to the following `*/`
sequence, as in the C programming language. This syntax enables a
comment to extend over multiple lines because the beginning and
closing sequences need not be on the same line.

**NOTE: Only C-style comments representing MySQL extensions or
optimizer hints are preserved**. E.g.,

```
/*! MySQL-specific code */

/*+ MySQL-specific code */
```

*For Reference Manual- MySQL Comments*, see
https://dev.mysql.com/doc/refman/en/comments.html.
b_strb_charr   c                 |    U S:H  =(       a1    [         R                  U5      =(       d    [         R                  U5      $ )Ns   --)r   rL   rG   rX   rY   s     r&   is_dash_style:MySQLScriptSplitter.remove_comments.<locals>.is_dash_style   s5    E> #33F; C&::6Br)   c                     U S:H  $ )N   # )rX   s    r&   is_hash_style:MySQLScriptSplitter.remove_comments.<locals>.is_hash_style   s    D= r)   c                 L    U S:H  =(       a    U[        S5      [        S5      1;  $ )Ns   /*!r   )ordr[   s     r&   
is_c_style7MySQLScriptSplitter.remove_comments.<locals>.is_c_style   s#    E>HfSXs3x4H&HHr)   r)   )r   N
'"N--#z/*)rl   rn   r      s   */)bytesintbool	bytearrayre   lenrangepopr   rL   rG   r8   )r*   r\   ra   rf   bufiliteral_ctx
line_breaksingle_quotedouble_quotestyle_s               r&   remove_comments#MySQLScriptSplitter.remove_comments   sV   <	 	 	 		! 	!4 	!	Ie 	IS 	IT 	I n 14TCHc#h,
#d)m" RS4733 E"3rs8,,EBC$'22 E$+#d)m:0EFA  #d)m:0E  !ec$i/DQUOu4LFA  !ec$i/DQUOu4LQ"3u:.	 / +;;CGDD.BB3r7KK		 +;;CGDD.BB3r7KK "tw<2N'N"g(TW8Q-Q"JJtwFAG #d)mJ Szr)   r   c                    U R                   b  U R                   $ / U l         [        n/ nSnU(       a  [        R                  U R                  S9nOU R                  n[
        R                  " [        US9 H  n[
        R                  " [        U5      (       al  U R                  U5      S   nUR                  5         U R                   R                  U R                  SR                  U5      US95        Xv[        U5      S /p2OUR                  U5        UnM     U(       a8  U R                   R                  U R                  SR                  U5      US95        U R                   $ )a  Splits the given script text into a sequence of individual statements.

The word DELIMITER and any of its lower and upper case combinations
such as delimiter, DeLiMiter, etc., are considered reserved words by
the connector. Users must quote these when included in multi statements
for other purposes different from declaring an actual statement delimiter;
e.g., as names for tables, columns, variables, in comments, etc.

```
CREATE TABLE `delimiter` (begin INT, end INT); -- I am a `DELimiTer` comment
```

If they are not quoted, the statement-mapping will not produce the expected
experience.

See https://dev.mysql.com/doc/refman/8.0/en/keywords.html to know more
about quoting a reserved word.

*Note that comments are always ignored as they are not considered to be
part of statements, with one exeception; **C-style comments representing
MySQL extensions or optimizer hints are preserved***.
Nr)   rT   )patternrN   r       )r*   r+   )r"   DEFAULT_DELIMITERr   r   r!   r2   r6   r   rS   rP   rv   extendr>   r4   rt   r8   )r%   r   r+   rw   prevr*   currnext_delimiters           r&   split_script MySQLScriptSplitter.split_script   sI   0 )%%%  %	 &66DJJ6GD::D HH%6tDD yy*D11 "&!J!J4!PQR!S 	 ""))))tyy~)S "0s>7J7L2M1N3 

4  D1 E6 %%%%499S>Y%O !!!r)   c                 8    U R                   R                  S5      $ )Nutf-8)r!   r.   )r%   s    r&   __repr__MySQLScriptSplitter.__repr__   s    zz  ))r)   )r!   r#   r$   r"   )T)__name__
__module____qualname____firstlineno____doc__r5   rp   r'   listr>   staticmethodrq   rr   rG   rL   rP   rU   r   r   strr   __static_attributes__r`   r)   r&   r   r   E   s    X?5 ?T ?U u e 0 ;# ;$ ; ; ;c ;d ; ; <U <tE{ < < >E >d > > Qe Q Q QfI"D I"DK I"V*# *r)   r   sql_codemap_resultsr   c           
   #     #    [         R                  U 5      (       d  U(       d  [        [        / 5      U S9v   g[        U S9nUR	                  5       nU(       d  [        [        S/5      SS9v   gU(       d%  [        [        U5      SR                  U5      S9v   gSnS [        U5       5       nU HO  nXd:  a(  [        SR                  X4U 5      [        X4U 5      S9v   [        X6   [        X6   /5      S9v   US	-   nMQ     U[        U5      :  a;  [        SR                  X4[        U5       5      [        X4[        U5       5      S9v   gg7f)
aO  Breaks a MySQL script into sub-scripts.

If the given script uses `DELIMITER` statements (which are not recognized
by MySQL Server), the connector will parse such statements to remove them
from the script and substitute delimiters as needed. This pre-processing
may cause a performance hit when using long scripts. Note that when enabling
`map_results`, the script is expected to use `DELIMITER` statements in order
to split the script into multiple query strings.

Args:
    sql_code: MySQL script.
    map_results: If True, each sub-script is `statement-result` mappable.

Returns:
    A generator of typed dictionaries with keys `single_stmts` and `mappable_stmts`.

    If mapping disabled and no delimiters detected, it returns a 1-item generator,
    the field `single_stmts` is an empty list and the `mappable_stmt` field
    corresponds to the unmodified script, that may be mappable.

    If mapping disabled and delimiters detected, it returns a 1-item generator,
    the field `single_stmts` is a list including all the single statements
    found in the script and the `mappable_stmt` field corresponds to the processed
    script (delimiters are stripped) that may be mappable.

    If maping enabled, the script is broken into mappable partitions. It returns
    an N-item generator (as many items as computed partitions), the field
    `single_stmts` is a list including all the single statements of the partition
    and the `mappable_stmt` field corresponds to the sub-script (partition) that
    is guaranteed to be mappable.

Raises:
    `InterfaceError` if an invalid delimiter string is found.
)single_stmtsmappable_stmtN)r   r)   s   ;
r   c              3   \   #    U  H"  u  pUS S R                  5       S:X  d  M  Uv   M$     g 7f)N   s   CALL )upper).0jstmts      r&   	<genexpr>(split_multi_statement.<locals>.<genexpr>j  s*     W&671$r(..:Jh:VQQ&6s   ,	,)r   r   r   )r   rU   r	   r   r   r4   	enumeratert   )r   r   tokstmtsrx   partition_idsr   s          r&   split_multi_statementr   $  sN    L ,,X66{ #b	RR

2C E  #seCPP #uV[[5G
 	
 	 	
AWi&6WM5$"(++eaj"9!&uqz!2 #(z1B
 	
 E  	3u:~ $kk%CJ*?@"5SZ#89	
 s   EEscriptc                    [         R                  " S[        R                  U 5      [         R                  S9nU(       a  [        US   5      S:w  a  [        / 5      $ [        U Vs/ s H  o"S   R                  S5      PM     sn5      $ s  snf )aP  Scans the MySQL script looking for `filenames` (one for each
`LOCAL INFILE` statement found).

Arguments:
    script: a MySQL script that may include one or more `LOCAL INFILE` statements.

Returns:
    filenames: a list of filenames (one for each `LOCAL INFILE` statement found).
    An empty list is returned if no matches are found.
s2   LOCAL\s+INFILE\s+(["'])((?:\\\1|(?:(?!\1)).)*)(\1))r   rN   r   r      r   r   )r2   findallr   r   
IGNORECASErt   r   r.   )r   matchesmatchs      r&   get_local_infile_filenamesr     sr     jjJ"226:mmG
 c'!*o*Ry @u(//'*@AA@s   %B	)F)r   r2   rC   collectionsr   typingr   r   r   errorsr   typesr	   r   r/   r3   r   	MULTILINEr   Pattern__annotations__r   rp   rr   r   r   r   r`   r)   r&   <module>r      s   : ? 	   - - " ' , 
													   E "

M
--",,
&! 2::  D\* \*B Z
Z
Z
 #T4/0Z
zBu Bs Br)   