def compile_string(space, source, filename, start, flags=0): w_source = space.wrap(source) start = rffi.cast(lltype.Signed, start) if start == Py_file_input: mode = "exec" elif start == Py_eval_input: mode = "eval" elif start == Py_single_input: mode = "single" else: raise OperationError(space.w_ValueError, space.wrap("invalid mode parameter for compilation")) return compiling.compile(space, w_source, filename, mode, flags)
def compile_string(space, source, filename, start, flags=0): w_source = space.newbytes(source) start = rffi.cast(lltype.Signed, start) if start == Py_file_input: mode = 'exec' elif start == Py_eval_input: mode = 'eval' elif start == Py_single_input: mode = 'single' else: raise oefmt(space.w_ValueError, "invalid mode parameter for compilation") return compiling.compile(space, w_source, filename, mode, flags)
def compile_string(space, source, filename, start): w_source = space.wrap(source) start = rffi.cast(lltype.Signed, start) if start == Py_file_input: mode = 'exec' elif start == Py_eval_input: mode = 'eval' elif start == Py_single_input: mode = 'single' else: raise OperationError( space.w_ValueError, space.wrap("invalid mode parameter for compilation")) return compiling.compile(space, w_source, filename, mode)
def run_string(space, source, filename, start, w_globals, w_locals): w_source = space.wrap(source) start = rffi.cast(lltype.Signed, start) if start == Py_file_input: mode = 'exec' elif start == Py_eval_input: mode = 'eval' elif start == Py_single_input: mode = 'single' else: raise OperationError(space.w_ValueError, space.wrap( "invalid mode parameter for PyRun_String")) w_code = compiling.compile(space, w_source, filename, mode) return compiling.eval(space, w_code, w_globals, w_locals)
def get_restart_pycode(source, filename='<string>', cmd='exec'): log('Trying to patch:\n%s' % source) try: py_code = py_compiling.compile(py_space, py_space.newtext(source), filename, cmd) if not isinstance(py_code, PyCode): print 'py_code not an instance of PyCode' return if cmd == 'eval': return py_code co_consts_w_len = len(py_code.co_consts_w) if co_consts_w_len >= 1: if co_consts_w_len > 1: log('More than 1 const produced: %s' % co_consts_w_len) first_consts_w = py_code.co_consts_w[0] if not isinstance(first_consts_w, PyCode): log('First const is not a PyCode') return py_code return first_consts_w except OperationError as e: # import pdb; pdb.set_trace() print 'Failed to compile new frame: %s' % e.errorstr(py_space)