Author: Amaury Forgeot d'Arc <[email protected]>
Branch: 
Changeset: r47662:f1491c2aa43b
Date: 2011-09-28 21:07 +0200
http://bitbucket.org/pypy/pypy/changeset/f1491c2aa43b/

Log:    unicode.translate accepts any mapping; missing items may raise
        KeyError or IndexError. Test and fix.

diff --git a/pypy/objspace/std/test/test_unicodeobject.py 
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -443,6 +443,8 @@
         assert u'<i><i><i>c' == u'abababc'.translate({ord('a'):None, 
ord('b'):u'<i>'})
         assert u'c' == u'abababc'.translate({ord('a'):None, ord('b'):u''})
         assert u'xyyx' == u'xzx'.translate({ord('z'):u'yy'})
+        assert u'abcd' == u'ab\0d'.translate(u'c')
+        assert u'abcd' == u'abcd'.translate(u'')
 
         raises(TypeError, u'hello'.translate)
         raises(TypeError, u'abababc'.translate, {ord('a'):''})
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -893,7 +893,7 @@
         try:
             w_newval = space.getitem(w_table, space.wrap(ord(unichar)))
         except OperationError, e:
-            if e.match(space, space.w_KeyError):
+            if e.match(space, space.w_LookupError):
                 result.append(unichar)
             else:
                 raise
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to