//usr/lib64/lib64//lib64//python2.7/ó
ÛœSec @ s› d Z d d l m Z d d l m Z d d l m Z m Z m Z m Z d „ Z
d „ Z d „ Z d „ Z
d „ Z d
„ Z d e j f d „ ƒ YZ d
S( sŒ 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 ( t
fixer_base( t token( t Namet symst Nodet Leafc C s¬ x¥ | j D]š } | j t j k r, t | ƒ S| j t j k r
| j r
| j d } | j t j k r¤ | j r¤ | j d } t | t ƒ r¡ | j d k r¡ t
Sq¤ q
q
Wt S( 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')
i t
__metaclass__( t childrent typeR t suitet
has_metaclasst simple_stmtt expr_stmtt
isinstanceR t valuet Truet False( t parentt nodet expr_nodet left_side( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyR
s
c C sÛ x' | j D] } | j t j k r
d Sq
Wx? t | j ƒ D]" \ } } | j t j k r: Pq: q: Wt d ƒ ‚ t t j g ƒ } xC | j | d rà | j | d } | j | j
ƒ ƒ | j ƒ q W| j | ƒ | } d S( sf one-line classes don't get a suite in the parse tree so we add
one to normalize the tree
Ns No class suite and no ':'!i ( R R R R t enumerateR t COLONt
ValueErrorR t append_childt clonet remove( t cls_nodeR t iR t move_node( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt fixup_parse_tree- s
c
C sñ x7 t | j ƒ D]" \ } } | j t j k r Pq q Wd S| j ƒ t t j g ƒ } t t j | g ƒ } x; | j | r¨ | j | } | j
| j ƒ ƒ | j ƒ qn W| j | | ƒ | j d j d } | j d j d } | j
| _
d S( 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 ( R R R R t SEMIR R R R R R R t insert_childt prefix(
R R t stmt_nodet semi_indR t new_exprt new_stmtR t new_leaf1t old_leaf1( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt fixup_simple_stmtG s
c C s: | j r6 | j d j t j k r6 | j d j ƒ n d S( Niÿÿÿÿ( R R R t NEWLINER ( R ( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt remove_trailing_newline_ s "c c sÿ x3 | j D] } | j t j k r
Pq
q
Wt d ƒ ‚ x t t | j ƒ ƒ D]« \ } } | j t j k rL | j rL | j d } | j t j k r÷ | j r÷ | j d } t | t
ƒ rô | j d k rô t | | | ƒ t
| ƒ | | | f Vqô q÷ qL qL Wd S( Ns No class suite!i u
__metaclass__( R R R R R t listR R R R
R R R( R* ( R R R t simple_nodeR t left_node( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt
find_metasd s "
c C s¹ | j d d d … } x, | rD | j ƒ } | j t j k r Pq q Wxm | r´ | j ƒ } t | t ƒ r” | j t j k r” | j r d | _ n d S| j | j d d d … ƒ qH Wd S( 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 (
R t popR R t INDENTR
R t DEDENTR! t extend( R t kidsR ( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt fixup_indent{ s ! t FixMetaclassc B s e Z e Z d Z d „ Z RS( s
classdef
c C s t | ƒ s d St | ƒ d } x- t | ƒ D] \ } } } | } | j ƒ q- W| j d j } t | j ƒ d k rÙ | j d j t j k rž | j d } q‘| j d j
ƒ } t t j | g ƒ } | j d | ƒ n¸ t | j ƒ d k rt t j g ƒ } | j
d | ƒ n~ t | j ƒ d k r…t t j g ƒ } | j
d t t j d ƒ ƒ | j
d | ƒ | j
d t t j d ƒ ƒ n t d ƒ ‚ | j d j d }
d
|
_ |
j } | j rå| j t t j d ƒ ƒ d |
_ n d
|
_ | j d } d
| j d _ d
| j d _ | j | ƒ t | ƒ | j s†| j ƒ t | d ƒ }
| |
_ | j |
ƒ | j t t j d ƒ ƒ n… t | j ƒ d k r| j d j t j k r| j d j t j k rt | d ƒ }
| j
d |
ƒ | j
d t t j d ƒ ƒ n d S( Ni i i i i i u )u (s Unexpected class definitiont metaclassu ,u u i u passu
iþÿÿÿiÿÿÿÿ( R
R t NoneR. R R R t lenR t arglistR R t set_childR R R t RPARt LPARR R R! R t COMMAR4 R) R0 R1 ( t selfR t resultst last_metaclassR R t stmtt text_typeR9 R t meta_txtt orig_meta_prefixR t pass_leaf( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt transform˜ s^
( t __name__t
__module__R t
BM_compatiblet PATTERNRF ( ( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyR5 ‘ s N( t __doc__t R t pygramR t
fixer_utilR R R R R
R R( R* R. R4 t BaseFixR5 ( ( ( s3 /usr/lib64/python2.7/lib2to3/fixes/fix_metaclass.pyt s "