tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
X\¬Qc @sdZddlmZddlmZddlmZmZddlm    Z
ddl m 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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyt
KeywordArgs    cCsttjdƒS(Nu((RRtLPAR(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytLParenscCsttjdƒS(Nu)(RRtRPAR(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytAssigns          cCsttj|d|ƒS(sReturn a NAME leafR(RRtNAME(tnameR((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytName&scCs|ttjtƒ|gƒgS(sA node tuple for obj.attr(RRttrailertDot(tobjtattr((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytAttr*scCsttjdƒS(s A comma leafu,(RRtCOMMA(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytComma.scCsttjdƒS(sA period (.) leafu.(RRtDOT(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytArgList6s$cCs:ttj|t|ƒgƒ}|dk    r6||_n|S(sA function callN(RRtpowerR)tNoneR(t    func_nameR%RR(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytCall=s  cCsttjdƒS(sA newline literalu
(RRtNEWLINE(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytNewlineDscCsttjdƒS(s A blank lineu(RRR.(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyt    BlankLineHscCsttj|d|ƒS(NR(RRtNUMBER(tnR((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytNumberLscCs1ttjttjdƒ|ttjdƒgƒS(sA numeric or string subscriptu[u](RRRRRtLBRACEtRBRACE(t
index_node((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyt    SubscriptOscCsttj|d|ƒS(s A string leafR(RRtSTRING(tstringR((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytStringUsc    Csd|_d|_d|_ttjdƒ}d|_ttjdƒ}d|_||||g}|r¯d|_ttjdƒ}d|_|jttj||gƒƒnttj|ttj    |ƒgƒ}ttj
ttj dƒ|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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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_namest import_from(t package_namet
name_leafstleaftchildrentimp((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytis_list•s cCsttjtƒ|tƒgƒS(N(RRRR R(R(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytin_special_contextÐs    %"cCsÙ|j}|dk    r+|jtjkr+tS|j}|jtjtj    fkrStS|jtj
kr||j d|kr|tS|jtj ksÑ|jtj krÕ|dk    r¾|jtjksÑ|j d|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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytfind_indentationús' 
 cCsW|jtjkr|S|jƒ}|jd}|_ttj|gƒ}||_|S(N(RqRRyR"RcR+R(R(RcRy((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytdoes_tree_importscCs|jtjtjfkS(s0Returns true if the node is an import statement.(RqRt import_nameRK(R(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyt    is_import"sc Cs¯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
tj t 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(RqRt simple_stmtROR‡(R(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pytis_import_stmt)sNiiuimportRu (R€R…R_RORqRRˆRR8R+RR†RRRQR/R#( RƒRR(R‰troott
insert_postoffsettidxtnode2timport_RO((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyR™‰s@ !  !!% ! !!N(:t__doc__t    itertoolsRtpgen2RtpytreeRRtpygramRRtRR R RRR+RRR RR)R-R/R0R3R7R:RHRQRTRURVRXtconsuming_callsRbRfRgRhRkRdRoRxR|R}R€R…R‡RRsRrR˜RRRŸR“R™(((sZ/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixer_util.pyt<module>sZ                                                                                                        - *