i f @ 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 d Z d d Z d d Z d d Z d d Z d d Z Gd d d e j Z d S)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)NamesymsNodeLeafc 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 d Sq q q Wd S)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) childrentyper suite has_metaclasssimple_stmt expr_stmt isinstancer value)parentnode expr_nodeZ left_side r @/opt/alt/python34/lib64/python3.4/lib2to3/fixes/fix_metaclass.pyr s r 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 } xI | j | d d r | j | d } | j | j | j q W| j | | } d S)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 r r enumerater COLON ValueErrorr append_childcloneremove)cls_noder ir move_noder r r fixup_parse_tree- s r! 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 } xA | j | d r | j | } | j | j | j qn W| j | | | j d j d } | j d j d } | j | _ d S)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 )r r r r SEMIr r r r r r r insert_childprefix) r r Z stmt_nodeZsemi_indr Znew_exprZnew_stmtr Z new_leaf1Z old_leaf1r r r fixup_simple_stmtG s r% c C s: | j r6 | j d j t j k r6 | j d j n d S)Nr r&