]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix some tests I broke. (More to follow.)
authorGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 21:47:52 +0000 (21:47 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 21:47:52 +0000 (21:47 +0000)
Lib/UserString.py
Lib/base64.py
Lib/test/test_urllib2.py

index 62e73bbc9df9b4ca2819adc717299c1ff489270b..500cd12c15dd4062a1dda5de576adb91c94c8b08 100755 (executable)
@@ -57,6 +57,8 @@ class UserString:
             return self.data >= string
 
     def __contains__(self, char):
+        if isinstance(char, UserString):
+            char = char.data
         return char in self.data
 
     def __len__(self): return len(self.data)
@@ -88,6 +90,8 @@ class UserString:
     def center(self, width, *args):
         return self.__class__(self.data.center(width, *args))
     def count(self, sub, start=0, end=sys.maxint):
+        if isinstance(sub, UserString):
+            sub = sub.data
         return self.data.count(sub, start, end)
     def decode(self, encoding=None, errors=None): # XXX improve this?
         if encoding:
@@ -110,6 +114,8 @@ class UserString:
     def expandtabs(self, tabsize=8):
         return self.__class__(self.data.expandtabs(tabsize))
     def find(self, sub, start=0, end=sys.maxint):
+        if isinstance(sub, UserString):
+            sub = sub.data
         return self.data.find(sub, start, end)
     def index(self, sub, start=0, end=sys.maxint):
         return self.data.index(sub, start, end)
@@ -130,6 +136,10 @@ class UserString:
     def partition(self, sep):
         return self.data.partition(sep)
     def replace(self, old, new, maxsplit=-1):
+        if isinstance(old, UserString):
+            old = old.data
+        if isinstance(new, UserString):
+            new = new.data
         return self.__class__(self.data.replace(old, new, maxsplit))
     def rfind(self, sub, start=0, end=sys.maxint):
         return self.data.rfind(sub, start, end)
index cec64229751f45cf774d6c6ac783d554bc8f8ef0..5d42065e2d355ebe64ce1896ea2b8d4f634038ee 100755 (executable)
@@ -28,7 +28,8 @@ __all__ = [
 
 
 def _translate(s, altchars):
-    assert isinstance(s, bytes), type(s)
+    if not isinstance(s, bytes):
+        raise TypeError("expected bytes, not %s" % s.__class__.__name__)
     translation = bytes(range(256))
     for k, v in altchars.items():
         translation[ord(k)] = v[0]
@@ -323,7 +324,8 @@ def decode(input, output):
 
 def encodestring(s):
     """Encode a string into multiple lines of base-64 data."""
-    assert isinstance(s, bytes), repr(s)
+    if not isinstance(s, bytes):
+        raise TypeError("expected bytes, not %s" % s.__class__.__name__)
     pieces = []
     for i in range(0, len(s), MAXBINSIZE):
         chunk = s[i : i + MAXBINSIZE]
@@ -333,7 +335,8 @@ def encodestring(s):
 
 def decodestring(s):
     """Decode a string."""
-    assert isinstance(s, bytes), repr(s)
+    if not isinstance(s, bytes):
+        raise TypeError("expected bytes, not %s" % s.__class__.__name__)
     return binascii.a2b_base64(s)
 
 
index 22979f6947623feffc999e799714988f2e8e5b01..5cbc6522084e22c8591daef860edad6b79717655 100644 (file)
@@ -998,7 +998,7 @@ class HandlerTests(unittest.TestCase):
         # expect one request without authorization, then one with
         self.assertEqual(len(http_handler.requests), 2)
         self.assertFalse(http_handler.requests[0].has_header(auth_header))
-        userpass = '%s:%s' % (user, password)
+        userpass = bytes('%s:%s' % (user, password), "ascii")
         auth_hdr_value = 'Basic ' + str(base64.encodestring(userpass)).strip()
         self.assertEqual(http_handler.requests[1].get_header(auth_header),
                          auth_hdr_value)