Your IP : 18.190.253.224


Current Path : /opt/alt/python38/lib64/python3.8/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/lib2to3/__pycache__/fixer_util.cpython-38.opt-1.pyc

U

i�fg;�
@s�dZddlmZddlmZmZddlmZddl	m
Z
dd�Zdd	�Zd
d�Z
dd
�ZdWdd�Zdd�Zdd�Zdd�Ze�e
�fdd�ZdXdd�Zdd�Zdd�ZdYdd �Zd!d"�ZdZd#d$�Zd[d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2d3d4d5d6d7d8d9d:h
Z d;d<�Z!d=a"d>a#d?a$d@a%dAdB�Z&dCdD�Z'dEdF�Z(dGdH�Z)dIdJ�Z*dKdL�Z+dMdN�Z,dOdP�Z-ej.ej/hZ0d\dQdR�Z1ej/ej.ej2hZ3dSdT�Z4d]dUdV�Z5dS)^z1Utility functions, node construction macros, etc.�)�token)�Leaf�Node)�python_symbols)�patcompcCsttj|ttjd�|g�S)N�=)r�symsZargumentrr�EQUAL)�keyword�value�r�7/opt/alt/python38/lib64/python3.8/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�}|dk	r"||_|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�itZtestZfor_leafZin_leafZ
inner_argsZif_leaf�innerrrr
�ListCompWs(

��rKcCsV|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


�rSc	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>�sz!ImportAndCall.<locals>.<listcomp>�rZlparZrpar)
r+�typerr-rr1r%r r!r)r/�results�namesr#Z
newarglistrT�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�rWr�rr)rrrQrr�lenrr�r/rrr
�is_tuple�s
������racCsXt|t�oVt|j�dkoVt|jdt�oVt|jdt�oV|jdjdkoV|jdjdkS)z'Does the node represent a list literal?rrW���r<r=)rrr_rQrrr`rrr
�is_list�s
�����rccCsttjt�|t�g�S�N)rrrrrr`rrr
�parenthesize�sre�sortedr�set�any�all�tuple�sum�min�max�	enumerateccs$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
rqzefor_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|kr@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�ziprq�match)r/Zpatterns�patternrrrYrrr
�in_special_context�s



rzcCs�|j}|dk	r|jtjkrdS|j}|jtjtjfkr:dS|jtjkrX|j	d|krXdS|jtj
ks�|jtjkr�|dk	r�|jtjks�|j	d|kr�dSdS)zG
    Check that something isn't an attribute or function name etc.
    NFrWT)
Zprev_siblingrXrr*rrr�funcdef�classdef�	expr_stmtrQZ
parametersZ
typedargslistr')r/�prevrrrrr
�is_probably_builtin�s&
��
��rcCsJ|dk	rF|jtjkr>t|j�dkr>|jd}|jtjkr>|jS|j}qdS)zFind the indentation of *node*.Nr^rr7)	rXr�suiter_rQr�INDENTrrr)r/�indentrrr
�find_indentations
r�cCs>|jtjkr|S|��}|jd}|_ttj|g�}||_|Srd)rXrr�r+rrr)r/rrr�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.)rXrZ
file_inputrr�
ValueErrorr`r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|jtjtjfkS)z0Returns true if the node is an import statement.)rXr�import_namerPr`r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�|dkr�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)NrW)rXr�simple_stmtrQr�r`rrr
�is_import_stmt>s�z$touch_import.<locals>.is_import_stmtNrWrrMrr)r�r�rnrQrXrr�rrArr�rrrSr6r,)r�rr/r��rootZ
insert_pos�offset�idxZnode2�import_rQrrr
�touch_import;s8�
�
r�cCs�|jD�]�}d}|jtjkrVt||jd�r4|St|t|jd�|�}|rR|}�n0|jtjtjfkr�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|jtk�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.Nrrbr^r]�:�rW)rQrXrZfor_stmt�_findr�r�Zif_stmtZ
while_stmtZtry_stmtrnr�COLONr�	_def_syms�_is_import_bindingr�r}r�)rr/r��childZretr:�iZkidrrr
r�isH
r�cCsT|g}|rP|��}|jdkr4|jtkr4|�|j�q|jtjkr|j|kr|SqdS)N�)�poprX�_block_syms�extendrQrrr)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 reuturn node if node will import name, or node
        will import * from package.  None is returned otherwise.
        See test cases for examples. rr^rbNr]�as)rXrr�rQZdotted_as_namesZdotted_as_namerrrrP�str�stripr�rOZimport_as_name�STAR)r/rr�rRr�Zlastr:rrr
r��s@





r�)N)NN)N)N)N)N)N)6�__doc__Zpgen2rZpytreerrZpygramrrr7rrrrrr r%r(r"r0r2r6r8r;r@rCrKrSr\rarcreZconsuming_callsrqrtrurvrsrzrr�r�r�r�r�r�r|r{r�r�r!r�r�r�rrrr
�<module>s`




�		-
*

?>