Spade
Mini Shell
| Directory:~$ /proc/self/root/lib/python2.7/site-packages/libfuturize/fixes/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@s�dZddlmZddlmZddlmZmZmZm Z m
Z
mZmZm
Z
mZd�Zd�Zd�Zd�Zd �Zd
�Zdejfd��YZd
S(s�Fixer for __metaclass__ = X ->
(future.utils.with_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( tNametsymstNodetLeafttouch_importtCalltStringtCommatparenthesizecCs�x�|jD]�}|jtjkr,t|�S|jtjkr
|jr
|jd}|jtjkr�|jr�|jd}t|t�r�|j dkr�t
Sq�q
q
WtS(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_metaclasstsimple_stmtt expr_stmtt
isinstanceRtvaluetTruetFalse(tparenttnodet expr_nodet left_side((sC/usr/lib/python2.7/site-packages/libfuturize/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(RR
RRt enumerateRtCOLONt
ValueErrorRtappend_childtclonetremove(tcls_nodeRtiRt move_node((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pytfixup_parse_tree9s
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(RRR
RtSEMIRRRRRRRtinsert_childtprefix(
RR!t stmt_nodetsemi_indRtnew_exprtnew_stmtR"t new_leaf1t old_leaf1((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pytfixup_simple_stmtSs
cCs:|jr6|jdjtjkr6|jdj�ndS(Ni����(RR
RtNEWLINER(R((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pytremove_trailing_newlineks"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(NsNo
class suite!iu
__metaclass__(RR
RRRtlistRRRRRRR-R/(R
RR!tsimple_nodeRt left_node((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pyt
find_metasps"
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(
RtpopR
RtINDENTRRtDEDENTR&textend(RtkidsR((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pytfixup_indent�s ! tFixMetaclasscBseZeZdZd�ZRS(s
classdef<any*>
cCs�t|�sdSt|�d}x-t|�D]\}}}|}|j�q-W|jdj}t|j�dkr�|jdjtj kr�|jd}q�|jdj
�} ttj | g�}|jd|�n�t|j�dkrttj g�}|j
d|�n~t|j�dkr�ttj g�}|j
dttjd��|j
d|�|j
dttjd��ntd ��|jdjd}
d
|
_|
j}tdd|�|jdjdj
�}d
|_|g}
|jr�t|j�dkr0|jdj
�}d|_n�t|j
��}d|_ttd�td�t�|t�ttjttjd�ttjd�gdd�gdd�}|
jt�|g�n|jttdd|j�|
��t
|�|jsM|j�t|d�}||_|j!|�|j!ttj"d��n�t|j�dkr�|jdjtj#kr�|jdjtj$kr�t|d�}|j
d|�|j
dttj"d��ndS(Niiiiiiu)u(sUnexpected
class definitiont metaclassufuture.utilsuwith_metaclassuiu
R
s 'NewBase'u{u}R&upassu
i����i����(%RR#tNoneR3RRR
tlenRtarglistRRt set_childR%RRtRPARtLPARRRR&RR
RRRR tatomtLBRACEtRBRACER7treplaceR9RR.R5R6(tselfRtresultstlast_metaclassRR!tstmtt text_typeR>Rtmeta_txttorig_meta_prefixR;t argumentstbasetbasest pass_leaf((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pyt transform�s~
$
(t__name__t
__module__Rt
BM_compatibletPATTERNRQ(((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pyR:�sN(t__doc__tlib2to3Rtlib2to3.pygramRtlib2to3.fixer_utilRRRRRRRR R
RR#R-R/R3R9tBaseFixR:(((sC/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_metaclass.pyt<module>s@