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

afa at codespeak.net afa at codespeak.net
Thu Oct 28 23:41:23 CEST 2010


Author: afa
Date: Thu Oct 28 23:41:22 2010
New Revision: 78425

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/strutil.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_strutil.py
Log:
'0x' is not a correct hexadecimal number.


Modified: pypy/branch/fast-forward/pypy/objspace/std/strutil.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/strutil.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/strutil.py	Thu Oct 28 23:41:22 2010
@@ -62,14 +62,14 @@
             raise ParseStringError, "%s() base must be >= 2 and <= 36" % (fname,)
         self.base = base
 
-        if not s:
-            self.error()
         if base == 16 and (s.startswith('0x') or s.startswith('0X')):
             s = s[2:]
         if base == 8 and (s.startswith('0o') or s.startswith('0O')):
             s = s[2:]
         if base == 2 and (s.startswith('0b') or s.startswith('0B')):
             s = s[2:]
+        if not s:
+            self.error()
         self.s = s
         self.n = len(s)
         self.i = 0

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_strutil.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_strutil.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_strutil.py	Thu Oct 28 23:41:22 2010
@@ -88,6 +88,8 @@
             raises(ParseStringError, string_to_int, s+'  ')
             raises(ParseStringError, string_to_int, '+'+s)
             raises(ParseStringError, string_to_int, '-'+s)
+        raises(ParseStringError, string_to_int, '0x', 16)
+        raises(ParseStringError, string_to_int, '-0x', 16)
 
     def test_string_to_int_overflow(self):
         import sys



More information about the Pypy-commit mailing list