[pypy-svn] pypy default: Another test and fix.

arigo commits-noreply at bitbucket.org
Tue Feb 8 13:44:40 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41699:18d9c14ffea0
Date: 2011-02-08 13:44 +0100
http://bitbucket.org/pypy/pypy/changeset/18d9c14ffea0/

Log:	Another test and fix.

diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -129,10 +129,15 @@
                         raise OperationError(self.space.w_ValueError, w_msg)
                     conversion = s[i]
                     i += 1
-                    c = s[i]
+                    if i < end:
+                        if s[i] != ':':
+                            w_msg = self.space.wrap("expected ':' after"
+                                                    " format specifier")
+                            raise OperationError(self.space.w_ValueError,
+                                                 w_msg)
+                        i += 1
                 else:
                     conversion = None
-                if c == ':':
                     i += 1
                 return s[start:end_name], conversion, i
             i += 1

diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -166,6 +166,8 @@
 
     def test_bogus_cases(self):
         raises(KeyError, '{0]}'.format, 5)
+        raises(ValueError, '{0!r'.format, 5)
+        raises(ValueError, '{0!rs}'.format, 5)
 
 
 class AppTestUnicodeFormat(BaseStringFormatTests):


More information about the Pypy-commit mailing list