Commits

Ronan Lamy committed 9a39153

Create exc_wrap()

  • Participants
  • Parent commits 33acc1d
  • Branches Opcode-class

Comments (0)

Files changed (2)

rpython/flowspace/flowcontext.py

             link = Link([w_type, w_value], self.graph.exceptblock)
             self.recorder.crnt_block.closeblock(link)
 
-        except FSException, e:
-            if e.w_type is self.space.w_ImportError:
-                msg = 'import statement always raises %s' % e
-                raise ImportError(msg)
-            link = Link([e.w_type, e.w_value], self.graph.exceptblock)
+        except FSException as exc:
+            if exc.w_type == self.space.w_ImportError:
+                msg = 'import statement always raises %s' % exc
+                raise exc.w_value.value
+            link = Link([exc.w_type, exc.w_value], self.graph.exceptblock)
             self.recorder.crnt_block.closeblock(link)
 
         except StopFlowing:
                 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:

rpython/flowspace/objspace.py

             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
         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)
                 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)
     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):
         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))