Kaydet (Commit) 2ee4be07 authored tarafından Walter Dörwald's avatar Walter Dörwald

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.
üst 1ec71ea4
...@@ -22,6 +22,25 @@ def test(name, input, output, *args): ...@@ -22,6 +22,25 @@ def test(name, input, output, *args):
except: except:
value = sys.exc_type value = sys.exc_type
f = name f = name
if value == output:
# if the original is returned make sure that
# this doesn't happen with subclasses
if value is input:
class ssub(str):
def __repr__(self):
return 'ssub(%r)' % str.__repr__(self)
input = ssub(input)
try:
f = getattr(input, name)
value = apply(f, args)
except AttributeError:
f = getattr(string, name)
value = apply(f, (input,) + args)
if value is input:
if verbose:
print 'no'
print '*',f, `input`, `output`, `value`
return
if value != output: if value != output:
if verbose: if verbose:
print 'no' print 'no'
......
...@@ -52,6 +52,25 @@ def test(method, input, output, *args): ...@@ -52,6 +52,25 @@ def test(method, input, output, *args):
exc = sys.exc_info()[:2] exc = sys.exc_info()[:2]
else: else:
exc = None exc = None
if value == output and type(value) is type(output):
# if the original is returned make sure that
# this doesn't happen with subclasses
if value is input:
class usub(unicode):
def __repr__(self):
return 'usub(%r)' % unicode.__repr__(self)
input = usub(input)
try:
f = getattr(input, method)
value = apply(f, args)
except:
value = sys.exc_type
exc = sys.exc_info()[:2]
if value is input:
if verbose:
print 'no'
print '*',f, `input`, `output`, `value`
return
if value != output or type(value) is not type(output): if value != output or type(value) is not type(output):
if verbose: if verbose:
print 'no' print 'no'
...@@ -63,6 +82,7 @@ def test(method, input, output, *args): ...@@ -63,6 +82,7 @@ def test(method, input, output, *args):
print 'yes' print 'yes'
test('capitalize', u' hello ', u' hello ') test('capitalize', u' hello ', u' hello ')
test('capitalize', u'Hello ', u'Hello ')
test('capitalize', u'hello ', u'Hello ') test('capitalize', u'hello ', u'Hello ')
test('capitalize', u'aaaa', u'Aaaa') test('capitalize', u'aaaa', u'Aaaa')
test('capitalize', u'AaAa', u'Aaaa') test('capitalize', u'AaAa', u'Aaaa')
...@@ -75,6 +95,7 @@ test('count', u'aaa', 3, 'a') ...@@ -75,6 +95,7 @@ test('count', u'aaa', 3, 'a')
test('count', u'aaa', 0, 'b') test('count', u'aaa', 0, 'b')
test('title', u' hello ', u' Hello ') test('title', u' hello ', u' Hello ')
test('title', u'Hello ', u'Hello ')
test('title', u'hello ', u'Hello ') test('title', u'hello ', u'Hello ')
test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String') test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String') test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String')
...@@ -200,6 +221,7 @@ test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi') ...@@ -200,6 +221,7 @@ test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi')
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8) test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8)
test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4) test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4)
test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4) test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4)
test('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4)
if 0: if 0:
test('capwords', u'abc def ghi', u'Abc Def Ghi') test('capwords', u'abc def ghi', u'Abc Def Ghi')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment