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
Y\¬Qc@s›dZddlmZddlmZddlmZmZmZm    Z    d„Z
d„Z d„Z d„Z d    „Zd
„Zd ejfd „ƒYZd S(sŒFixer for __metaclass__ = X -> (metaclass=X) methods.
 
   The various forms of classef (inherits nothing, inherits once, inherints
   many) don't parse the same in the CST so we look at ALL classes for
   a __metaclass__ and if we find one normalize the inherits to all be
   an arglist.
 
   For one-liner classes ('class X: pass') there is no indent/dedent so
   we normalize those into having a suite.
 
   Moving the __metaclass__ into the classdef can also cause the class
   body to be empty so there is some special casing for that as well.
 
   This fixer also tries very hard to keep original indenting and spacing
   in all those corner cases.
 
i(t
fixer_base(ttoken(tNametsymstNodetLeafcCs¬x¥|jD]š}|jtjkr,t|ƒS|jtjkr
|jr
|jd}|jtjkr¤|jr¤|jd}t|tƒr¡|j    dkr¡t
Sq¤q
q
Wt S(së we have to check the cls_node without changing it.
        There are two possiblities:
          1)  clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta')
          2)  clsdef => simple_stmt => expr_stmt => Leaf('__meta')
    it __metaclass__( tchildrenttypeRtsuitet has_metaclasst simple_stmtt    expr_stmtt
isinstanceRtvaluetTruetFalse(tparenttnodet    expr_nodet    left_side((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyR
s
  cCsÛx'|jD]}|jtjkr
dSq
Wx?t|jƒD]"\}}|jtjkr:Pq:q:Wtdƒ‚ttjgƒ}xC|j|drÃ|j|d}|j    |j
ƒƒ|j ƒqW|j    |ƒ|}dS(sf one-line classes don't get a suite in the parse tree so we add
        one to normalize the tree
    NsNo class suite and no ':'!i( RRRR    t    enumerateRtCOLONt
ValueErrorRt append_childtclonetremove(tcls_nodeRtiR    t    move_node((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pytfixup_parse_tree-s  c
Csñx7t|jƒD]"\}}|jtjkrPqqWdS|jƒttjgƒ}ttj    |gƒ}x;|j|r¨|j|}|j
|j ƒƒ|jƒqnW|j ||ƒ|jdjd}|jdjd}    |    j |_ dS(sÑ if there is a semi-colon all the parts count as part of the same
        simple_stmt.  We just want the __metaclass__ part so we move
        everything efter the semi-colon into its own simple_stmt node
    Ni(RRRRtSEMIRRRR R RRt insert_childtprefix(
RRt    stmt_nodetsemi_indRtnew_exprtnew_stmtRt    new_leaf1t    old_leaf1((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pytfixup_simple_stmtGs
 cCs:|jr6|jdjtjkr6|jdjƒndS(Niÿÿÿÿ(RRRtNEWLINER(R((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pytremove_trailing_newline_s"ccsÿx3|jD]}|jtjkr
Pq
q
Wtdƒ‚xÂtt|jƒƒD]«\}}|jtjkrL|jrL|jd}|jtjkr÷|jr÷|jd}t    |t
ƒrô|j dkrôt |||ƒt |ƒ|||fVqôq÷qLqLWdS(NsNo class suite!iu __metaclass__(RRRR    RtlistRR R R RRR(R*(RRRt simple_nodeRt    left_node((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyt
find_metasds "  
cCs¹|jddd…}x,|rD|jƒ}|jtjkrPqqWxm|r´|jƒ}t|tƒr”|jtjkr”|jrd|_ndS|j    |jddd…ƒqHWdS(s› If an INDENT is followed by a thing with a prefix then nuke the prefix
        Otherwise we get in trouble when removing __metaclass__ at suite start
    Niÿÿÿÿu(
RtpopRRtINDENTR RtDEDENTR!textend(R    tkidsR((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyt fixup_indent{s          !     t FixMetaclasscBseZeZdZd„ZRS(s
    classdef<any*>
    cCs't|ƒsdSt|ƒd}x-t|ƒD]\}}}|}|jƒq-W|jdj}t|jƒdkrÙ|jdjtj    krž|jd}q‘|jdj
ƒ}    t tj    |    gƒ}|j d|ƒn¸t|jƒdkrt tj    gƒ}|j d|ƒn~t|jƒdkr…t tj    gƒ}|j dttjdƒƒ|j d|ƒ|j dttjdƒƒn td    ƒ‚|jdjd}
d
|
_|
j} |jrå|jttjd ƒƒd |
_n    d |
_|jd} | jtjkst‚d | jd_d | jd_|j|ƒt|ƒ|jsž|jƒt|dƒ} | | _|j| ƒ|jttjdƒƒn…t|jƒdkr#|jdjtjkr#|jdjtjkr#t|dƒ} |j d| ƒ|j dttjdƒƒndS(Niiiiiiu)u(sUnexpected class definitiont    metaclassu,u uiupassu
iþÿÿÿiÿÿÿÿ(R
RtNoneR.RRRtlenRtarglistRRt    set_childR RRtRPARtLPARRRR!RtCOMMAR tAssertionErrorR4R)R0R1(tselfRtresultstlast_metaclassR    Rtstmtt    text_typeR9Rtmeta_txttorig_meta_prefixR t    pass_leaf((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyt    transform˜s` 
                    
    
     (t__name__t
__module__Rt BM_compatibletPATTERNRG(((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyR5‘sN(t__doc__tRtpygramRt
fixer_utilRRRRR
RR(R*R.R4tBaseFixR5(((sc/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/lib2to3/fixes/fix_metaclass.pyt<module>s"