<s> from __future__ import absolute_import , print_function <EOL> from os . path import abspath , dirname <EOL> from types import ModuleType <EOL> import os <EOL> import sys <EOL> import traceback <EOL> from bokeh . util . serialization import make_id <EOL> class _CodeRunner ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , source , path , argv ) : <EOL> self . _failed = False <EOL> self . _error = None <EOL> self . _error_detail = None <EOL> import ast <EOL> self . _code = None <EOL> try : <EOL> nodes = ast . parse ( source , path ) <EOL> self . _code = compile ( nodes , filename = path , mode = '<STR_LIT>' ) <EOL> except SyntaxError as e : <EOL> self . _failed = True <EOL> self . _error = ( "<STR_LIT>" % ( os . path . basename ( e . filename ) , e . lineno , e . text ) ) <EOL> import traceback <EOL> self . _error_detail = traceback . format_exc ( ) <EOL> self . _path = path <EOL> self . _source = source <EOL> self . _argv = argv <EOL> @ property <EOL> def source ( self ) : <EOL> return self . _source <EOL> @ property <EOL> def path ( self ) : <EOL> return self . _path <EOL> @ property <EOL> def failed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _failed <EOL> @ property <EOL> def error ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _error <EOL> @ property <EOL> def error_detail ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _error_detail <EOL> def new_module ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . failed : <EOL> return None <EOL> module_name = '<STR_LIT>' + make_id ( ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> module = ModuleType ( module_name ) <EOL> module . __dict__ [ '<STR_LIT>' ] = abspath ( self . _path ) <EOL> return module <EOL> def run ( self , module , post_check ) : <EOL> try : <EOL> _cwd = os . getcwd ( ) <EOL> _sys_path = list ( sys . path ) <EOL> _sys_argv = list ( sys . argv ) <EOL> os . chdir ( dirname ( self . _path ) ) <EOL> sys . path . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> sys . argv = [ os . path . basename ( self . _path ) ] + self . _argv <EOL> exec ( self . _code , module . __dict__ ) <EOL> post_check ( ) <EOL> except Exception as e : <EOL> self . _failed = True <EOL> self . _error_detail = traceback . format_exc ( ) <EOL> exc_type , exc_value , exc_traceback = sys . exc_info ( ) <EOL> filename , line_number , func , txt = traceback . extract_tb ( exc_traceback ) [ - <NUM_LIT:1> ] <EOL> self . _error = "<STR_LIT>" % ( str ( e ) , os . path . basename ( filename ) , line_number , func , txt ) <EOL> finally : <EOL> os . chdir ( _cwd ) <EOL> sys . path = _sys_path <EOL> sys . argv = _sys_argv </s>
