Beispiel #1
0
def _run_eval_string(source, filename, space, eval):
    if eval:
        cmd = 'eval'
    else:
        cmd = 'exec'
 
    try:
        if space is None:
            from pypy.objspace.std import StdObjSpace
            space = StdObjSpace()

        w = space.wrap

        pycode = compilecode(space, source, filename or '<string>', cmd)

        mainmodule = ensure__main__(space)
        w_globals = mainmodule.w_dict

        space.setitem(w_globals, w('__builtins__'), space.builtin)
        if filename is not None:
            space.setitem(w_globals, w('__file__'), w(filename))

        retval = pycode.exec_code(space, w_globals, w_globals)
        if eval:
            return retval
        else:
            return

    except OperationError, operationerr:
        operationerr.record_interpreter_traceback()
        raise
Beispiel #2
0
def _run_eval_string(source, filename, space, eval):
    if eval:
        cmd = 'eval'
    else:
        cmd = 'exec'

    try:
        if space is None:
            from pypy.objspace.std import StdObjSpace
            space = StdObjSpace()

        pycode = compilecode(space, source, filename or '<string>', cmd)

        mainmodule = ensure__main__(space)
        w_globals = mainmodule.w_dict

        space.setitem(w_globals, space.newtext('__builtins__'), space.builtin)
        if filename is not None:
            space.setitem(w_globals, space.newtext('__file__'),
                          space.newfilename(filename))

        retval = pycode.exec_code(space, w_globals, w_globals)
        if eval:
            return retval
        else:
            return

    except OperationError as operationerr:
        operationerr.record_interpreter_traceback()
        raise
Beispiel #3
0
 def setup_class(cls):
     init_extmodule_code()
     conf = get_pypy_config()
     conf.objspace.extmodules = 'testext.extmod'
     old_sys_path[:] = sys.path[:]
     sys.path.insert(0, str(udir))
     space = StdObjSpace(conf)
     cls.space = space
Beispiel #4
0
def run_module(module_name, args, space=None):
    """Implements PEP 338 'Executing modules as scripts', overwriting
    sys.argv[1:] using `args` and executing the module `module_name`.
    sys.argv[0] always is `module_name`.

    Delegates the real work to the runpy module provided as the reference
    implementation.
    """
    if space is None:
        from pypy.objspace.std import StdObjSpace
        space = StdObjSpace()
    w = space.wrap
    argv = [module_name]
    if args is not None:
        argv.extend(args)
    space.setitem(space.sys.w_dict, w('argv'), w(argv))
    w_import = space.builtin.get('__import__')
    runpy = space.call_function(w_import, w('runpy'))
    w_run_module = space.getitem(runpy.w_dict, w('run_module'))
    return space.call_function(w_run_module, w(module_name), space.w_None,
                               w('__main__'), space.w_True)
Beispiel #5
0
def run_module(module_name, args, space=None):
    """Implements PEP 338 'Executing modules as scripts', overwriting
    sys.argv[1:] using `args` and executing the module `module_name`.
    sys.argv[0] always is `module_name`.

    Delegates the real work to the runpy module provided as the reference
    implementation.
    """
    if space is None:
        from pypy.objspace.std import StdObjSpace
        space = StdObjSpace()
    w = space.wrap
    argv = [module_name]
    if args is not None:
        argv.extend(args)
    space.setitem(space.sys.w_dict, w('argv'), w(argv))
    w_import = space.builtin.get('__import__')
    runpy = space.call_function(w_import, w('runpy'))
    w_run_module = space.getitem(runpy.w_dict, w('run_module'))
    return space.call_function(w_run_module, w(module_name), space.w_None,
                               w('__main__'), space.w_True)