Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r56197:632de45afcdb
Date: 2012-07-18 22:27 +0200
http://bitbucket.org/pypy/pypy/changeset/632de45afcdb/
Log: bah, we cannot use unicode.lower in rpython. Work-around that
diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py
--- a/pypy/objspace/std/strutil.py
+++ b/pypy/objspace/std/strutil.py
@@ -166,7 +166,6 @@
MANTISSA_DIGITS = len(str( (1L << MANTISSA_BITS)-1 )) + 1
@enforceargs(unicode)
-@with_unicode_literals
def string_to_float(s):
"""
Conversion of string to float.
@@ -179,30 +178,31 @@
s = strip_spaces(s)
if not s:
- raise ParseStringError("empty string for float()")
+ raise ParseStringError(u"empty string for float()")
- low = s.lower()
- if low == "-inf" or low == "-infinity":
- return -INFINITY
- elif low == "inf" or low == "+inf":
- return INFINITY
- elif low == "infinity" or low == "+infinity":
- return INFINITY
- elif low == "nan" or low == "+nan":
- return NAN
- elif low == "-nan":
- return -NAN
+ try:
+ ascii_s = s.encode('ascii')
+ except UnicodeEncodeError:
+ # if it's not ASCII, it certainly is not one of the cases below
+ pass
+ else:
+ low = ascii_s.lower()
+ if low == "-inf" or low == "-infinity":
+ return -INFINITY
+ elif low == "inf" or low == "+inf":
+ return INFINITY
+ elif low == "infinity" or low == "+infinity":
+ return INFINITY
+ elif low == "nan" or low == "+nan":
+ return NAN
+ elif low == "-nan":
+ return -NAN
# rstring_to_float only supports byte strings, but we have an unicode
# here. Do as CPython does: convert it to UTF-8
- mystring = encode_utf8(s)
+ mystring = s.encode('utf-8')
try:
return rstring_to_float(mystring)
except ValueError:
- raise ParseStringError("invalid literal for float(): '%s'" % s)
-
-# we need to put it in a separate function else 'utf-8' becomes an unicode
-# literal too
-def encode_utf8(s):
- return s.encode('utf-8')
+ raise ParseStringError(u"invalid literal for float(): '%s'" % s)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit