Viewing File: /opt/alt/python35/lib64/python3.5/lib2to3/fixes/__pycache__/fix_metaclass.cpython-35.pyc



¯ÕYf ã@s­dZddlmZddlmZddlmZmZmZm	Z	dd„Z
dd„Zd	d
„Zdd„Z
d
d„Zdd„ZGdd„dejƒZdS)aŒ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.

é)Ú
fixer_base)Útoken)ÚNameÚsymsÚNodeÚLeafcCs¦xŸ|jD]”}|jtjkr,t|ƒS|jtjkr
|jr
|jd}|jtjkr
|jr
|jd}t|tƒr
|j	dkr
dSq
WdS)zì we have to check the cls_node without changing it.
        There are two possibilities:
          1)  clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta')
          2)  clsdef => simple_stmt => expr_stmt => Leaf('__meta')
    éÚ
__metaclass__TF)
ÚchildrenÚtyperÚsuiteÚ
has_metaclassÚsimple_stmtÚ	expr_stmtÚ
isinstancerÚvalue)ÚparentÚnodeÚ	expr_nodeZ	left_side©rú@/opt/alt/python35/lib64/python3.5/lib2to3/fixes/fix_metaclass.pyr
s


r
cCsÞx'|jD]}|jtjkr
dSq
Wx<t|jƒD]\}}|jtjkr:Pq:Wtdƒ‚ttjgƒ}xI|j|dd…rÆ|j|d}|j	|j
ƒƒ|jƒq~W|j	|ƒ|}dS)zf one-line classes don't get a suite in the parse tree so we add
        one to normalize the tree
    NzNo class suite and no ':'!é)r
rrrÚ	enumeraterÚCOLONÚ
ValueErrorrÚappend_childÚcloneÚremove)Úcls_noderÚirÚ	move_noderrrÚfixup_parse_tree-s
r!c
Csôx4t|jƒD]\}}|jtjkrPqWdS|jƒttjgƒ}ttj	|gƒ}xA|j|d…r«|j|}|j
|jƒƒ|jƒqkW|j||ƒ|jdjd}|jdjd}	|	j
|_
dS)zÑ 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 after the semi-colon into its own simple_stmt node
    Nr)rr
rrÚSEMIrrrrrrrÚinsert_childÚprefix)
rrZ	stmt_nodeZsemi_indrZnew_exprZnew_stmtr Z	new_leaf1Z	old_leaf1rrrÚfixup_simple_stmtGs

r%cCs7|jr3|jdjtjkr3|jdjƒdS)Nréÿÿÿÿr&)r
rrÚNEWLINEr)rrrrÚremove_trailing_newline_s"r(ccsóx0|jD]}|jtjkr
Pq
Wtdƒ‚x¹tt|jƒƒD]¢\}}|jtjkrI|jrI|jd}|jtjkrI|jrI|jd}t	|t
ƒrI|jdkrIt|||ƒt
|ƒ|||fVqIWdS)NzNo class suite!rr	)r
rrrrÚlistrrrrrrr%r()rrrZsimple_noderZ	left_noderrrÚ
find_metasds"


r*cCs³|jddd…}x)|rA|jƒ}|jtjkrPqWxj|r®|jƒ}t|tƒrŽ|jtjkrŽ|jrŠd|_dS|j	|jddd…ƒqEWdS)z› 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
    NrÚr&r&)
r
ÚpoprrÚINDENTrrÚDEDENTr$Úextend)rZkidsrrrrÚfixup_indent{s		!		r0c@s(eZdZdZdZdd„ZdS)ÚFixMetaclassTz
    classdef<any*>
    cCs$t|ƒsdSt|ƒd}x-t|ƒD]\}}}|}|jƒq-W|jdj}t|jƒdkrÙ|jdjtjkrž|jd}q‘|jdj	ƒ}	t
tj|	gƒ}|jd|ƒn¸t|jƒdkrt
tjgƒ}|jd|ƒn~t|jƒdkr…t
tjgƒ}|jdt
tjdƒƒ|jd|ƒ|jdt
tjdƒƒntd	ƒ‚|jdjd}
d
|
_|
j}|jrå|jt
tjdƒƒd|
_n	d
|
_|jd}|jtjkst‚d
|jd_d
|jd_|j|ƒt|ƒ|jsž|jƒt
|dƒ}
||
_|j|
ƒ|jt
tjdƒƒn‚t|jƒdkr |jdjtjkr |jdjtjkr t
|dƒ}
|jd|
ƒ|jdt
tjdƒƒdS)Nréééérú)ú(zUnexpected class definitionÚ	metaclassú,ú r+rÚpassÚ
éþÿÿÿr&r&r&)r
r!r*rr
rÚlenrÚarglistrrZ	set_childr#rrÚRPARÚLPARrrr$rÚCOMMArÚAssertionErrorr0r'r-r.)ÚselfrZresultsZlast_metaclassrrZstmtZ	text_typer?rZmeta_txtZorig_meta_prefixrZ	pass_leafrrrÚ	transform˜s`
				


	
	
zFixMetaclass.transformN)Ú__name__Ú
__module__Ú__qualname__Z
BM_compatibleZPATTERNrErrrrr1‘sr1N)Ú__doc__r+rZpygramrZ
fixer_utilrrrrr
r!r%r(r*r0ZBaseFixr1rrrrÚ<module>s"
Back to Directory File Manager