Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ee4be0

Browse files
committed
Apply diff3.txt from SF patch http://www.python.org/sf/536241
If a str or unicode method returns the original object, make sure that for str and unicode subclasses the original will not be returned. This should prevent SF bug http://www.python.org/sf/460020 from reappearing.
1 parent 1ec71ea commit 2ee4be0

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lib/test/test_string.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ def test(name, input, output, *args):
2222
except:
2323
value = sys.exc_type
2424
f = name
25+
if value == output:
26+
# if the original is returned make sure that
27+
# this doesn't happen with subclasses
28+
if value is input:
29+
class ssub(str):
30+
def __repr__(self):
31+
return 'ssub(%r)' % str.__repr__(self)
32+
input = ssub(input)
33+
try:
34+
f = getattr(input, name)
35+
value = apply(f, args)
36+
except AttributeError:
37+
f = getattr(string, name)
38+
value = apply(f, (input,) + args)
39+
if value is input:
40+
if verbose:
41+
print 'no'
42+
print '*',f, `input`, `output`, `value`
43+
return
2544
if value != output:
2645
if verbose:
2746
print 'no'

Lib/test/test_unicode.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ def test(method, input, output, *args):
5252
exc = sys.exc_info()[:2]
5353
else:
5454
exc = None
55+
if value == output and type(value) is type(output):
56+
# if the original is returned make sure that
57+
# this doesn't happen with subclasses
58+
if value is input:
59+
class usub(unicode):
60+
def __repr__(self):
61+
return 'usub(%r)' % unicode.__repr__(self)
62+
input = usub(input)
63+
try:
64+
f = getattr(input, method)
65+
value = apply(f, args)
66+
except:
67+
value = sys.exc_type
68+
exc = sys.exc_info()[:2]
69+
if value is input:
70+
if verbose:
71+
print 'no'
72+
print '*',f, `input`, `output`, `value`
73+
return
5574
if value != output or type(value) is not type(output):
5675
if verbose:
5776
print 'no'
@@ -63,6 +82,7 @@ def test(method, input, output, *args):
6382
print 'yes'
6483

6584
test('capitalize', u' hello ', u' hello ')
85+
test('capitalize', u'Hello ', u'Hello ')
6686
test('capitalize', u'hello ', u'Hello ')
6787
test('capitalize', u'aaaa', u'Aaaa')
6888
test('capitalize', u'AaAa', u'Aaaa')
@@ -75,6 +95,7 @@ def test(method, input, output, *args):
7595
test('count', u'aaa', 0, 'b')
7696

7797
test('title', u' hello ', u' Hello ')
98+
test('title', u'Hello ', u'Hello ')
7899
test('title', u'hello ', u'Hello ')
79100
test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
80101
test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String')
@@ -200,6 +221,7 @@ def __getitem__(self, i): return self.seq[i]
200221
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
201222
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4)
202223
test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4)
224+
test('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4)
203225

204226
if 0:
205227
test('capwords', u'abc def ghi', u'Abc Def Ghi')

0 commit comments

Comments
 (0)