
    ^j#              	          d 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 ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ  G d de          Zdee
         dee         fdZ	 d'de dee
         defdZ! G d de"          Z# G d de"          Z$de de%e&e&f         de'dej(        fdZ)de dej(        fdZ*de de de fdZ+d ej(        dee          fd!Z,d ej(        d"eej(                 d#ej(        dee          fd$Z-d ej(        d"eej(                 dee          fd%Z.d ej/        deej(                 fd&Z0dS )(z/
Parse Python code and perform AST validation.
    N)
CollectionIterator)VERSION_TO_FEATURESFeatureTargetVersionsupports_feature)syms)pygram)driver)Grammar)
ParseError)
TokenError)LeafNodec                       e Zd ZdZdS )InvalidInputz7Raised when input source code fails all parse attempts.N__name__
__module____qualname____doc__     Q/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/black/parsing.pyr   r      s        AAAAr   r   target_versionsreturnc                    | s#t           j        t           j        t           j        gS g }t	          | t
          j                  s9t	          | t
          j                  s|                    t           j                   t	          | t
          j	                  s|                    t           j                   t          d | D                       r|                    t           j                   |S )Nc              3   H   K   | ]}t           j        t          |         v V  d S N)r   PATTERN_MATCHINGr   ).0vs     r   	<genexpr>zget_grammars.<locals>.<genexpr>.   s0      
W
W!7#':1'==
W
W
W
W
W
Wr   )r
   python_grammar_async_keywordspython_grammarpython_grammar_soft_keywordsr   r   ASYNC_IDENTIFIERSr    appendASYNC_KEYWORDSany)r   grammarss     r   get_grammarsr,      s     	
 0!/
 	
 H2  >0HII> 	<===OW-CDD /-...

W
W
W
W
WWW =;<<< Or   r   src_txtc                 6   |                      d          s| dz  } t          t          |                    }|r*t          |d           }d|                                 }nd}i }|D ]Q}t          j        |          }	 |                    | d          } nO# t          $ r}	|	j	        d         \  }
}| 
                                }	 ||
dz
           }n# t          $ r d}Y nw xY wd	| d
|
 d| d| dd|dz
  z   d|	j         }t          |          ||j        <   Y d}	~	d}	~	wt          $ r}|j        d         \  }
}| 
                                }	 ||
dz
           }n# t          $ r d}Y nw xY wd	| d
|
 d| d| dd|dz
  z   d|j        d          }t          |          ||j        <   Y d}~Kd}~ww xY wt#          |          dk    sJ |t          |                   }|dt%          |t&                    rt)          t*          j        |g          }|S )z4Given a string with source, return the lib2to3 Node.
c                     | j         S r   )value)tvs    r   <lambda>zlib2to3_parse.<locals>.<lambda>@   s    RX r   )keyz for target version  F   z<line number missing in source>zCannot parsez: :z
     z^
ParseError: Nz^
TokenError: r   )endswithr,   setmaxprettyr   Driverparse_stringr   context
splitlines
IndexErrormsgr   versionr   argslen
isinstancer   r   r	   
file_input)r-   r   r+   max_tvtv_strerrorsgrammardrvresultpelinenocolumnlinesfaulty_line	error_msgteexcs                    r   lib2to3_parserV   7   s    D!! 4C0011H _*=*=>>>999F ) )mG$$!	>%%gu55FE 	> 	> 	>Z]NFF&&((E@#FQJ/ @ @ @?@(v ( ( ( (& ( ("( (fqj)( (  "v( (  '39&=&=F7?###### 	> 	> 	>WQZNFF&&((E@#FQJ/ @ @ @?@,v , , , ,& , ,", ,fqj), ,  "wqz, ,  '39&=&=F7?######	>" 6{{aS[[!t&$ 1dox00Msl   B
F9$$D"	CD"C$!D"#C$$9D""F9/$F4E F4 E/,F4.E//?F44F9c                       e Zd ZdZdS )ASTSafetyErrorzDRaised when Black's generated code is not equivalent to the old AST.Nr   r   r   r   rX   rX   v   s        NNNNr   rX   c                       e Zd ZdZdS )SourceASTParseErroru  Raised when the source file cannot be parsed by ast.parse().

    This is not a bug in Black — Black's lib2to3-based parser is more lenient
    than Python's ast.parse(), so it may accept code that ast.parse() rejects.
    In blackd, this should be reported as a 400 Bad Request.
    Nr   r   r   r   rZ   rZ   z   s           r   rZ   srcrC   type_commentsc                    d}t          j                    5  t          j        dt                     t          j        dt                     t          j        | |||          cd d d            S # 1 swxY w Y   d S )Nz	<unknown>ignore)feature_versionr\   )warningscatch_warningssimplefilterSyntaxWarningDeprecationWarningastparse)r[   rC   r\   filenames       r   _parse_single_versionrh      s     H		 	"	" 
 
h666h(:;;;y7-
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   AA//A36A3c                    d t          dt          j        d         dz             D             }d}t          |d          D ]>}	 t	          | |d          c S # t
          $ r}|st          |          }Y d }~7d }~ww xY wt          |d          D ]&}	 t	          | |d          c S # t
          $ r Y #w xY wt          |          )	Nc                     g | ]}d |fS )   r   )r!   minors     r   
<listcomp>zparse_ast.<locals>.<listcomp>   s    JJJuE
JJJr   rk   r6   r5   T)reverse)r\   F)rangesysversion_infosortedrh   SyntaxErrorstr)r[   versionsfirst_errorrC   es        r   	parse_astrx      s   JJa1A!1Dq1H(I(IJJJHK(D111 % %	%(gTJJJJJJ 	% 	% 	% %!!ff	%
 (D111  	(gUKKKKKK 	 	 	D	 k
"
""s*   A
A="A88A=B((
B54B5lineendr1   c                     d |                                 D             }|                     |          }|                                S )Nc                 6    g | ]}|                                 S r   )strip)r!   is     r   rm   z_normalize.<locals>.<listcomp>   s     AAA17799AAAr   )r@   joinr|   )ry   r1   stripped
normalizeds       r   
_normalizer      sI     BAe.>.>.@.@AAAHh''J r   nodec                 "    t          | g           S )z=Simple visitor generating strings to compare ASTs by content.)_stringify_ast)r   s    r   stringify_astr      s    $###r   parent_stack
new_parentc              #      K   |                     |           t          | |          E d {V  |                                 d S r   )r(   r   pop)r   r   r   s      r   _stringify_ast_with_new_parentr      sV       
###dL111111111r   c              #   x  K   t          | t          j                  r,t          | j        t                    r| j        dk    rd | _        dt          |          z   | j        j         dV  t          | j
                  D ]}t          | t          j                  r n	 t          | |          }n# t          $ r Y >w xY wdt          |          dz   z   | dV  t          |t                    r|D ]}|dk    r^t          | t          j                  rDt          |t          j                  r*t#          |          D ]}t%          |||           E d {V  ft          |t          j                  rt%          |||           E d {V  t          |t          j                  rt%          |||           E d {V  Bt          | t          j                  r_|dk    rYt          |t                    rDt          |          dk    r1t          |d	         t          j                  rt+          d
|          }n2|dk    r*t          |t                    r|                                }n|}dt          |          dz   z   |d|j        j         V  dt          |          z   d| j        j         V  d S )Nuz    (r6   =targetsr1      r/   type_commentz,  # z)  # /)rF   re   Constantr1   rt   kindrE   	__class__r   rr   _fields
TypeIgnoregetattrAttributeErrorlistDeleteTuple_unwrap_tuplesr   ASTExprr   rstrip)r   r   fieldr1   itemeltr   s          r   r   r      s\     4&&tz3'' I
 	c,'''
C)@
C
C
CCCC%% 7 7dCN++ 	E	#D%00EE 	 	 	H	 3|,,q01;5;;;;;;eT"" +	 X X Y&&"444 '"433 '  .d33  #At$ $        
  cg.. X=dLRVWWWWWWWWWX  sw'' 	5e\4PPPPPPPPPP
 4..#W$$uc** %%%** |B/:: + (e44

.((Zs-C-C("\\^^

"
S..23 /Z / /O,/ /   
 c,'''
H
Ht~/F
H
HHHHHHs   !B22
B?>B?c              #      K   | j         D ]6}t          |t          j                  rt	          |          E d {V  2|V  7d S r   )eltsrF   re   r   r   )r   r   s     r   r   r     sc      y  c39%% 	%c**********IIII	 r   )r   )1r   re   rp   r`   collections.abcr   r   
black.moder   r   r   r   black.nodesr	   blib2to3r
   blib2to3.pgen2r   blib2to3.pgen2.grammarr   blib2to3.pgen2.parser   blib2to3.pgen2.tokenizer   blib2to3.pytreer   r   
ValueErrorr   r:   r   r,   rt   rV   	ExceptionrX   rZ   tupleintboolr   rh   rx   r   r   r   r   r   r   r   r   r   <module>r      sR    


 



  0 0 0 0 0 0 0 0 T T T T T T T T T T T T             ! ! ! ! ! ! * * * * * * + + + + + + . . . . . . & & & & & & & &B B B B B: B B B#m"4 g    @ @B< <<#-m#<<	< < < <~O O O O OY O O O    )   	
		
S#X	
:>	
W	
 	
 	
 	
#3 #37 # # # #, C C    $ $HSM $ $ $ $

'!%cg<?Gc]   FI FISW FI(3- FI FI FI FIR x'8      r   