AlkantarClanX12

Your IP : 3.138.37.43


Current Path : /proc/self/root/opt/alt/python39/lib64/python3.9/lib2to3/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python39/lib64/python3.9/lib2to3/__pycache__/fixer_util.cpython-39.pyc

a

R�ff;�@s�dZddlmZddlmZmZddlmZddl	m
Z
dd�Zdd	�Zd
d�Z
dd
�ZdNdd�Zdd�Zdd�Zdd�Ze�e
�fdd�ZdOdd�Zdd�Zdd�ZdPdd �Zd!d"�ZdQd#d$�ZdRd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zhd1�Z d2d3�Z!d4a"d5a#d6a$d7a%d8d9�Z&d:d;�Z'd<d=�Z(d>d?�Z)d@dA�Z*dBdC�Z+dDdE�Z,dFdG�Z-ej.ej/hZ0dSdHdI�Z1ej/ej.ej2hZ3dJdK�Z4dTdLdM�Z5dS)Uz1Utility functions, node construction macros, etc.�)�token)�Leaf�Node)�python_symbols)�patcompcCsttj|ttjd�|g�S)N�=)r�symsZargumentrr�EQUAL)�keyword�value�r�7/opt/alt/python39/lib64/python3.9/lib2to3/fixer_util.py�
KeywordArgs�rcCsttjd�S)N�()rr�LPARrrrr
�LParensrcCsttjd�S)N�))rr�RPARrrrr
�RParensrcCsHt|t�s|g}t|t�s&d|_|g}ttj|ttjddd�g|�S)zBuild an assignment statement� r��prefix)	�
isinstance�listrrr�atomrrr	)�target�sourcerrr
�Assigns

�rNcCsttj||d�S)zReturn a NAME leafr)rr�NAME)�namerrrr
�Name$sr cCs|ttjt�|g�gS)zA node tuple for obj.attr)rr�trailer�Dot)�obj�attrrrr
�Attr(sr%cCsttjd�S)zA comma leaf�,)rr�COMMArrrr
�Comma,sr(cCsttjd�S)zA period (.) leaf�.)rr�DOTrrrr
r"0sr"cCs4ttj|��|��g�}|r0|�dttj|��|S)z-A parenthesised argument list, used by Call()r)rrr!�clone�insert_child�arglist)�argsZlparenZrparen�noderrr
�ArgList4sr0cCs&ttj|t|�g�}|dur"||_|S)zA function callN)rr�powerr0r)Z	func_namer.rr/rrr
�Call;sr2cCsttjd�S)zA newline literal�
�rr�NEWLINErrrr
�NewlineBsr6cCsttjd�S)zA blank line�r4rrrr
�	BlankLineFsr8cCsttj||d�S)Nr)rr�NUMBER)�nrrrr
�NumberJsr;cCs"ttjttjd�|ttjd�g�S)zA numeric or string subscript�[�])rrr!rr�LBRACE�RBRACE)Z
index_noderrr
�	SubscriptMs
�r@cCsttj||d�S)z
A string leafr)rr�STRING)�stringrrrr
�StringSsrCc	Cs�d|_d|_d|_ttjd�}d|_ttjd�}d|_||||g}|rtd|_ttjd�}d|_|�ttj||g��ttj|ttj	|�g�}ttj
ttjd�|ttjd�g�S)zuA list comprehension of the form [xp for fp in it if test].

    If test is None, the "if test" part is omitted.
    r7r�for�in�ifr<r=)
rrrr�appendrrZcomp_ifZ	listmakerZcomp_forrr>r?)	Zxp�fp�it�testZfor_leafZin_leafZ
inner_argsZif_leaf�innerrrr
�ListCompWs(

��rLcCsV|D]}|��qttjd�ttj|dd�ttjddd�ttj|�g}ttj|�}|S)zO Return an import statement in the form:
        from package import name_leafs�fromrr�import)�removerrrrr�import_as_names�import_from)Zpackage_nameZ
name_leafsZleaf�children�imprrr
�
FromImportos


�rTc	Cs�|d��}|jtjkr"|��}nttj|��g�}|d}|rNdd�|D�}ttjtt|d�t|d��ttj|d��||d��g�g|�}|j	|_	|S)	zfReturns an import statement and calls a method
    of the module:

    import module
    module.name()r#�aftercSsg|]}|���qSr)r+)�.0r:rrr
�
<listcomp>��z!ImportAndCall.<locals>.<listcomp>�rZlparZrpar)
r+�typerr-rr1r%r r!r)r/�results�namesr#Z
newarglistrU�newrrr
�
ImportAndCall�s*


�����r^cCs�t|t�r |jt�t�gkr dSt|t�o�t|j�dko�t|jdt�o�t|jdt�o�t|jdt�o�|jdjdko�|jdjdkS)z(Does the node represent a tuple literal?T�rYr�rr)rrrRrr�lenrr�r/rrr
�is_tuple�s
������rccCsXt|t�oVt|j�dkoVt|jdt�oVt|jdt�oV|jdjdkoV|jdjdkS)z'Does the node represent a list literal?rrY���r<r=)rrrarRrrrbrrr
�is_list�s
�����recCsttjt�|t�g�S�N)rrrrrrbrrr
�parenthesize�srg>
�min�tuple�	enumerate�all�any�sortedr�max�sum�setccs$t||�}|r |Vt||�}q
dS)alFollow an attribute chain.

    If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
    use this to iterate over all objects in the chain. Iteration is
    terminated by getattr(x, attr) is None.

    Args:
        obj: the starting object
        attr: the name of the chaining attribute

    Yields:
        Each successive object in the chain.
    N)�getattr)r#r$�nextrrr
�
attr_chain�s
rszefor_stmt< 'for' any 'in' node=any ':' any* >
        | comp_for< 'for' any 'in' node=any any* >
     z�
power<
    ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
      'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
    trailer< '(' node=any ')' >
    any*
>
z`
power<
    ( 'sorted' | 'enumerate' )
    trailer< '(' arglist<node=any any*> ')' >
    any*
>
FcCspts&t�t�at�t�at�t�adatttg}t|t|d��D]*\}}i}|�||�r@|d|ur@dSq@dS)a Returns true if node is in an environment where all that is required
        of it is being iterable (ie, it doesn't matter if it returns a list
        or an iterator).
        See test_map_nochange in test_fixers.py for some examples and tests.
        T�parentr/F)	�
pats_builtrZcompile_pattern�p0�p1�p2�ziprs�match)r/Zpatterns�patternrtr[rrr
�in_special_context�s



r|cCs�|j}|dur|jtjkrdS|j}|jtjtjfvr:dS|jtjkrX|j	d|urXdS|jtj
ks�|jtjkr�|dur�|jtjks�|j	d|ur�dSdS)zG
    Check that something isn't an attribute or function name etc.
    NFrYT)
Zprev_siblingrZrr*rtr�funcdef�classdef�	expr_stmtrR�
parametersZ
typedargslistr')r/�prevrtrrr
�is_probably_builtin�s&
��
��r�cCsJ|durF|jtjkr>t|j�dkr>|jd}|jtjkr>|jS|j}qdS)zFind the indentation of *node*.Nr`rr7)	rZr�suiterarRr�INDENTrrt)r/�indentrrr
�find_indentations
r�cCs>|jtjkr|S|��}|jd}|_ttj|g�}||_|Srf)rZrr�r+rtr)r/rtr�rrr
�
make_suitesr�cCs$|jtjkr |j}|std��q|S)zFind the top level namespace.z,root found before file_input node was found.)rZrZ
file_inputrt�
ValueErrorrbrrr
�	find_root&s

r�cCst|t|�|�}t|�S)z� Returns true if name is imported from package at the
        top level of the tree which node belongs to.
        To cover the case of an import like 'import foo', use
        None for the package and 'foo' for the name. )�find_bindingr��bool)�packagerr/Zbindingrrr
�does_tree_import/sr�cCs|jtjtjfvS)z0Returns true if the node is an import statement.)rZr�import_namerQrbrrr
�	is_import7sr�cCs.dd�}t|�}t|||�r dSd}}t|j�D]F\}}||�sDq2t|j|d��D]\}}||�sVqlqV||}qzq2|dkr�t|j�D]8\}}|jtjkr�|jr�|jdjtjkr�|d}q�q�|dur�t	tj
ttjd�ttj|dd�g�}	nt
|ttj|dd�g�}	|	t�g}
|�|t	tj|
��dS)	z\ Works like `does_tree_import` but adds an import statement
        if it was not imported. cSs |jtjko|jot|jd�S)NrY)rZr�simple_stmtrRr�rbrrr
�is_import_stmt>s�z$touch_import.<locals>.is_import_stmtNrYrrNrr)r�r�rjrRrZrr�rrArr�rrrTr6r,)r�rr/r��rootZ
insert_pos�offset�idxZnode2�import_rRrrr
�touch_import;s8�
�
r�cCs�|jD�]�}d}|jtjkrVt||jd�r4|St|t|jd�|�}|rR|}�n0|jtjtjfvr�t|t|jd�|�}|r�|}�n�|jtj	k�rt|t|jd�|�}|r�|}nTt
|jdd��D]@\}}|jtjkr�|j
dkr�t|t|j|d�|�}|r�|}q�nx|jtv�r2|jdj
|k�r2|}nTt|||��rF|}n@|jtjk�rbt|||�}n$|jtjk�r�t||jd��r�|}|r|�s�|St|�r|SqdS)	z� Returns the node which binds variable name, otherwise None.
        If optional argument package is supplied, only imports will
        be returned.
        See test cases for examples.Nrrdr`r_�:�rY)rRrZrZfor_stmt�_findr�r�Zif_stmtZ
while_stmtZtry_stmtrjr�COLONr�	_def_syms�_is_import_bindingr�rr�)rr/r��childZretr:�iZkidrrr
r�isB
r�cCsT|g}|rP|��}|jdkr4|jtvr4|�|j�q|jtjkr|j|kr|SqdS)N�)�poprZ�_block_syms�extendrRrrr)rr/Znodesrrr
r��sr�cCs�|jtjkr�|s�|jd}|jtjkrx|jD]H}|jtjkrV|jdj|krt|Sq,|jtjkr,|j|kr,|Sq,nL|jtjkr�|jd}|jtjkr�|j|kr�|Sn|jtjkr�|j|kr�|Sn�|jtj	k�r�|r�t
|jd���|kr�dS|jd}|�rtd|��rdS|jtj
k�r0t||��r0|S|jtjk�rh|jd}|jtjk�r�|j|k�r�|Sn6|jtjk�r�|j|k�r�|S|�r�|jtjk�r�|SdS)z� Will return node if node will import name, or node
        will import * from package.  None is returned otherwise.
        See test cases for examples. rr`rdNr_�as)rZrr�rRZdotted_as_namesZdotted_as_namerrrrQ�str�stripr�rPZimport_as_name�STAR)r/rr�rSr�Zlastr:rrr
r��s@





r�)N)NN)N)N)N)N)N)6�__doc__Zpgen2rZpytreerrZpygramrrr7rrrrrr r%r(r"r0r2r6r8r;r@rCrLrTr^rcrergZconsuming_callsrsrvrwrxrur|r�r�r�r�r�r�r�r~r}r�r�r!r�r�r�rrrr
�<module>sX




		-
*