AlkantarClanX12

Your IP : 3.128.171.192


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/fixes/__pycache__/fix_metaclass.cpython-34.pyo

�
i f
 �@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�q
q
WdS)z� 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')
    ��
__metaclass__TF)
�children�typer�suite�
has_metaclass�simple_stmt�	expr_stmt�
isinstancer�value)�parent�node�	expr_nodeZ	left_side�r�@/opt/alt/python34/lib64/python3.4/lib2to3/fixes/fix_metaclass.pyr
s


r
cCs�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)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�x7t|j�D]"\}}|jtjkrPqqWdS|j�ttjg�}ttj	|g�}xA|j|d�r�|j|}|j
|j��|j�qnW|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%cCs:|jr6|jdjtjkr6|jdj�ndS)Nr���r&)r
rr�NEWLINEr)rrrr�remove_trailing_newline_s"r(ccs�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)NzNo class suite!rr	)r
rrrr�listrrrrrrr%r()rrrZsimple_noderZ	left_noderrr�
find_metasds"


r*cCs�|jddd�}x,|rD|j�}|jtjkrPqqWxm|r�|j�}t|t�r�|jtjkr�|jr�d|_ndS|j	|jddd��qHWdS)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*>
    cCst|�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}d
|jd_d
|jd_|j|�t|�|js�|j�t
|d�}
||
_|j|
�|jt
tjd��n�t|j�dkr|jdjtjkr|jdjtjkrt
|d�}
|jd|
�|jdt
tjd��ndS)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�COMMAr0r'r-r.)�selfrZresultsZlast_metaclassrrZstmtZ	text_typer?rZmeta_txtZorig_meta_prefixrZ	pass_leafrrr�	transform�s^
				


	
	
zFixMetaclass.transformN)�__name__�
__module__�__qualname__Z
BM_compatibleZPATTERNrDrrrrr1�sr1N)�__doc__r+rZpygramrZ
fixer_utilrrrrr
r!r%r(r*r0ZBaseFixr1rrrr�<module>s"