[pypy-commit] pypy translation-cleanup: Move parts of sc_import() to FlowObjSpace
rlamy
noreply at buildbot.pypy.org
Thu Aug 30 18:38:29 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57008:7ae5f94673e5
Date: 2012-08-22 20:00 +0100
http://bitbucket.org/pypy/pypy/changeset/7ae5f94673e5/
Log: Move parts of sc_import() to FlowObjSpace
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -406,6 +406,26 @@
return self.do_operation_with_implicit_exceptions('getattr',
w_obj, w_name)
+ def import_name(self, w_name, w_glob, w_loc, w_frm):
+ if not isinstance(w_loc, Constant):
+ # import * in a function gives us the locals as Variable
+ # we always forbid it as a SyntaxError
+ raise SyntaxError, "RPython: import * is not allowed in functions"
+
+ if self.do_imports_immediately:
+ name, glob, loc, frm = (self.unwrap(w_name), self.unwrap(w_glob),
+ self.unwrap(w_loc), self.unwrap(w_frm))
+ try:
+ mod = __import__(name, glob, loc, frm)
+ except ImportError, e:
+ raise OperationError(self.w_ImportError, self.wrap(str(e)))
+ return self.wrap(mod)
+
+ # redirect it, but avoid exposing the globals
+ w_glob = Constant({})
+ return self.do_operation('simple_call', Constant(__import__),
+ w_name, w_glob, w_loc, w_frm)
+
def import_from(self, w_module, w_name):
try:
return self.getattr(w_module, w_name)
diff --git a/pypy/objspace/flow/specialcase.py b/pypy/objspace/flow/specialcase.py
--- a/pypy/objspace/flow/specialcase.py
+++ b/pypy/objspace/flow/specialcase.py
@@ -20,22 +20,7 @@
w_loc = args_w[2]
if len(args_w) > 3:
w_frm = args_w[3]
- if not isinstance(w_loc, Constant):
- # import * in a function gives us the locals as Variable
- # we always forbid it as a SyntaxError
- raise SyntaxError, "RPython: import * is not allowed in functions"
- if space.do_imports_immediately:
- name, glob, loc, frm = (space.unwrap(w_name), space.unwrap(w_glob),
- space.unwrap(w_loc), space.unwrap(w_frm))
- try:
- mod = __import__(name, glob, loc, frm)
- except ImportError, e:
- raise OperationError(space.w_ImportError, space.wrap(str(e)))
- return space.wrap(mod)
- # redirect it, but avoid exposing the globals
- w_glob = Constant({})
- return space.do_operation('simple_call', Constant(__import__),
- w_name, w_glob, w_loc, w_frm)
+ return space.import_name(w_name, w_glob, w_loc, w_frm)
def sc_operator(space, fn, args):
args_w, kwds_w = args.unpack()
More information about the pypy-commit
mailing list