<s> class C : <EOL> __metaclass__ = type <EOL> def __init__ ( self ) : <EOL> self . __state = <NUM_LIT:0> <EOL> def getstate ( self ) : <EOL> return self . __state <EOL> def setstate ( self , state ) : <EOL> self . __state = state <EOL> a = C ( ) <EOL> assert a . getstate ( ) == <NUM_LIT:0> <EOL> a . setstate ( <NUM_LIT:10> ) <EOL> assert a . getstate ( ) == <NUM_LIT:10> <EOL> class D : <EOL> class __metaclass__ ( type ) : <EOL> def myself ( cls ) : return cls <EOL> assert D . myself ( ) == D <EOL> d = D ( ) <EOL> assert d . __class__ == D <EOL> class M1 ( type ) : <EOL> def __new__ ( cls , name , bases , dict ) : <EOL> dict [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> return type . __new__ ( cls , name , bases , dict ) <EOL> class C : <EOL> __metaclass__ = M1 <EOL> assert C . __spam__ == <NUM_LIT:1> <EOL> c = C ( ) <EOL> assert c . __spam__ == <NUM_LIT:1> <EOL> class _instance ( object ) : <EOL> pass <EOL> class M2 ( object ) : <EOL> @ staticmethod <EOL> def __new__ ( cls , name , bases , dict ) : <EOL> self = object . __new__ ( cls ) <EOL> self . name = name <EOL> self . bases = bases <EOL> self . dict = dict <EOL> return self <EOL> def __call__ ( self ) : <EOL> it = _instance ( ) <EOL> for key in self . dict : <EOL> if key . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> setattr ( it , key , self . dict [ key ] . __get__ ( it , self ) ) <EOL> return it <EOL> class C : <EOL> __metaclass__ = M2 <EOL> def spam ( self ) : <EOL> return <NUM_LIT> <EOL> assert C . name == '<STR_LIT:C>' <EOL> assert C . bases == ( ) <EOL> assert '<STR_LIT>' in C . dict <EOL> c = C ( ) <EOL> assert c . spam ( ) == <NUM_LIT> <EOL> class autosuper ( type ) : <EOL> def __new__ ( metaclass , name , bases , dict ) : <EOL> cls = super ( autosuper , metaclass ) . __new__ ( metaclass , <EOL> name , bases , dict ) <EOL> while name [ : <NUM_LIT:1> ] == "<STR_LIT:_>" : <EOL> name = name [ <NUM_LIT:1> : ] <EOL> if name : <EOL> name = "<STR_LIT>" % name <EOL> else : <EOL> name = "<STR_LIT>" <EOL> setattr ( cls , name , super ( cls ) ) <EOL> return cls <EOL> class A : <EOL> __metaclass__ = autosuper <EOL> def meth ( self ) : <EOL> return "<STR_LIT:A>" <EOL> class B ( A ) : <EOL> def meth ( self ) : <EOL> return "<STR_LIT:B>" + self . __super . meth ( ) <EOL> class C ( A ) : <EOL> def meth ( self ) : <EOL> return "<STR_LIT:C>" + self . __super . meth ( ) <EOL> class D ( C , B ) : <EOL> def meth ( self ) : <EOL> return "<STR_LIT:D>" + self . __super . meth ( ) <EOL> assert D ( ) . meth ( ) == "<STR_LIT>" <EOL> class E ( B , C ) : <EOL> def meth ( self ) : <EOL> return "<STR_LIT:E>" + self . __super . meth ( ) <EOL> assert E ( ) . meth ( ) == "<STR_LIT>" <EOL> class autoproperty ( type ) : <EOL> def __new__ ( metaclass , name , bases , dict ) : <EOL> hits = { } <EOL> for key , val in dict . iteritems ( ) : <EOL> if key . startswith ( "<STR_LIT>" ) : <EOL> key = key [ <NUM_LIT:5> : ] <EOL> get , set = hits . get ( key , ( None , None ) ) <EOL> get = val <EOL> hits [ key ] = get , set <EOL> elif key . startswith ( "<STR_LIT>" ) : <EOL> key = key [ <NUM_LIT:5> : ] <EOL> get , set = hits . get ( key , ( None , None ) ) <EOL> set = val <EOL> hits [ key ] = get , set <EOL> for key , ( get , set ) in hits . iteritems ( ) : <EOL> dict [ key ] = property ( get , set ) <EOL> return super ( autoproperty , metaclass ) . __new__ ( metaclass , <EOL> name , bases , dict ) <EOL> class A : <EOL> __metaclass__ = autoproperty <EOL> def _get_x ( self ) : <EOL> return - self . __x <EOL> def _set_x ( self , x ) : <EOL> self . __x = - x <EOL> a = A ( ) <EOL> assert not hasattr ( a , "<STR_LIT:x>" ) <EOL> a . x = <NUM_LIT:12> <EOL> assert a . x == <NUM_LIT:12> <EOL> assert a . _A__x == - <NUM_LIT:12> <EOL> class multimetaclass ( autoproperty , autosuper ) : <EOL> pass <EOL> class A : <EOL> __metaclass__ = multimetaclass <EOL> def _get_x ( self ) : <EOL> return "<STR_LIT:A>" <EOL> class B ( A ) : <EOL> def _get_x ( self ) : <EOL> return "<STR_LIT:B>" + self . __super . _get_x ( ) <EOL> class C ( A ) : <EOL> def _get_x ( self ) : <EOL> return "<STR_LIT:C>" + self . __super . _get_x ( ) <EOL> class D ( C , B ) : <EOL> def _get_x ( self ) : <EOL> return "<STR_LIT:D>" + self . __super . _get_x ( ) <EOL> assert D ( ) . x == "<STR_LIT>" <EOL> class T ( type ) : <EOL> counter = <NUM_LIT:0> <EOL> def __init__ ( self , * args ) : <EOL> T . counter += <NUM_LIT:1> <EOL> class C : <EOL> __metaclass__ = T <EOL> assert T . counter == <NUM_LIT:1> <EOL> a = C ( ) <EOL> assert type ( a ) == C <EOL> assert T . counter == <NUM_LIT:1> <EOL> class C ( object ) : pass <EOL> c = C ( ) <EOL> try : c ( ) <EOL> except TypeError : pass <EOL> else : self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class A ( type ) : <EOL> def __new__ ( * args , ** kwargs ) : <EOL> return type . __new__ ( * args , ** kwargs ) <EOL> class B ( object ) : <EOL> pass <EOL> class C ( object ) : <EOL> __metaclass__ = A <EOL> class D ( B , C ) : <EOL> pass <EOL> print "<STR_LIT>" </s>
