Author: Philip Jenvey <[email protected]>
Branch:
Changeset: r69031:307818c61207
Date: 2014-01-30 15:39 -0800
http://bitbucket.org/pypy/pypy/changeset/307818c61207/
Log: bring over the ability to ignore the L suffix from py3k
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -254,16 +254,18 @@
@staticmethod
@jit.elidable
- def fromstr(s, base=0):
- """As string_to_int(), but ignores an optional 'l' or 'L' suffix
- and returns an rbigint."""
+ def fromstr(s, base=0, ignore_l_suffix=False, fname='long'):
+ """As string_to_int(), but optionally ignores an optional 'l' or
+ 'L' suffix and returns an rbigint.
+ """
from rpython.rlib.rstring import NumberStringParser, \
strip_spaces
s = literal = strip_spaces(s)
- if (s.endswith('l') or s.endswith('L')) and base < 22:
+ if (not ignore_l_suffix and (s.endswith('l') or s.endswith('L')) and
+ base < 22):
# in base 22 and above, 'L' is a valid digit! try: long('L',22)
s = s[:-1]
- parser = NumberStringParser(s, literal, base, 'long')
+ parser = NumberStringParser(s, literal, base, fname)
return rbigint._from_numberstring_parser(parser)
@staticmethod
diff --git a/rpython/rlib/test/test_rbigint.py
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -214,8 +214,13 @@
from rpython.rlib.rstring import ParseStringError
assert rbigint.fromstr('123L').tolong() == 123
assert rbigint.fromstr('123L ').tolong() == 123
+ py.test.raises(ParseStringError, rbigint.fromstr, '123L ',
+ ignore_l_suffix=True)
py.test.raises(ParseStringError, rbigint.fromstr, 'L')
py.test.raises(ParseStringError, rbigint.fromstr, 'L ')
+ e = py.test.raises(ParseStringError, rbigint.fromstr, 'L ',
+ fname='int')
+ assert 'int()' in e.value.msg
assert rbigint.fromstr('123L', 4).tolong() == 27
assert rbigint.fromstr('123L', 30).tolong() == 27000 + 1800 + 90 + 21
assert rbigint.fromstr('123L', 22).tolong() == 10648 + 968 + 66 + 21
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit