[pypy-svn] r64304 - in pypy/trunk/pypy/module/unicodedata: . test

afa at codespeak.net afa at codespeak.net
Fri Apr 17 20:06:06 CEST 2009


Author: afa
Date: Fri Apr 17 20:06:04 2009
New Revision: 64304

Modified:
   pypy/trunk/pypy/module/unicodedata/interp_ucd.py
   pypy/trunk/pypy/module/unicodedata/test/test_unicodedata.py
Log:
In narrow unicode builds, unicodedata.lookup should raise a KeyError
when given a name outside the BMP, instead the ValueError raised by unichr().

This fixes one test in test_unicodedata


Modified: pypy/trunk/pypy/module/unicodedata/interp_ucd.py
==============================================================================
--- pypy/trunk/pypy/module/unicodedata/interp_ucd.py	(original)
+++ pypy/trunk/pypy/module/unicodedata/interp_ucd.py	Fri Apr 17 20:06:04 2009
@@ -58,8 +58,15 @@
     _get_code.unwrap_spec = ['self', ObjSpace, str]
     
     def lookup(self, space, name):
-        return space.call_function(space.builtin.get('unichr'),
-                                   self._get_code(space, name))
+        w_code = self._get_code(space, name)
+        try:
+            return space.call_function(space.builtin.get('unichr'), w_code)
+        except OperationError, ex:
+            if not ex.match(space, space.w_ValueError):
+                raise
+            msg = space.mod(space.wrap("result %d larger than sys.maxunicode"), w_code)
+            raise OperationError(space.w_KeyError, msg)
+
     lookup.unwrap_spec = ['self', ObjSpace, str]
 
     def name(self, space, w_unichr, w_default=NoneNotWrapped):

Modified: pypy/trunk/pypy/module/unicodedata/test/test_unicodedata.py
==============================================================================
--- pypy/trunk/pypy/module/unicodedata/test/test_unicodedata.py	(original)
+++ pypy/trunk/pypy/module/unicodedata/test/test_unicodedata.py	Fri Apr 17 20:06:04 2009
@@ -73,6 +73,11 @@
                     pass
                 raises(KeyError, unicodedata.lookup, charname)
 
+    def test_bug_1704793(self): # from CPython
+        import sys, unicodedata
+        if sys.maxunicode == 65535:
+            raises(KeyError, unicodedata.lookup, "GOTHIC LETTER FAIHU")
+
 class TestUnicodeData(object):
     def setup_class(cls):
         import random, unicodedata



More information about the Pypy-commit mailing list