[pypy-svn] r80020 - in pypy/branch/fast-forward/pypy/objspace/std: . test
agaynor at codespeak.net
agaynor at codespeak.net
Mon Dec 13 07:33:31 CET 2010
Author: agaynor
Date: Mon Dec 13 07:33:29 2010
New Revision: 80020
Modified:
pypy/branch/fast-forward/pypy/objspace/std/stringobject.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_stringobject.py
Log:
Make "\t\t".expandtabs(sys.maxint) raise an OverflowError with a useful error message.
Modified: pypy/branch/fast-forward/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/stringobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/stringobject.py Mon Dec 13 07:33:29 2010
@@ -671,12 +671,18 @@
def str_expandtabs__String_ANY(space, w_self, w_tabsize):
u_self = w_self._value
- u_tabsize = space.int_w(w_tabsize)
+ u_tabsize = space.int_w(w_tabsize)
u_expanded = ""
if u_self:
split = u_self.split("\t")
- u_expanded =oldtoken = split.pop(0)
+ try:
+ ovfcheck(len(split) * u_tabsize)
+ except OverflowError:
+ raise OperationError(space.w_OverflowError,
+ space.wrap("new string is too long")
+ )
+ u_expanded = oldtoken = split.pop(0)
for token in split:
#print "%d#%d -%s-" % (_tabindent(oldtoken,u_tabsize), u_tabsize, token)
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_stringobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_stringobject.py Mon Dec 13 07:33:29 2010
@@ -351,6 +351,8 @@
raises(TypeError, 'hello'.endswith, (42,))
def test_expandtabs(self):
+ import sys
+
assert 'abc\rab\tdef\ng\thi'.expandtabs() == 'abc\rab def\ng hi'
assert 'abc\rab\tdef\ng\thi'.expandtabs(8) == 'abc\rab def\ng hi'
assert 'abc\rab\tdef\ng\thi'.expandtabs(4) == 'abc\rab def\ng hi'
@@ -360,16 +362,18 @@
assert 'abc\r\nab\r\ndef\ng\r\nhi'.expandtabs(4) == 'abc\r\nab\r\ndef\ng\r\nhi'
s = 'xy\t'
- assert s.expandtabs() =='xy '
+ assert s.expandtabs() == 'xy '
s = '\txy\t'
- assert s.expandtabs() ==' xy '
- assert s.expandtabs(1) ==' xy '
- assert s.expandtabs(2) ==' xy '
- assert s.expandtabs(3) ==' xy '
+ assert s.expandtabs() == ' xy '
+ assert s.expandtabs(1) == ' xy '
+ assert s.expandtabs(2) == ' xy '
+ assert s.expandtabs(3) == ' xy '
+
+ assert 'xy'.expandtabs() == 'xy'
+ assert ''.expandtabs() == ''
- assert 'xy'.expandtabs() =='xy'
- assert ''.expandtabs() ==''
+ raises(OverflowError, "t\tt\t".expandtabs, sys.maxint)
def test_expandtabs_overflows_gracefully(self):
import sys
More information about the Pypy-commit
mailing list