[pypy-commit] pypy flowoperators: Create exc_wrap()
rlamy
noreply at buildbot.pypy.org
Fri Jul 5 19:41:43 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: flowoperators
Changeset: r65207:684ea56ca2c5
Date: 2013-05-02 18:08 +0100
http://bitbucket.org/pypy/pypy/changeset/684ea56ca2c5/
Log: Create exc_wrap()
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -506,7 +506,7 @@
self.recorder.crnt_block.closeblock(link)
except FSException, e:
- if e.w_type is self.space.w_ImportError:
+ if e.w_type == self.space.w_ImportError:
msg = 'import statement always raises %s' % e
raise ImportError(msg)
link = Link([e.w_type, e.w_value], graph.exceptblock)
@@ -661,8 +661,8 @@
self.last_exception = operr
raise operr
else:
- raise FSException(space.w_TypeError,
- space.wrap("raise: no active exception to re-raise"))
+ raise space.exc_wrap(TypeError(
+ "raise: no active exception to re-raise"))
w_value = space.w_None
if nbargs >= 3:
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -135,6 +135,11 @@
raise WrapException
return Constant(obj)
+ def exc_wrap(self, exc):
+ w_value = self.wrap(exc)
+ w_type = self.wrap(type(exc))
+ return FSException(w_type, w_value)
+
def int_w(self, w_obj):
if isinstance(w_obj, Constant):
val = w_obj.value
@@ -238,7 +243,7 @@
else:
# the only case left here is (inst, None), from a 'raise inst'.
if not self.is_w(w_arg2, self.w_None):
- raise FSException(self.w_TypeError, self.wrap(
+ raise self.exc_wrap(TypeError(
"instance exception may not have a separate value"))
w_value = w_arg1
w_type = self.type(w_value)
@@ -292,7 +297,7 @@
try:
v, next_unroller = it.step()
except IndexError:
- raise FSException(self.w_StopIteration, self.w_None)
+ raise self.exc_wrap(StopIteration())
else:
frame.replace_in_stack(it, next_unroller)
return self.wrap(v)
@@ -341,8 +346,8 @@
def import_name(self, name, glob=None, loc=None, frm=None, level=-1):
try:
mod = __import__(name, glob, loc, frm, level)
- except ImportError, e:
- raise FSException(self.w_ImportError, self.wrap(str(e)))
+ except ImportError as e:
+ raise self.exc_wrap(e)
return self.wrap(mod)
def import_from(self, w_module, w_name):
@@ -357,8 +362,8 @@
try:
return self.wrap(getattr(w_module.value, w_name.value))
except AttributeError:
- raise FSException(self.w_ImportError,
- self.wrap("cannot import name '%s'" % w_name.value))
+ raise self.exc_wrap(ImportError(
+ "cannot import name '%s'" % w_name.value))
def call_method(self, w_obj, methname, *arg_w):
w_meth = self.getattr(w_obj, self.wrap(methname))
More information about the pypy-commit
mailing list