Your IP : 3.145.44.46


Current Path : /opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/fixer_util.cpython-35.opt-1.pyc



��Yf�;�
@svdZddlmZddlmZddlmZmZddlm	Z
ddlmZdd	�Z
d
d�Zdd
�Zdd�Zddd�Zdd�Zdd�Zdd�Ze�e�dd�Zdddd�Zdd�Zdd �Zdd!d"�Zd#d$�Zdd%d&�Zdd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4d5d6d7d8d9d:d;d<h
Z"d=d>�Z#d?a$d@a%dAa&dBa'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+dKdL�Z,dMdN�Z-dOdP�Z.dQdR�Z/e
j0e
j1hZ2ddSdT�Z3e
j1e
j0e
j4hZ5dUdV�Z6ddWdX�Z7dS)Yz1Utility functions, node construction macros, etc.�)�islice�)�token)�Leaf�Node)�python_symbols)�patcompcCs%ttj|ttjd�|g�S)N�=)r�symsZargumentrr�EQUAL)�keyword�value�r�7/opt/alt/python35/lib64/python3.5/lib2to3/fixer_util.py�
KeywordArgs	rcCsttjd�S)N�()rr�LPARrrrr�LParensrcCsttjd�S)N�))rr�RPARrrrr�RParensrcCsft|t�s|g}t|t�s9d|_|g}ttj|ttjddd�g|�S)zBuild an assignment statement� r	�prefix)	�
isinstance�listrrr
�atomrrr)�target�sourcerrr�Assigns				rNcCsttj|d|�S)zReturn a NAME leafr)rr�NAME)�namerrrr�Name&sr!cCs|ttjt�|g�gS)zA node tuple for obj.attr)rr
�trailer�Dot)�obj�attrrrr�Attr*sr&cCsttjd�S)zA comma leaf�,)rr�COMMArrrr�Comma.sr)cCsttjd�S)zA period (.) leaf�.)rr�DOTrrrrr#2sr#cCsJttj|j�|j�g�}|rF|jdttj|��|S)z-A parenthesised argument list, used by Call()r)rr
r"�clone�insert_child�arglist)�argsZlparenZrparen�noderrr�ArgList6s$r1cCs7ttj|t|�g�}|dk	r3||_|S)zA function callN)rr
�powerr1r)Z	func_namer/rr0rrr�Call=s	r3cCsttjd�S)zA newline literal�
)rr�NEWLINErrrr�NewlineDsr6cCsttjd�S)zA blank line�)rrr5rrrr�	BlankLineHsr8cCsttj|d|�S)Nr)rr�NUMBER)�nrrrr�NumberLsr;cCs1ttjttjd�|ttjd�g�S)zA numeric or string subscript�[�])rr
r"rr�LBRACE�RBRACE)Z
index_noderrr�	SubscriptOsr@cCsttj|d|�S)z
A string leafr)rr�STRING)�stringrrrr�StringUsrCc	Csd|_d|_d|_ttjd�}d|_ttjd�}d|_||||g}|r�d|_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.
    r7r�for�in�ifr<r=)
rrrr�appendrr
Zcomp_ifZ	listmakerZcomp_forrr>r?)	Zxp�fp�itZtestZfor_leafZin_leafZ
inner_argsZif_leaf�innerrrr�ListCompYs$							$	rKcCsx|D]}|j�qWttjd�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�imprrr�
FromImportqs
rSc	Cs�|dj�}|jtjkr1|j�}nttj|j�g�}|d}|rodd�|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,)�.0r:rrr�
<listcomp>�s	z!ImportAndCall.<locals>.<listcomp>rrZlparZrpar)
r,�typer
r.rr2r&r!r"r)r0�results�namesr$Z
newarglistrT�newrrr�
ImportAndCall�s
	Z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�rr�rr)rrrQrr�lenrr
)r0rrr�is_tuple�s*r_cCszt|t�oyt|j�dkoyt|jdt�oyt|jdt�oy|jdjdkoy|jdjdkS)z'Does the node represent a list literal?rrr<r=���r`)rrr^rQrr
)r0rrr�is_list�sracCsttjt�|t�g�S)N)rr
rrr)r0rrr�parenthesize�srb�sortedr�set�any�all�tuple�sum�min�max�	enumerateccs4t||�}x|r/|Vt||�}qWdS)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%�nextrrr�
attr_chain�s	rnzefor_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*
>
FcCs�ts9tjt�atjt�atjt�adatttg}xRt|t|d��D]8\}}i}|j||�ra|d|kradSqaWdS)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�parentr0F)	�
pats_builtrZcompile_pattern�p0�p1�p2�ziprn�match)r0Zpatterns�patternrorXrrr�in_special_context�s%"rwcCs�|j}|dk	r+|jtjkr+dS|j}|jtjtjfkrSdS|jtjkr||j	d|kr|dS|jtj
ks�|jtjkr�|dk	r�|jtjks�|j	d|kr�dSdS)zG
    Check that something isn't an attribute or function name etc.
    NFrT)
Zprev_siblingrWrr+ror
�funcdef�classdef�	expr_stmtrQZ
parametersZ
typedargslistr()r0�prevrorrr�is_probably_builtin�s		%r|cCsmxf|dk	rh|jtjkr\t|j�dkr\|jd}|jtjkr\|jS|j}qWdS)zFind the indentation of *node*.Nr]rr7)	rWr
�suiter^rQr�INDENTr
ro)r0�indentrrr�find_indentations'

r�cCsW|jtjkr|S|j�}|jd}|_ttj|g�}||_|S)N)rWr
r}r,ror)r0ror}rrr�
make_suites	r�cCs8x1|jtjkr3|j}|std��qW|S)zFind the top level namespace.z,root found before file_input node was found.)rWr
Z
file_inputro�
ValueError)r0rrr�	find_root(s
	r�cCs"t|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)�packager r0Zbindingrrr�does_tree_import1sr�cCs|jtjtjfkS)z0Returns true if the node is an import statement.)rWr
�import_namerP)r0rrr�	is_import9sr�cCs�dd�}t|�}t|||�r.dSd}}xnt|j�D]]\}}||�scqHx4t|j|d��D]\}}||�s}Pq}W||}PqHW|dkrx\t|j�D]K\}}|jtjkr�|jr�|jdjtjkr�|d}Pq�W|dkrYt	tj
ttjd�ttj|dd�g�}	n$t
|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+|jo+t|jd�S)Nr)rWr
�simple_stmtrQr�)r0rrr�is_import_stmt@sz$touch_import.<locals>.is_import_stmtNrrrMrr)r�r�rkrQrWr
r�rrArr�rrrSr6r-)r�r r0r��rootZ
insert_pos�offset�idxZnode2�import_rQrrr�touch_import=s4
&

	!$r�cCs<x5|jD]*}d}|jtjkrpt||jd�rB|St|t|jd�|�}|r|}n�|jtjtjfkr�t|t|jd	�|�}|r|}n[|jtj	krvt|t|jd�|�}|r�|}qxt
|jdd��D]\\}}|jtjkr|j
dkrt|t|j|d�|�}|r|}qWn�|jtkr�|jdj
|kr�|}npt|||�r�|}nU|jtjkr�t|||�}n.|jtjkrt||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\�:�rr`r`)rQrWr
Zfor_stmt�_findr�r�Zif_stmtZ
while_stmtZtry_stmtrkr�COLONr
�	_def_syms�_is_import_bindingr�rzr�)r r0r��childZretr:�iZkidrrrr�ksH			&!#
%		r�cCs||g}xl|rw|j�}|jdkrO|jtkrO|j|j�q|jtjkr|j|kr|SqWdS)N�)�poprW�_block_syms�extendrQrrr
)r r0Znodesrrrr��s		!r�cCs$|jtjkr|r|jd}|jtjkr�x�|jD]Z}|jtjkrw|jdj|kr�|SqB|jtjkrB|j|krB|SqBWq |jtjkr�|jd}|jtjkr|j|kr|Sq |jtjkr |j|kr |Sn|jtj	kr |rMt
|jd�j�|krMdS|jd}|rstd|�rsdS|jtj
kr�t||�r�|S|jtjkr�|jd}|jtjkr |j|kr |SnA|jtjkr|j|kr|S|r |jtjkr |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`)rWr
r�rQZdotted_as_namesZdotted_as_namer
rrrP�str�stripr�rOZimport_as_name�STAR)r0r r�rRr�Zlastr:rrrr��s@
!
!!%
!
!!r�)8�__doc__�	itertoolsrZpgen2rZpytreerrZpygramrr
r7rrrrrr!r&r)r#r1r3r6r8r;r@rCrKrSr[r_rarbZconsuming_callsrnrqrrrsrprwr|r�r�r�r�r�r�ryrxr�r�r"r�r�r�rrrr�<module>s\		-*

?>