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

Skip to content

Commit f207277

Browse files
author
Michael W. Hudson
committed
More --disable-unicode stuff.
I'm getting better at vi!
1 parent 3704644 commit f207277

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

Lib/UserString.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
Note: string objects have grown methods in Python 1.6
66
This module requires Python 1.6 or later.
77
"""
8-
from types import StringType, UnicodeType
8+
from types import StringTypes
99
import sys
1010

1111
__all__ = ["UserString","MutableString"]
1212

1313
class UserString:
1414
def __init__(self, seq):
15-
if isinstance(seq, StringType) or isinstance(seq, UnicodeType):
15+
if isinstance(seq, StringTypes):
1616
self.data = seq
1717
elif isinstance(seq, UserString):
1818
self.data = seq.data[:]
@@ -43,19 +43,19 @@ def __getslice__(self, start, end):
4343
def __add__(self, other):
4444
if isinstance(other, UserString):
4545
return self.__class__(self.data + other.data)
46-
elif isinstance(other, StringType) or isinstance(other, UnicodeType):
46+
elif isinstance(other, StringTypes):
4747
return self.__class__(self.data + other)
4848
else:
4949
return self.__class__(self.data + str(other))
5050
def __radd__(self, other):
51-
if isinstance(other, StringType) or isinstance(other, UnicodeType):
51+
if isinstance(other, StringTypes):
5252
return self.__class__(other + self.data)
5353
else:
5454
return self.__class__(str(other) + self.data)
5555
def __iadd__(self, other):
5656
if isinstance(other, UserString):
5757
self.data += other.data
58-
elif isinstance(other, StringType) or isinstance(other, UnicodeType):
58+
elif isinstance(other, StringTypes):
5959
self.data += other
6060
else:
6161
self.data += str(other)
@@ -159,7 +159,7 @@ def __setslice__(self, start, end, sub):
159159
start = max(start, 0); end = max(end, 0)
160160
if isinstance(sub, UserString):
161161
self.data = self.data[:start]+sub.data+self.data[end:]
162-
elif isinstance(sub, StringType) or isinstance(sub, UnicodeType):
162+
elif isinstance(sub, StringTypes):
163163
self.data = self.data[:start]+sub+self.data[end:]
164164
else:
165165
self.data = self.data[:start]+str(sub)+self.data[end:]

Lib/test/string_tests.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,15 @@ def run_method_tests(test):
176176
test('strip', 'hello', 'hello', 'xyz')
177177

178178
# strip/lstrip/rstrip with unicode arg
179-
test('strip', 'xyzzyhelloxyzzy', u'hello', u'xyz')
180-
test('lstrip', 'xyzzyhelloxyzzy', u'helloxyzzy', u'xyz')
181-
test('rstrip', 'xyzzyhelloxyzzy', u'xyzzyhello', u'xyz')
182-
test('strip', 'hello', u'hello', u'xyz')
179+
if have_unicode:
180+
test('strip', 'xyzzyhelloxyzzy',
181+
unicode('hello', 'ascii'), unicode('xyz', 'ascii'))
182+
test('lstrip', 'xyzzyhelloxyzzy',
183+
unicode('helloxyzzy', 'ascii'), unicode('xyz', 'ascii'))
184+
test('rstrip', 'xyzzyhelloxyzzy',
185+
unicode('xyzzyhello', 'ascii'), unicode('xyz', 'ascii'))
186+
test('strip', 'hello',
187+
unicode('hello', 'ascii'), unicode('xyz', 'ascii'))
183188

184189
test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
185190
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')

0 commit comments

Comments
 (0)