ok

Mini Shell

Direktori : /lib64/python3.6/lib2to3/__pycache__/
Upload File :
Current File : //lib64/python3.6/lib2to3/__pycache__/fixer_util.cpython-36.opt-1.pyc

3


 \g;�
@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�*/usr/lib64/python3.6/lib2to3/fixer_util.py�
KeywordArgsrcCs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 leaf)r)rr�NAME)�namerrrr
�Name$srcCs|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|j�|j�g�}|r0|jdttj|��|S)z-A parenthesised argument list, used by Call()r)rrr �clone�insert_child�arglist)�argsZlparenZrparen�noderrr
�ArgList4sr/cCs&ttj|t|�g�}|dk	r"||_|S)zA function callN)rr�powerr/r)Z	func_namer-rr.rrr
�Call;sr1cCsttjd�S)zA newline literal�
)rr�NEWLINErrrr
�NewlineBsr4cCsttjd�S)zA blank line�)rrr3rrrr
�	BlankLineFsr6cCsttj||d�S)N)r)rr�NUMBER)�nrrrr
�NumberJsr9cCs"ttjttjd�|ttjd�g�S)zA numeric or string subscript�[�])rrr rr�LBRACE�RBRACE)Z
index_noderrr
�	SubscriptMsr>cCsttj||d�S)z
A string leaf)r)rr�STRING)�stringrrrr
�StringSsrAc	Cs�d|_d|_d|_ttjd�}d|_ttjd�}d|_||||g}|rtd|_ttjd�}d|_|jttj||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.
    r5r�for�in�ifr:r;)
rrrr�appendrrZcomp_ifZ	listmakerZcomp_forrr<r=)	Zxp�fp�itZtestZfor_leafZin_leafZ
inner_argsZif_leaf�innerrrr
�ListCompWs$
rIcCsZx|D]}|j�qWttjd�ttj|dd�ttjddd�ttj|�g}ttj|�}|S)zO Return an import statement in the form:
        from package import name_leafs�fromr)r�import)�removerrrrr�import_as_names�import_from)Zpackage_nameZ
name_leafsZleaf�children�imprrr
�
FromImportos

rQc	Cs�|dj�}|jtjkr"|j�}nttj|j�g�}|d}|rNdd�|D�}ttjtt|d�t|d��ttj|dj�||dj�g�g|�}|j	|_	|S)	zfReturns an import statement and calls a method
    of the module:

    import module
    module.name()r"�aftercSsg|]}|j��qSr)r*)�.0r8rrr
�
<listcomp>�sz!ImportAndCall.<locals>.<listcomp>�rZlparZrpar)
r*�typerr,rr0r$rr r)r.�results�namesr"Z
newarglistrR�newrrr
�
ImportAndCall�s
DrZcCs�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�rUr�rr)rrrOrr�lenrr)r.rrr
�is_tuple�s
r^cCsXt|t�oVt|j�dkoVt|jdt�oVt|jdt�oV|jdjdkoV|jdjdkS)z'Does the node represent a list literal?rrUr:r;���r_)rrr]rOrr)r.rrr
�is_list�s
r`cCsttjt�|t�g�S)N)rrrrr)r.rrr
�parenthesize�sra�sortedr�set�any�all�tuple�sum�min�max�	enumerateccs(t||�}x|r"|Vt||�}qWdS)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
rmzefor_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*
>
FcCsrts&tjt�atjt�atjt�adatttg}x<t|t|d��D](\}}i}|j||�rB|d|krBdSqBWdS)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�ziprm�match)r.Zpatterns�patternrnrWrrr
�in_special_context�s



rvcCs�|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.
    NFrUT)
Zprev_siblingrVrr)rnr�funcdef�classdef�	expr_stmtrOZ
parametersZ
typedargslistr&)r.�prevrnrrr
�is_probably_builtin�sr{cCsNxH|dk	rH|jtjkr@t|j�dkr@|jd}|jtjkr@|jS|j}qWdS)zFind the indentation of *node*.Nr\rr5)	rVr�suiter]rOr�INDENTrrn)r.�indentrrr
�find_indentations


rcCs>|jtjkr|S|j�}|jd}|_ttj|g�}||_|S)N)rVrr|r*rnr)r.rnr|rrr
�
make_suitesr�cCs(x"|jtjkr"|j}|std��qW|S)zFind the top level namespace.z,root found before file_input node was found.)rVrZ
file_inputrn�
ValueError)r.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.)rVr�import_namerN)r.rrr
�	is_import7sr�cCs4dd�}t|�}t|||�r dSd}}xTt|j�D]F\}}||�sFq4x(t|j|d��D]\}}||�sZPqZW||}Pq4W|dkr�xDt|j�D]6\}}|jtjkr�|jr�|jdjtjkr�|d}Pq�W|dkr�t	tj
ttjd�ttj|dd�g�}	nt
|ttj|dd�g�}	|	t�g}
|j|t	tj|
��dS)	z\ Works like `does_tree_import` but adds an import statement
        if it was not imported. cSs |jtjko|jot|jd�S)NrU)rVr�simple_stmtrOr�)r.rrr
�is_import_stmt>sz$touch_import.<locals>.is_import_stmtNrUrrKr)r)r�r�rjrOrVrr�rr?rr�rrrQr4r+)r�rr.r��rootZ
insert_pos�offset�idxZnode2�import_rOrrr
�touch_import;s4

r�cCs��x�|jD�]�}d}|jtjkrVt||jd�r4|St|t|jd�|�}|rR|}�n4|jtjtjfkr�t|t|jd	�|�}|r�|}�n|jtj	k�rt|t|jd�|�}|r�|}nXx�t
|jdd��D]@\}}|jtjko�|j
dkr�t|t|j|d�|�}|r�|}q�Wnx|jtk�r6|jdj
|k�r6|}nTt|||��rJ|}n@|jtjk�rft|||�}n$|jtjk�r�t||jd��r�|}|r
|�s�|St|�r
|Sq
WdS)
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.Nrr\r[�:�rUr_r_)rOrVrZfor_stmt�_findr�r�Zif_stmtZ
while_stmtZtry_stmtrjr�COLONr�	_def_syms�_is_import_bindingr�ryr�)rr.r��childZretr8�iZkidrrr
r�isH
r�cCsX|g}xL|rR|j�}|jdkr6|jtkr6|j|j�q|jtjkr|j|kr|SqWdS)N�)�poprV�_block_syms�extendrOrrr)rr.Znodesrrr
r��sr�cCs�|jtjkr�|r�|jd}|jtjkrvx�|jD]@}|jtjkrV|jdj|krp|Sq0|jtjkr0|j|kr0|Sq0WnL|jtjkr�|jd}|jtjkr�|j|kr�|Sn|jtjkr�|j|kr�|Sn�|jtj	k�r�|r�t
|jd�j�|kr�dS|jd}|�rtd|��rdS|jtj
k�r.t||��r.|S|jtjk�rf|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\Nr[�asr_)rVrr�rOZdotted_as_namesZdotted_as_namerrrrN�str�stripr�rMZimport_as_name�STAR)r.rr�rPr�Zlastr8rrr
r��s@




r�)N)NN)N)N)N)N)N)6�__doc__Zpgen2rZpytreerrZpygramrrr5rrrrrrr$r'r!r/r1r4r6r9r>rArIrQrZr^r`raZconsuming_callsrmrprqrrrorvr{rr�r�r�r�r�rxrwr�r�r r�r�r�rrrr
�<module>sZ





		-
*

Zerion Mini Shell 1.0