[pypy-svn] r69346 - in pypy/branch/faster-raise/pypy: interpreter module/exceptions module/exceptions/test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 17 14:36:34 CET 2009


Author: arigo
Date: Tue Nov 17 14:36:34 2009
New Revision: 69346

Modified:
   pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py
   pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
Log:
Test and fix.


Modified: pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py	Tue Nov 17 14:36:34 2009
@@ -1033,6 +1033,14 @@
             buffer = self.buffer_w(w_obj)
             return buffer.as_str()
 
+    def realunicode_w(self, w_obj):
+        # Like unicode_w, but only works if w_obj is really of type
+        # 'unicode'.
+        if not self.is_true(self.isinstance(w_obj, self.w_unicode)):
+            raise OperationError(self.w_TypeError,
+                                 self.wrap('argument must be a unicode'))
+        return self.unicode_w(w_obj)
+
     def bool_w(self, w_obj):
         # Unwraps a bool, also accepting an int for compatibility.
         # This is here mostly just for gateway.int_unwrapping_space_method().

Modified: pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	Tue Nov 17 14:36:34 2009
@@ -244,7 +244,7 @@
     
     def descr_init(self, space, w_object, w_start, w_end, w_reason):
         # typechecking
-        space.unicode_w(w_object)
+        space.realunicode_w(w_object)
         space.int_w(w_start)
         space.int_w(w_end)
         space.str_w(w_reason)
@@ -658,7 +658,7 @@
     def descr_init(self, space, w_encoding, w_object, w_start, w_end, w_reason):
         # typechecking
         space.str_w(w_encoding)
-        space.unicode_w(w_object)
+        space.realunicode_w(w_object)
         space.int_w(w_start)
         space.int_w(w_end)
         space.str_w(w_reason)

Modified: pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	Tue Nov 17 14:36:34 2009
@@ -168,6 +168,7 @@
         assert str(ue) == "'x' codec can't encode character u'\\x39' in position 1: bah"
         ue.object = []
         assert ue.object == []
+        raises(TypeError, UnicodeEncodeError, "x", "y", 1, 5, "bah")
 
     def test_multiple_inheritance(self):
         from exceptions import LookupError, ValueError, Exception



More information about the Pypy-commit mailing list