
    Vh              
       F   d dl mZmZmZ eZd dlZ ej                  d      Z ej                  dej                        Z
 ej                  dej                        Z G d de      Z G d d	e      Z ed
dddd
d
dd
      Z ed
ddd
d
      Zd Zd Zd Zd Zd Zd Zy)    )absolute_importdivisionprint_functionNz(\'|\").*--z (UNION|INTERSECT|EXCEPT).*SELECTz4;.*(SELECT|UPDATE|INSERT|DELETE|DROP|TRUNCATE|ALTER)c                       e Zd Zy)SQLParseErrorN__name__
__module____qualname__     s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/database.pyr   r           r   r   c                       e Zd Zy)UnclosedQuoteErrorNr   r   r   r   r   r   $   r   r   r               )databaseschematablecolumnrole
tablespacesequencepublication)r   r   r   r   varsc                     d}	 	 | j                  |      }||z   }	 | |dz      }||k(  r	 | |dz   d  } |dz   }n|S 7# t        $ r t        w xY w# t        $ r |cY S w xY w# t        $ r t        w xY w)Nr   r   r   )index
ValueErrorr   
IndexError)
identifier
quote_char
accumulatequote	next_chars        r   _find_end_quoter(   8   s    J
	%$$Z0E  %'
	"519-I 
")'	
3
'!^
 #   	%$$	%
  		  )(()s%   ; A A AAAA/c                     | st        d      d}| j                  |      rrd}	 t        | dd  |      dz   }|t        |       dz
  k  rG| |dz      dk(  r1|dz   }| d | }| |dz   d  }t	        ||      }|j                  d|       nt        d      | g}	 |s	 | j                  d      }|dk(  s|t        |       dz
  k\  r.| j                  ||d	z        } d
j                  || |f      } | g}|S | d | }| |dz   d  }t	        ||      }|j                  ||d	z        }d
j                  |||f      }|j                  d|       |S S # t        $ r d}Y w xY w# t        $ r0 | j                  ||d	z        } d
j                  || |f      } | g}Y |S w xY w)Nz4Identifier name unspecified or unquoted trailing dotFTr   r$   .r   z1User escaped identifiers must escape extra quotesr    )r   
startswithr(   len_identifier_parseinsertr   r    replacejoinr!   )r#   r$   already_quoted	end_quotedotfirst_identifiernext_identifierfurther_identifierss           r   r/   r/   N   s	   RSSNZ(	3'
12:NQRRI 3z?Q..i!m,3#a-C'1$3'7$&0q&:O*;OZ*X''..q2BC'([\\'1l#	@""3'C ax3#j/A"55'//
JNK
WWj*j%IJ
'1l#  $.ds#3 ",S1WX"6&7&T##3#;#;J
UV#W #%77J8H*+U#V #**1.>?G " 	#"N	#$  	/#++J
QGJ*j*!EFJ#-, #	/s#   E E EE5FFc                     t        | d      }t        |      t        |   kD  rt        d|t        |   fz        dj	                  |      S )N"r*   z5PostgreSQL does not support %s with more than %i dotsr+   )r/   r.   _PG_IDENTIFIER_TO_DOT_LEVELr   r2   )r#   id_typeidentifier_fragmentss      r   pg_quote_identifierr>   }   sf    ,ZCH
 #>w#GGSW^`{  }D  aE  WF  F  G  	G88())r   c                     t        | d      }t        |      dz
  t        |   kD  rt        d|t        |   fz        g }|D ]*  }|dk(  r|j	                  d       |j	                  |       , dj                  |      S )N`r*   r   z0MySQL does not support %s with more than %i dotsz`*`*r+   )r/   r.   _MYSQL_IDENTIFIER_TO_DOT_LEVELr   appendr2   )r#   r<   r=   special_cased_fragmentsfragments        r   mysql_quote_identifierrF      s    ,ZCH !A%)G)PPNRY[y  {B  \C  RD  D  E  	E ( 5u#**3/#**84	5 88+,,r   c                 f    | syt         t        t        fD ]  }t        j                  ||       s y y)zCheck if the passed string is potentially dangerous.
    Can be used to prevent SQL injections.

    Note: use this function only when you can't use
      psycopg2's cursor.execute method parametrized
      (typically with DDL queries).
    FT)	PATTERN_1	PATTERN_2	PATTERN_3research)stringpatterns     r   is_input_dangerousrO      s6     y)4 99Wf% r   c                    |}g }|D ]  }t        |t              rt        |      s|j                  |       1t        |t              r%|D ]  }t        |      s|j                  |       ! f|t        |t
              ryt        |      }t        |      s|j                  |        |r%| j                  ddj                  |      z         yy)z(Wrapper for is_input_dangerous function.Nz*Passed input '%s' is potentially dangerousz, )msg)
isinstancestrrO   rC   listbool	fail_jsonr2   )moduleargsneeds_to_checkdangerous_elementselemes         r   check_inputr]      s    N 0dC !$'"))$/d# 1%a(&--a01 \Zd3 t9D!$'"))$/!0$  57;yyAS7TU 	V r   )
__future__r   r   r   type__metaclass__rK   compilerH   
IGNORECASErI   rJ   	Exceptionr   r   dictr;   rB   r(   r/   r>   rF   rO   r]   r   r   r   <module>re      s    C B 	 BJJ~&	 BJJ:BMMJ	 BJJNPRP]P]^		I 		 	 #
	
	  "&q!!RS!T ,,^*-$Vr   