summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urlparse.py
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2005-01-09 15:29:10 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2005-01-09 15:29:10 (GMT)
commit41e4faa82bdf4fb601a97565bf30ee683c4bfd50 (patch)
tree64d542aff19737d2d93f8fcfe3b4a15d41e117f0 /Lib/test/test_urlparse.py
parentcdd625a77067e226a5dc715d1892f9511a067391 (diff)
downloadcpython-41e4faa82bdf4fb601a97565bf30ee683c4bfd50.zip
cpython-41e4faa82bdf4fb601a97565bf30ee683c4bfd50.tar.gz
cpython-41e4faa82bdf4fb601a97565bf30ee683c4bfd50.tar.bz2
Patch #712317: In URLs such as http://www.example.com?query=spam, treat '?' as
a delimiter. Previously, the 'network location' (<authority> in RFC 2396) would become 'www.example.com?query=spam', while RFC 2396 does not allow a '?' in <authority>. See bug #548176 for further discussion.
Diffstat (limited to 'Lib/test/test_urlparse.py')
-rw-r--r--Lib/test/test_urlparse.py79
1 files changed, 51 insertions, 28 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 8932b3c..04572ba 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -8,20 +8,22 @@ RFC1808_BASE = "http://a/b/c/d;p?q#f"
RFC2396_BASE = "http://a/b/c/d;p?q"
class UrlParseTestCase(unittest.TestCase):
- def test_frags(self):
- for url, parsed, split in [
- ('http://www.python.org',
- ('http', 'www.python.org', '', '', '', ''),
- ('http', 'www.python.org', '', '', '')),
- ('http://www.python.org#abc',
- ('http', 'www.python.org', '', '', '', 'abc'),
- ('http', 'www.python.org', '', '', 'abc')),
- ('http://www.python.org/#abc',
- ('http', 'www.python.org', '/', '', '', 'abc'),
- ('http', 'www.python.org', '/', '', 'abc')),
- (RFC1808_BASE,
- ('http', 'a', '/b/c/d', 'p', 'q', 'f'),
- ('http', 'a', '/b/c/d;p', 'q', 'f')),
+
+ def checkRoundtrips(self, url, parsed, split):
+ result = urlparse.urlparse(url)
+ self.assertEqual(result, parsed)
+ # put it back together and it should be the same
+ result2 = urlparse.urlunparse(result)
+ self.assertEqual(result2, url)
+
+ # check the roundtrip using urlsplit() as well
+ result = urlparse.urlsplit(url)
+ self.assertEqual(result, split)
+ result2 = urlparse.urlunsplit(result)
+ self.assertEqual(result2, url)
+
+ def test_roundtrips(self):
+ testcases = [
('file:///tmp/junk.txt',
('file', '', '/tmp/junk.txt', '', '', ''),
('file', '', '/tmp/junk.txt', '', '')),
@@ -29,20 +31,41 @@ class UrlParseTestCase(unittest.TestCase):
('imap', 'mail.python.org', '/mbox1', '', '', ''),
('imap', 'mail.python.org', '/mbox1', '', '')),
('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf',
- ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '', ''),
- ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '')),
- ]:
- result = urlparse.urlparse(url)
- self.assertEqual(result, parsed)
- # put it back together and it should be the same
- result2 = urlparse.urlunparse(result)
- self.assertEqual(result2, url)
-
- # check the roundtrip using urlsplit() as well
- result = urlparse.urlsplit(url)
- self.assertEqual(result, split)
- result2 = urlparse.urlunsplit(result)
- self.assertEqual(result2, url)
+ ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
+ '', '', ''),
+ ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
+ '', '')),
+ ]
+ for url, parsed, split in testcases:
+ self.checkRoundtrips(url, parsed, split)
+
+ def test_http_roundtrips(self):
+ # urlparse.urlsplit treats 'http:' as an optimized special case,
+ # so we test both 'http:' and 'https:' in all the following.
+ # Three cheers for white box knowledge!
+ testcases = [
+ ('://www.python.org',
+ ('www.python.org', '', '', '', ''),
+ ('www.python.org', '', '', '')),
+ ('://www.python.org#abc',
+ ('www.python.org', '', '', '', 'abc'),
+ ('www.python.org', '', '', 'abc')),
+ ('://www.python.org?q=abc',
+ ('www.python.org', '', '', 'q=abc', ''),
+ ('www.python.org', '', 'q=abc', '')),
+ ('://www.python.org/#abc',
+ ('www.python.org', '/', '', '', 'abc'),
+ ('www.python.org', '/', '', 'abc')),
+ ('://a/b/c/d;p?q#f',
+ ('a', '/b/c/d', 'p', 'q', 'f'),
+ ('a', '/b/c/d;p', 'q', 'f')),
+ ]
+ for scheme in ('http', 'https'):
+ for url, parsed, split in testcases:
+ url = scheme + url
+ parsed = (scheme,) + parsed
+ split = (scheme,) + split
+ self.checkRoundtrips(url, parsed, split)
def checkJoin(self, base, relurl, expected):
self.assertEqual(urlparse.urljoin(base, relurl), expected,