<s> from test . test_support import verbose , verify , TestFailed <EOL> import sys <EOL> import new <EOL> class Eggs : <EOL> def get_yolks ( self ) : <EOL> return self . yolks <EOL> print '<STR_LIT>' <EOL> m = new . module ( '<STR_LIT>' ) <EOL> if verbose : <EOL> print m <EOL> m . Eggs = Eggs <EOL> sys . modules [ '<STR_LIT>' ] = m <EOL> import Spam <EOL> def get_more_yolks ( self ) : <EOL> return self . yolks + <NUM_LIT:3> <EOL> print '<STR_LIT>' <EOL> C = new . classobj ( '<STR_LIT>' , ( Spam . Eggs , ) , { '<STR_LIT>' : get_more_yolks } ) <EOL> if verbose : <EOL> print C <EOL> print '<STR_LIT>' <EOL> c = new . instance ( C , { '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> if verbose : <EOL> print c <EOL> o = new . instance ( C ) <EOL> verify ( o . __dict__ == { } , <EOL> "<STR_LIT>" ) <EOL> del o <EOL> o = new . instance ( C , None ) <EOL> verify ( o . __dict__ == { } , <EOL> "<STR_LIT>" ) <EOL> del o <EOL> def break_yolks ( self ) : <EOL> self . yolks = self . yolks - <NUM_LIT:2> <EOL> print '<STR_LIT>' <EOL> im = new . instancemethod ( break_yolks , c , C ) <EOL> if verbose : <EOL> print im <EOL> verify ( c . get_yolks ( ) == <NUM_LIT:3> and c . get_more_yolks ( ) == <NUM_LIT:6> , <EOL> '<STR_LIT>' ) <EOL> im ( ) <EOL> verify ( c . get_yolks ( ) == <NUM_LIT:1> and c . get_more_yolks ( ) == <NUM_LIT:4> , <EOL> '<STR_LIT>' ) <EOL> im = new . instancemethod ( break_yolks , c ) <EOL> im ( ) <EOL> verify ( c . get_yolks ( ) == - <NUM_LIT:1> ) <EOL> try : <EOL> new . instancemethod ( break_yolks , None ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> try : <EOL> new . instancemethod ( break_yolks , c , kw = <NUM_LIT:1> ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> codestr = '''<STR_LIT>''' <EOL> ccode = compile ( codestr , '<STR_LIT>' , '<STR_LIT>' ) <EOL> import __builtin__ <EOL> g = { '<STR_LIT:c>' : <NUM_LIT:0> , '<STR_LIT>' : __builtin__ } <EOL> print '<STR_LIT>' <EOL> func = new . function ( ccode , g ) <EOL> if verbose : <EOL> print func <EOL> func ( ) <EOL> verify ( g [ '<STR_LIT:c>' ] == <NUM_LIT:3> , <EOL> '<STR_LIT>' ) <EOL> def f ( x ) : <EOL> def g ( y ) : <EOL> return x + y <EOL> return g <EOL> g = f ( <NUM_LIT:4> ) <EOL> new . function ( f . func_code , { } , "<STR_LIT>" ) <EOL> g2 = new . function ( g . func_code , { } , "<STR_LIT>" , ( <NUM_LIT:2> , ) , g . func_closure ) <EOL> verify ( g2 ( ) == <NUM_LIT:6> ) <EOL> g3 = new . function ( g . func_code , { } , "<STR_LIT>" , None , g . func_closure ) <EOL> verify ( g3 ( <NUM_LIT:5> ) == <NUM_LIT:9> ) <EOL> def test_closure ( func , closure , exc ) : <EOL> try : <EOL> new . function ( func . func_code , { } , "<STR_LIT>" , None , closure ) <EOL> except exc : <EOL> pass <EOL> else : <EOL> print "<STR_LIT>" <EOL> test_closure ( g , None , TypeError ) <EOL> test_closure ( g , ( <NUM_LIT:1> , ) , TypeError ) <EOL> test_closure ( g , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ValueError ) <EOL> test_closure ( f , g . func_closure , ValueError ) <EOL> print '<STR_LIT>' <EOL> if hasattr ( new , '<STR_LIT:code>' ) : <EOL> def f ( a ) : pass <EOL> c = f . func_code <EOL> argcount = c . co_argcount <EOL> nlocals = c . co_nlocals <EOL> stacksize = c . co_stacksize <EOL> flags = c . co_flags <EOL> codestring = c . co_code <EOL> constants = c . co_consts <EOL> names = c . co_names <EOL> varnames = c . co_varnames <EOL> filename = c . co_filename <EOL> name = c . co_name <EOL> firstlineno = c . co_firstlineno <EOL> lnotab = c . co_lnotab <EOL> freevars = c . co_freevars <EOL> cellvars = c . co_cellvars <EOL> d = new . code ( argcount , nlocals , stacksize , flags , codestring , <EOL> constants , names , varnames , filename , name , <EOL> firstlineno , lnotab , freevars , cellvars ) <EOL> d = new . code ( argcount , nlocals , stacksize , flags , codestring , <EOL> constants , names , varnames , filename , name , <EOL> firstlineno , lnotab ) <EOL> try : <EOL> d = new . code ( - argcount , nlocals , stacksize , flags , codestring , <EOL> constants , names , varnames , filename , name , <EOL> firstlineno , lnotab ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> try : <EOL> d = new . code ( argcount , - nlocals , stacksize , flags , codestring , <EOL> constants , names , varnames , filename , name , <EOL> firstlineno , lnotab ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> try : <EOL> d = new . code ( argcount , nlocals , stacksize , flags , codestring , <EOL> constants , ( <NUM_LIT:5> , ) , varnames , filename , name , <EOL> firstlineno , lnotab ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> class S ( str ) : pass <EOL> t = ( S ( "<STR_LIT>" ) , ) <EOL> d = new . code ( argcount , nlocals , stacksize , flags , codestring , <EOL> constants , t , varnames , filename , name , <EOL> firstlineno , lnotab ) <EOL> verify ( type ( t [ <NUM_LIT:0> ] ) is S , "<STR_LIT>" ) <EOL> if verbose : <EOL> print d </s>
