ok

Mini Shell

Direktori : /proc/self/root/lib64/python2.7/lib2to3/
Upload File :
Current File : //proc/self/root/lib64/python2.7/lib2to3/fixer_util.pyc

�
_цdc@sdZddlmZddlmZddlmZmZddlm	Z
ddlmZd�Z
d	�Zd
�Zd�Zd5d�Zd
�Zd�Zd�Ze�e�d�Zd5d5d�Zd�Zd�Zd5d�Zd�Zd5d�Zd5d�Zd�Zd�Zd�Z d�Z!e"ddddd d!d"d#d$d%g
�Z#d&�Z$d'a%d(a&d)a'e(a)d*�Z*d+�Z+d,�Z,d-�Z-d.�Z.d/�Z/d0�Z0d1�Z1e"e
j2e
j3g�Z4d5d2�Z5e"e
j3e
j2e
j6g�Z7d3�Z8d5d4�Z9d5S(6s1Utility functions, node construction macros, etc.i����(tislicei(ttoken(tLeaftNode(tpython_symbols(tpatcompcCs%ttj|ttjd�|g�S(Nu=(RtsymstargumentRRtEQUAL(tkeywordtvalue((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt
KeywordArgs	cCsttjd�S(Nu((RRtLPAR(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytLParenscCsttjd�S(Nu)(RRtRPAR(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytRParenscCslt|t�s|g}nt|t�s?d|_|g}nttj|ttjddd�g|�S(sBuild an assignment statementu u=tprefix(	t
isinstancetlistRRRtatomRRR(ttargettsource((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytAssigns		cCsttj|d|�S(sReturn a NAME leafR(RRtNAME(tnameR((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytName&scCs|ttjt�|g�gS(sA node tuple for obj.attr(RRttrailertDot(tobjtattr((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytAttr*scCsttjd�S(sA comma leafu,(RRtCOMMA(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytComma.scCsttjd�S(sA period (.) leafu.(RRtDOT(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyR2scCsMttj|j�|j�g�}|rI|jdttj|��n|S(s-A parenthesised argument list, used by Call()i(RRRtclonetinsert_childtarglist(targstlparentrparentnode((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytArgList6s$cCs:ttj|t|�g�}|dk	r6||_n|S(sA function callN(RRtpowerR)tNoneR(t	func_nameR%RR(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytCall=scCsttjd�S(sA newline literalu
(RRtNEWLINE(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytNewlineDscCsttjd�S(sA blank lineu(RRR.(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt	BlankLineHscCsttj|d|�S(NR(RRtNUMBER(tnR((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytNumberLscCs1ttjttjd�|ttjd�g�S(sA numeric or string subscriptu[u](RRRRRtLBRACEtRBRACE(t
index_node((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt	SubscriptOscCsttj|d|�S(s
A string leafR(RRtSTRING(tstringR((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytStringUsc	Csd|_d|_d|_ttjd�}d|_ttjd�}d|_||||g}|r�d|_ttjd�}d|_|jttj||g��nttj|ttj	|�g�}ttj
ttjd�|ttjd�g�S(suA list comprehension of the form [xp for fp in it if test].

    If test is None, the "if test" part is omitted.
    uu uforuinuifu[u](
RRRRtappendRRtcomp_ift	listmakertcomp_forRR4R5(	txptfptitttesttfor_leaftin_leaft
inner_argstif_leaftinner((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytListCompYs$							"$	cCsx|D]}|j�qWttjd�ttj|dd�ttjddd�ttj|�g}ttj|�}|S(sO Return an import statement in the form:
        from package import name_leafsufromRu uimport(tremoveRRRRRtimport_as_namestimport_from(tpackage_namet
name_leafstleaftchildrentimp((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt
FromImportqs
c	Cs�t|t�r.|jt�t�gkr.tSt|t�o�t|j�dko�t|jdt�o�t|jdt�o�t|jdt�o�|jdjdko�|jdjdkS(s(Does the node represent a tuple literal?iiiiu(u)(	RRROR
RtTruetlenRR
(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytis_tuple�s*cCszt|t�oyt|j�dkoyt|jdt�oyt|jdt�oy|jdjdkoy|jdjdkS(s'Does the node represent a list literal?iii����u[u](RRRSRORR
(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytis_list�scCsttjt�|t�g�S(N(RRRR
R(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytparenthesize�stsortedRtsettanytallttupletsumtmintmaxt	enumerateccs4t||�}x|r/|Vt||�}qWdS(slFollow 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(tgetattr(RRtnext((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt
attr_chain�s	sefor_stmt< 'for' any 'in' node=any ':' any* >
        | comp_for< 'for' any 'in' node=any any* >
     s�
power<
    ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
      'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
    trailer< '(' node=any ')' >
    any*
>
s`
power<
    ( 'sorted' | 'enumerate' )
    trailer< '(' arglist<node=any any*> ')' >
    any*
>
cCs�ts<tjt�atjt�atjt�atantttg}xRt|t|d��D]8\}}i}|j	||�rd|d|krdtSqdWt
S(s 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.
        tparentR((t
pats_builtRtcompile_patterntp0tp1tp2RRtzipRbtmatchtFalse(R(tpatternstpatternRctresults((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytin_special_context�s	%"cCs�|j}|dk	r+|jtjkr+tS|j}|jtjtj	fkrStS|jtj
kr||jd|kr|tS|jtjks�|jtj
kr�|dk	r�|jtjks�|jd|kr�tStS(sG
    Check that something isn't an attribute or function name etc.
    iN(tprev_siblingR+ttypeRR!RkRcRtfuncdeftclassdeft	expr_stmtROt
parameterst
typedargslistRRR(R(tprevRc((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytis_probably_builtin�s		%cCspxi|dk	rk|jtjkr_t|j�dkr_|jd}|jtjkr_|jSn|j	}qWdS(sFind the indentation of *node*.iiuN(
R+RqRtsuiteRSRORtINDENTR
Rc(R(tindent((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytfind_indentation�s'


cCsW|jtjkr|S|j�}|jd}|_ttj|g�}||_|S(N(RqRRyR"RcR+R(R(RcRy((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt
make_suites	cCs;x4|jtjkr6|j}|std��qqW|S(sFind the top level namespace.s,root found before file_input node was found.(RqRt
file_inputRct
ValueError(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt	find_roots
	cCs"t|t|�|�}t|�S(s� 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. (tfind_bindingR�tbool(tpackageRR(tbinding((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytdoes_tree_importscCs|jtjtjfkS(s0Returns true if the node is an import statement.(RqRtimport_nameRK(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt	is_import"scCs�d�}t|�}t|||�r+dSd}}xnt|j�D]]\}}||�scqEnx1t|j|�D]\}}||�swPqwqwW||}PqEW|dkrxbt|j�D]N\}}|jtjkr�|jr�|jdjtjkr�|d}Pq�q�Wn|dkr\t
tjttj
d�ttj
|dd�g�}	n$t|ttj
|dd�g�}	|	t�g}
|j|t
tj|
��dS(s\ Works like `does_tree_import` but adds an import statement
        if it was not imported. cSs,|jtjko+|jo+t|jd�S(Ni(RqRtsimple_stmtROR�(R(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pytis_import_stmt)sNiiuimportRu (R�R�R_RORqRR�RR8R+RR�RRRQR/R#(R�RR(R�troott
insert_postoffsettidxtnode2timport_RO((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyttouch_import&s4	
 

	!$c	CsKxD|jD]9}d}|jtjkrst||jd�rB|St|t|jd�|�}|r |}q n�|jtjtj	fkr�t|t|jd�|�}|r |}q na|jtj
kr|t|t|jd�|�}|r�|}q xt|jd�D]b\}}|jtj
kr|jdkrt|t|j|d�|�}|ru|}quqqWn�|jtkr�|jdj|kr�|}nvt|||�r�|}n[|jtjkr�t|||�}n4|jtjkr t||jd�r |}q n|r
|s0|St|�rC|Sq
q
WdS(	s� 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.ii����iit:iiN(ROR+RqRtfor_stmtt_findR�R}tif_stmtt
while_stmtttry_stmtR_RtCOLONR
t	_def_symst_is_import_bindingR�RtR�(RR(R�tchildtretR2titkid((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyR�TsH	 !#%		cCs||g}xl|rw|j�}|jdkrO|jtkrO|j|j�q|jtjkr|j|kr|SqWdS(Ni(	tpopRqt_block_symstextendRORRR
R+(RR(tnodes((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyR�s		!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|jtjkr�t
||�r�|S|jtjkr�|jd}|jtjkr |j|kr |Sq#|jtjkr|j|kr|S|r#|jtjkr#|SndS(s� Will reuturn node if node will import name, or node
        will import * from package.  None is returned otherwise.
        See test cases for examples. iii����iuasN(RqRR�ROtdotted_as_namestdotted_as_nameR
RRRKtunicodetstripR+R�RJtimport_as_nametSTAR(R(RR�RPR�tlastR2((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyR��s@
!
!!%
!
!!N(:t__doc__t	itertoolsRtpgen2RtpytreeRRtpygramRRtRRR
RRR+RRR RR)R-R/R0R3R7R:RHRQRTRURVRXtconsuming_callsRbRfRgRhRkRdRoRxR|R}R�R�R�R�RsRrR�R�RR�R�R�(((s*/usr/lib64/python2.7/lib2to3/fixer_util.pyt<module>sZ																									-*	

Zerion Mini Shell 1.0