[pypy-svn] r76104 - in pypy/branch/fast-forward/pypy/objspace/std: . test

benjamin at codespeak.net benjamin at codespeak.net
Sun Jul 11 03:15:06 CEST 2010


Author: benjamin
Date: Sun Jul 11 03:15:04 2010
New Revision: 76104

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/newformat.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
Log:
fix for non-latin 1 keys

Modified: pypy/branch/fast-forward/pypy/objspace/std/newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/newformat.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/newformat.py	Sun Jul 11 03:15:04 2010
@@ -168,7 +168,15 @@
             index = self.auto_numbering
             self.auto_numbering += 1
         if index == -1:
-            arg_key = name[:i]
+            kwarg = name[:i]
+            if self.is_unicode:
+                try:
+                    arg_key = kwarg.encode("latin-1")
+                except UnicodeEncodeError:
+                    # Not going to be found in a dict of strings.
+                    raise OperationError(space.w_KeyError, space.wrap(kwarg))
+            else:
+                arg_key = kwarg
             try:
                 w_arg = self.kwargs[arg_key]
             except KeyError:

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py	Sun Jul 11 03:15:04 2010
@@ -112,6 +112,9 @@
         assert self.s("{!s}").format(x()) == self.s("42")
         assert self.s("{!r}").format(x()) == self.s("32")
 
+    def test_non_latin1_key(self):
+        raises(KeyError, self.s("{\u1000}").format)
+
 
 class AppTestStringFormat(BaseStringFormatTests):
 



More information about the Pypy-commit mailing list