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

Skip to content

Commit 98b349f

Browse files
committed
Fix some tests I broke. (More to follow.)
1 parent 1f2ca56 commit 98b349f

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

Lib/UserString.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def __ge__(self, string):
5757
return self.data >= string
5858

5959
def __contains__(self, char):
60+
if isinstance(char, UserString):
61+
char = char.data
6062
return char in self.data
6163

6264
def __len__(self): return len(self.data)
@@ -88,6 +90,8 @@ def capitalize(self): return self.__class__(self.data.capitalize())
8890
def center(self, width, *args):
8991
return self.__class__(self.data.center(width, *args))
9092
def count(self, sub, start=0, end=sys.maxint):
93+
if isinstance(sub, UserString):
94+
sub = sub.data
9195
return self.data.count(sub, start, end)
9296
def decode(self, encoding=None, errors=None): # XXX improve this?
9397
if encoding:
@@ -110,6 +114,8 @@ def endswith(self, suffix, start=0, end=sys.maxint):
110114
def expandtabs(self, tabsize=8):
111115
return self.__class__(self.data.expandtabs(tabsize))
112116
def find(self, sub, start=0, end=sys.maxint):
117+
if isinstance(sub, UserString):
118+
sub = sub.data
113119
return self.data.find(sub, start, end)
114120
def index(self, sub, start=0, end=sys.maxint):
115121
return self.data.index(sub, start, end)
@@ -130,6 +136,10 @@ def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
130136
def partition(self, sep):
131137
return self.data.partition(sep)
132138
def replace(self, old, new, maxsplit=-1):
139+
if isinstance(old, UserString):
140+
old = old.data
141+
if isinstance(new, UserString):
142+
new = new.data
133143
return self.__class__(self.data.replace(old, new, maxsplit))
134144
def rfind(self, sub, start=0, end=sys.maxint):
135145
return self.data.rfind(sub, start, end)

Lib/base64.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929

3030
def _translate(s, altchars):
31-
assert isinstance(s, bytes), type(s)
31+
if not isinstance(s, bytes):
32+
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
3233
translation = bytes(range(256))
3334
for k, v in altchars.items():
3435
translation[ord(k)] = v[0]
@@ -323,7 +324,8 @@ def decode(input, output):
323324

324325
def encodestring(s):
325326
"""Encode a string into multiple lines of base-64 data."""
326-
assert isinstance(s, bytes), repr(s)
327+
if not isinstance(s, bytes):
328+
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
327329
pieces = []
328330
for i in range(0, len(s), MAXBINSIZE):
329331
chunk = s[i : i + MAXBINSIZE]
@@ -333,7 +335,8 @@ def encodestring(s):
333335

334336
def decodestring(s):
335337
"""Decode a string."""
336-
assert isinstance(s, bytes), repr(s)
338+
if not isinstance(s, bytes):
339+
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
337340
return binascii.a2b_base64(s)
338341

339342

Lib/test/test_urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def _test_basic_auth(self, opener, auth_handler, auth_header,
998998
# expect one request without authorization, then one with
999999
self.assertEqual(len(http_handler.requests), 2)
10001000
self.assertFalse(http_handler.requests[0].has_header(auth_header))
1001-
userpass = '%s:%s' % (user, password)
1001+
userpass = bytes('%s:%s' % (user, password), "ascii")
10021002
auth_hdr_value = 'Basic ' + str(base64.encodestring(userpass)).strip()
10031003
self.assertEqual(http_handler.requests[1].get_header(auth_header),
10041004
auth_hdr_value)

0 commit comments

Comments
 (0)