<s> import PyV8 <EOL> class FileWrapper ( object ) : <EOL> def __init__ ( self , fname , mode ) : <EOL> self . f = open ( fname , mode ) <EOL> def seek ( self , seekto = None ) : <EOL> if seekto is None : <EOL> return self . f . seek ( ) <EOL> return self . f . seek ( seekto ) <EOL> def close ( self ) : <EOL> return self . f . close ( ) <EOL> def write ( self , bytes ) : <EOL> return self . f . write ( bytes ) <EOL> def read ( self , bytes = None ) : <EOL> if bytes is None : <EOL> return self . f . read ( ) <EOL> return self . f . read ( bytes ) <EOL> class Global ( PyV8 . JSClass ) : <EOL> def pyv8_open ( self , fname , mode ) : <EOL> return FileWrapper ( fname , mode ) <EOL> def pyv8_print_fn ( self , arg ) : <EOL> print arg <EOL> def pyv8_import_module ( self , parent_name , module_name ) : <EOL> exec "<STR_LIT>" + module_name <EOL> return locals ( ) [ module_name ] <EOL> def pyv8_load ( self , modules ) : <EOL> for i in range ( len ( modules ) ) : <EOL> fname = modules [ i ] <EOL> try : <EOL> fp = open ( fname , '<STR_LIT:r>' ) <EOL> txt = fp . read ( ) . decode ( '<STR_LIT>' ) <EOL> fp . close ( ) <EOL> x = self . __context__ . eval ( txt ) <EOL> except Exception , e : <EOL> raise ImportError ( "<STR_LIT>" % ( fname , e ) ) </s>
