AlkantarClanX12

Your IP : 18.189.194.44


Current Path : /proc/self/root/usr/lib64/python3.6/lib2to3/fixes/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.6/lib2to3/fixes/__pycache__/fix_metaclass.cpython-36.pyc

3


 \ �@svdZddlmZddlmZddlmZmZmZdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�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)�syms�Node�LeafcCsxxr|jD]h}|jtjkr t|�S|jtjkr|jr|jd}|jtjkr|jr|jd}t|t�r|j	dkrdSqWdS)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�3/usr/lib64/python3.6/lib2to3/fixes/fix_metaclass.pyrs



rcCs�x|jD]}|jtjkrdSqWx,t|j�D]\}}|jtjkr,Pq,Wtd��ttjg�}x:|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	r
rr�	enumerater�COLON�
ValueErrorr�append_child�clone�remove)�cls_noder�ir�	move_noderrr�fixup_parse_tree-s
r c
Cs�x(t|j�D]\}}|jtjkrPqWdS|j�ttjg�}ttj	|g�}x2|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	r
r�SEMIrrrrr
rr�insert_child�prefix)
rrZ	stmt_nodeZsemi_indrZnew_exprZnew_stmtrZ	new_leaf1Z	old_leaf1rrr�fixup_simple_stmtGs
r$cCs*|jr&|jdjtjkr&|jdj�dS)Nr���r%)r	r
r�NEWLINEr)rrrr�remove_trailing_newline_sr'ccs�x$|jD]}|jtjkrPqWtd��x�tt|j��D]t\}}|jtjkr6|jr6|jd}|jtjkr6|jr6|jd}t	|t
�r6|jdkr6t|||�t
|�|||fVq6WdS)NzNo class suite!rr)r	r
rrr�listrr
rrrrr$r')rrrZsimple_noderZ	left_noderrr�
find_metasds



r)cCs�|jddd�}x|r.|j�}|jtjkrPqWxL|r||j�}t|t�rd|jtjkrd|jr`d|_dS|j	|jddd��q2WdS)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	�popr
r�INDENTrr�DEDENTr#�extend)rZkidsrrrr�fixup_indent{sr/c@seZdZdZdZdd�ZdS)�FixMetaclassTz
    classdef<any*>
    cCsNt|�sdSt|�d}x"t|�D]\}}}|}|j�q"W|jdj}t|j�dkr�|jdjtjkrt|jd}n(|jdj	�}	t
tj|	g�}|jd|�n�t|j�dkr�t
tjg�}|jd|�nZt|j�dk�rt
tjg�}|jdt
tjd��|jd|�|jdt
tjd��ntd	��|jdjd}
d
|
_|
j}|j�r^|jt
tjd��d|
_nd
|
_|jd}|jtjk�s�t�d
|jd_d
|jd_|j|�t|�|j�s�|j�t
|d�}
||
_|j|
�|jt
tjd��nbt|j�dk�rJ|jdjtjk�rJ|jdjtjk�rJt
|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�AssertionErrorr/r&r,r-)�selfrZresultsZlast_metaclassrrZstmtZ	text_typer>rZmeta_txtZorig_meta_prefixrZ	pass_leafrrr�	transform�s`




zFixMetaclass.transformN)�__name__�
__module__�__qualname__Z
BM_compatibleZPATTERNrDrrrrr0�sr0N)�__doc__r*rZpygramrZ
fixer_utilrrrrr r$r'r)r/ZBaseFixr0rrrr�<module>s