Commits

Brian Curtin  committed bb394a5

bytes/str changes to make twisted.web.test.test_webclient.ParseUrlTestCase pass (80/443 issue remains)

  • Participants
  • Parent commits 4b2a79c
  • Branches t3k

Comments (0)

Files changed (3)

File twisted/web/client.py

     url = url.strip()
     parsed = http.urlparse(url)
     scheme = parsed[0]
-    path = urlunparse(('', '') + parsed[2:])
+    path = urlunparse((b'', b'') + parsed[2:])
 
     if defaultPort is None:
         if scheme == 'https':
             defaultPort = 80
 
     host, port = parsed[1], defaultPort
-    if ':' in host:
+    if b':' in host:
         host, port = host.split(':')
         try:
             port = int(port)

File twisted/web/http.py

     Parse an URL into six components.
 
     This is similar to L{urlparse.urlparse}, but rejects C{unicode} input
-    and always produces C{str} output.
+    and always produces C{bytes} output.
 
     @type url: C{str}
 
     of the URL.
     """
     if isinstance(url, str):
-        raise TypeError("url must be str, not unicode")
+        raise TypeError("url must be bytes, not str")
     scheme, netloc, path, params, query, fragment = _urlparse(url)
     if isinstance(scheme, str):
         scheme = scheme.encode('ascii')

File twisted/web/test/test_webclient.py

         """
         # The default port for HTTP is 80.
         self.assertEqual(
-            client._parse('http://127.0.0.1/'),
-            ('http', '127.0.0.1', 80, '/'))
+            client._parse(b'http://127.0.0.1/'),
+            (b'http', b'127.0.0.1', 80, b'/'))
 
         # The default port for HTTPS is 443.
         self.assertEqual(
-            client._parse('https://127.0.0.1/'),
-            ('https', '127.0.0.1', 443, '/'))
+            client._parse(b'https://127.0.0.1/'),
+            (b'https', b'127.0.0.1', 443, b'/'))
 
         # Specifying a port.
         self.assertEqual(
-            client._parse('http://spam:12345/'),
-            ('http', 'spam', 12345, '/'))
+            client._parse(b'http://spam:12345/'),
+            (b'http', b'spam', 12345, b'/'))
 
         # Weird (but commonly accepted) structure uses default port.
         self.assertEqual(
-            client._parse('http://spam:/'),
-            ('http', 'spam', 80, '/'))
+            client._parse(b'http://spam:/'),
+            (b'http', b'spam', 80, b'/'))
 
         # Spaces in the hostname are trimmed, the default path is /.
         self.assertEqual(
-            client._parse('http://foo '),
-            ('http', 'foo', 80, '/'))
+            client._parse(b'http://foo '),
+            (b'http', b'foo', 80, b'/'))
 
 
     def test_externalUnicodeInterference(self):
         goodInput = badInput.encode('ascii')
         urlparse(badInput)
         scheme, host, port, path = client._parse(goodInput)
-        self.assertIsInstance(scheme, str)
-        self.assertIsInstance(host, str)
-        self.assertIsInstance(path, str)
+        self.assertIsInstance(scheme, bytes)
+        self.assertIsInstance(host, bytes)
+        self.assertIsInstance(path, bytes)