<s> import tempfile , sys , os <EOL> print "<STR_LIT>" , eval ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" , eval ( "<STR_LIT>" ) <EOL> def functionEval1 ( ) : <EOL> return eval ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" , functionEval1 ( ) <EOL> def functionEval2 ( ) : <EOL> a = [ <NUM_LIT:2> ] <EOL> g = { } <EOL> r = eval ( "<STR_LIT>" , g ) <EOL> return r , g . keys ( ) , a <EOL> print "<STR_LIT>" , functionEval2 ( ) <EOL> def functionEval3 ( ) : <EOL> result = [ ] <EOL> for x in eval ( "<STR_LIT>" ) : <EOL> result . append ( x ) <EOL> return result <EOL> print "<STR_LIT>" , functionEval3 ( ) <EOL> print "<STR_LIT>" , <EOL> exec ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" , d <EOL> def functionExec1 ( ) : <EOL> a = <NUM_LIT:1> <EOL> code = "<STR_LIT>" <EOL> exec ( code ) <EOL> return a <EOL> def functionExec2 ( ) : <EOL> a = <NUM_LIT:1> <EOL> code = "<STR_LIT>" <EOL> exec code in globals ( ) , locals ( ) <EOL> return a <EOL> print "<STR_LIT>" , functionExec1 ( ) , functionExec2 ( ) <EOL> tmp_filename = tempfile . gettempdir ( ) + "<STR_LIT>" <EOL> f = open ( tmp_filename , '<STR_LIT:w>' ) <EOL> f . write ( "<STR_LIT>" ) <EOL> f . close ( ) <EOL> execfile ( tmp_filename ) <EOL> print "<STR_LIT>" , e , f <EOL> global_vars = { '<STR_LIT:e>' : '<STR_LIT:0>' , '<STR_LIT:f>' : <NUM_LIT:0> } <EOL> local_vars = dict ( global_vars ) <EOL> execfile ( tmp_filename , global_vars ) <EOL> print "<STR_LIT>" , global_vars . keys ( ) <EOL> execfile ( tmp_filename , global_vars , local_vars ) <EOL> print "<STR_LIT>" , local_vars <EOL> def functionExecfile ( ) : <EOL> e = <NUM_LIT:0> <EOL> f = <NUM_LIT:0> <EOL> global_vars = { '<STR_LIT:e>' : '<STR_LIT:0>' , '<STR_LIT:f>' : <NUM_LIT:0> } <EOL> local_vars = dict ( global_vars ) <EOL> print "<STR_LIT>" , <EOL> x = execfile ( tmp_filename , global_vars , local_vars ) <EOL> print x , <EOL> print global_vars . keys ( ) , local_vars , e , f <EOL> functionExecfile ( ) <EOL> class classExecfile : <EOL> e = <NUM_LIT:0> <EOL> f = <NUM_LIT:0> <EOL> print "<STR_LIT>" , <EOL> execfile ( tmp_filename ) <EOL> print "<STR_LIT>" , e , f <EOL> f = <NUM_LIT:7> <EOL> def functionExecNonesTuple ( ) : <EOL> f = <NUM_LIT:0> <EOL> exec ( "<STR_LIT>" , None , None ) <EOL> print "<STR_LIT>" , f <EOL> def functionExecNonesSyntax ( ) : <EOL> f = <NUM_LIT:0> <EOL> exec "<STR_LIT>" in None , None <EOL> print "<STR_LIT>" , f <EOL> functionExecNonesTuple ( ) <EOL> functionExecNonesSyntax ( ) <EOL> print "<STR_LIT>" , f <EOL> def functionEvalNones2 ( ) : <EOL> f = <NUM_LIT:11> <EOL> code = '<STR_LIT:f>' <EOL> g = None <EOL> l = None <EOL> f1 = eval ( code , l , g ) <EOL> print "<STR_LIT>" , f1 <EOL> functionEvalNones2 ( ) <EOL> def functionExecNonesTuple2 ( ) : <EOL> f = <NUM_LIT:0> <EOL> code = "<STR_LIT>" <EOL> g = None <EOL> l = None <EOL> exec ( code , l , g ) <EOL> print "<STR_LIT>" , f <EOL> def functionExecNonesSyntax2 ( ) : <EOL> f = <NUM_LIT:0> <EOL> code = "<STR_LIT>" <EOL> g = None <EOL> l = None <EOL> exec code in l , g <EOL> print "<STR_LIT>" , f <EOL> functionExecNonesTuple2 ( ) <EOL> functionExecNonesSyntax2 ( ) <EOL> print "<STR_LIT>" <EOL> exec """<STR_LIT>""" <EOL> exec """<STR_LIT>""" <EOL> x = <NUM_LIT:1> <EOL> y = <NUM_LIT:1> <EOL> def functionGlobalsExecShadow ( ) : <EOL> global x <EOL> print "<STR_LIT>" , x <EOL> y = <NUM_LIT:0> <EOL> print "<STR_LIT>" , y <EOL> print "<STR_LIT>" , locals ( ) <EOL> exec """<STR_LIT>""" <EOL> print "<STR_LIT>" , x <EOL> exec """<STR_LIT>""" <EOL> print "<STR_LIT>" , locals ( ) <EOL> exec """<STR_LIT>""" <EOL> print "<STR_LIT>" , x <EOL> exec """<STR_LIT>""" <EOL> def print_global_y ( ) : <EOL> global y <EOL> print "<STR_LIT>" , y <EOL> print_global_y ( ) <EOL> print "<STR_LIT>" , y <EOL> functionGlobalsExecShadow ( ) <EOL> def functionWithClosureProvidedByExec ( ) : <EOL> code = "<STR_LIT>" <EOL> exec code in None , None <EOL> def func ( ) : <EOL> print "<STR_LIT>" , ValueError <EOL> func ( ) <EOL> functionWithClosureProvidedByExec ( ) <EOL> x = <NUM_LIT:2> <EOL> def functionWithExecAffectingClosure ( ) : <EOL> x = <NUM_LIT:4> <EOL> code = "<STR_LIT>" <EOL> space = locals ( ) <EOL> exec code in space <EOL> def closureMaker ( ) : <EOL> return x <EOL> return d , closureMaker ( ) <EOL> print "<STR_LIT>" , functionWithExecAffectingClosure ( ) <EOL> def generatorFunctionWithExec ( ) : <EOL> yield <NUM_LIT:1> <EOL> code = "<STR_LIT>" <EOL> exec code <EOL> yield y <EOL> print "<STR_LIT>" , tuple ( generatorFunctionWithExec ( ) ) <EOL> def evalInContractions ( ) : <EOL> r1 = list ( eval ( str ( s ) ) for s in range ( <NUM_LIT:3> ) ) <EOL> r2 = [ eval ( str ( s ) ) for s in range ( <NUM_LIT:4> ) ] <EOL> return r1 , r2 <EOL> print "<STR_LIT>" , evalInContractions ( ) <EOL> def execDefinesFunctionToLocalsExplicity ( ) : <EOL> exec """<STR_LIT>""" in locals ( ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> assert makeAddPair <EOL> return "<STR_LIT:yes>" <EOL> print "<STR_LIT>" , execDefinesFunctionToLocalsExplicity ( ) <EOL> os . unlink ( tmp_filename ) <EOL> def execWithShortTuple ( ) : <EOL> try : <EOL> exec ( "<STR_LIT>" , ) <EOL> except Exception as e : <EOL> return "<STR_LIT>" + repr ( e ) <EOL> print "<STR_LIT>" , execWithShortTuple ( ) </s>
