Your IP : 18.118.120.13


Current Path : /opt/alt/python33/lib64/python3.3/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/lib2to3/fixes/__pycache__/fix_metaclass.cpython-33.pyo

�
��f	 c@s�dZddlmZddlmZddlmZmZmZm	Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�ZGdd�dej�ZdS(u�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(u
fixer_base(utoken(uNameusymsuNodeuLeafcCs�x�|jD]�}|jtjkr,t|�S|jtjkr
|jr
|jd}|jtjkr�|jr�|jd}t|t�r�|j	dkr�dSq�q
q
WdS(u� 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')
    iu
__metaclass__TF(uchildrenutypeusymsusuiteu
has_metaclassusimple_stmtu	expr_stmtu
isinstanceuLeafuvalueuTrueuFalse(uparentunodeu	expr_nodeu	left_side((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyu
has_metaclasss


u
has_metaclasscCs�x'|jD]}|jtjkr
dSq
Wx?t|j�D]"\}}|jtjkr:Pq:q:Wtd��ttjg�}xI|j|dd�r�|j|d}|j	|j
��|j�q�W|j	|�|}dS(uf one-line classes don't get a suite in the parse tree so we add
        one to normalize the tree
    NuNo class suite and no ':'!i(uchildrenutypeusymsusuiteu	enumerateutokenuCOLONu
ValueErroruNodeuappend_childucloneuremove(ucls_nodeunodeuiusuiteu	move_node((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyufixup_parse_tree-s
ufixup_parse_treec
Cs�x7t|j�D]"\}}|jtjkrPqqWdS|j�ttjg�}ttj	|g�}xA|j|d�r�|j|}|j
|j��|j�qnW|j||�|jdjd}|jdjd}	|	j
|_
dS(u� 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
    Ni(u	enumerateuchildrenutypeutokenuSEMIuremoveuNodeusymsu	expr_stmtusimple_stmtuappend_childucloneuinsert_childuprefix(
uparentuiu	stmt_nodeusemi_indunodeunew_exprunew_stmtu	move_nodeu	new_leaf1u	old_leaf1((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyufixup_simple_stmtGs

ufixup_simple_stmtcCs:|jr6|jdjtjkr6|jdj�ndS(Nii����i����(uchildrenutypeutokenuNEWLINEuremove(unode((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyuremove_trailing_newline_s"uremove_trailing_newlineccs�x3|jD]}|jtjkr
Pq
q
Wtd��x�tt|j��D]�\}}|jtjkrL|jrL|jd}|jtjkr�|jr�|jd}t	|t
�r�|jdkr�t|||�t
|�|||fVq�q�qLqLWdS(NuNo class suite!iu
__metaclass__(uchildrenutypeusymsusuiteu
ValueErrorulistu	enumerateusimple_stmtu	expr_stmtu
isinstanceuLeafuvalueufixup_simple_stmturemove_trailing_newline(ucls_nodeunodeuiusimple_nodeu	expr_nodeu	left_node((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyu
find_metasds"


u
find_metascCs�|jddd�}x,|rD|j�}|jtjkrPqqWxm|r�|j�}t|t�r�|jtjkr�|jr�d|_ndS|j	|jddd��qHWdS(u� 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
    Niui����i����(
uchildrenupoputypeutokenuINDENTu
isinstanceuLeafuDEDENTuprefixuextend(usuiteukidsunode((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyufixup_indent{s		!	ufixup_indentcBs,|EeZdZdZdZdd�ZdS(uFixMetaclassu
    classdef<any*>
    cCst|�sdSt|�d}x-t|�D]\}}}|}|j�q-W|jdj}t|j�dkr�|jdjtj	kr�|jd}q�|jdj
�}	ttj	|	g�}|jd|�n�t|j�dkrttj	g�}|j
d|�n~t|j�dkr�ttj	g�}|j
dttjd��|j
d|�|j
dttjd��ntd	��|jdjd}
d
|
_|
j}|jr�|jttjd��d|
_n	d
|
_|jd}d
|jd_d
|jd_|j|�t|�|js�|j�t|d�}
||
_|j|
�|jttjd��n�t|j�dkr|jdjtjkr|jdjtjkrt|d�}
|j
d|
�|j
dttjd��ndS(Niiiiiiu)u(uUnexpected class definitionu	metaclassu,u uiupassu
i����i����i����i����(u
has_metaclassufixup_parse_treeuNoneu
find_metasuremoveuchildrenutypeulenusymsuarglistucloneuNodeu	set_childuinsert_childuLeafutokenuRPARuLPARu
ValueErroruvalueuprefixuappend_childuCOMMAufixup_indentuNEWLINEuINDENTuDEDENT(uselfunodeuresultsulast_metaclassusuiteuiustmtu	text_typeuarglistuparentumeta_txtuorig_meta_prefixu	expr_stmtu	pass_leaf((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyu	transform�s^
				


	
	
uFixMetaclass.transformNT(u__name__u
__module__u__qualname__uTrueu
BM_compatibleuPATTERNu	transform(u
__locals__((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyuFixMetaclass�suFixMetaclassN(u__doc__uu
fixer_baseupygramutokenu
fixer_utiluNameusymsuNodeuLeafu
has_metaclassufixup_parse_treeufixup_simple_stmturemove_trailing_newlineu
find_metasufixup_indentuBaseFixuFixMetaclass(((u@/opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_metaclass.pyu<module>s"

?>