Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_urlparse.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 2ff89f0f1d19 |
| children | 7da7f9bfdaac |
| rev | line source |
|---|---|
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
1 #! /usr/bin/env python |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
2 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23075
diff
changeset
|
3 from test import test_support |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
4 import unittest |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
5 import urlparse |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
6 |
|
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
7 RFC1808_BASE = "http://a/b/c/d;p?q#f" |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
8 RFC2396_BASE = "http://a/b/c/d;p?q" |
|
48233
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
9 RFC3986_BASE = "http://a/b/c/d;p?q" |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
10 |
|
48995
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
11 # A list of test cases. Each test case is a a two-tuple that contains |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
12 # a string with the query and a dictionary with the expected result. |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
13 |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
14 parse_qsl_test_cases = [ |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
15 ("", []), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
16 ("&", []), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
17 ("&&", []), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
18 ("=", [('', '')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
19 ("=a", [('', 'a')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
20 ("a", [('a', '')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
21 ("a=", [('a', '')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
22 ("a=", [('a', '')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
23 ("&a=b", [('a', 'b')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
24 ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
25 ("a=1&a=2", [('a', '1'), ('a', '2')]), |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
26 ] |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
27 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
28 class UrlParseTestCase(unittest.TestCase): |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
29 |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
30 def checkRoundtrips(self, url, parsed, split): |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
31 result = urlparse.urlparse(url) |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
32 self.assertEqual(result, parsed) |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
33 t = (result.scheme, result.netloc, result.path, |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
34 result.params, result.query, result.fragment) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
35 self.assertEqual(t, parsed) |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
36 # put it back together and it should be the same |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
37 result2 = urlparse.urlunparse(result) |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
38 self.assertEqual(result2, url) |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
39 self.assertEqual(result2, result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
40 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
41 # the result of geturl() is a fixpoint; we can always parse it |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
42 # again to get the same result: |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
43 result3 = urlparse.urlparse(result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
44 self.assertEqual(result3.geturl(), result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
45 self.assertEqual(result3, result) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
46 self.assertEqual(result3.scheme, result.scheme) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
47 self.assertEqual(result3.netloc, result.netloc) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
48 self.assertEqual(result3.path, result.path) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
49 self.assertEqual(result3.params, result.params) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
50 self.assertEqual(result3.query, result.query) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
51 self.assertEqual(result3.fragment, result.fragment) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
52 self.assertEqual(result3.username, result.username) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
53 self.assertEqual(result3.password, result.password) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
54 self.assertEqual(result3.hostname, result.hostname) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
55 self.assertEqual(result3.port, result.port) |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
56 |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
57 # check the roundtrip using urlsplit() as well |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
58 result = urlparse.urlsplit(url) |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
59 self.assertEqual(result, split) |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
60 t = (result.scheme, result.netloc, result.path, |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
61 result.query, result.fragment) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
62 self.assertEqual(t, split) |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
63 result2 = urlparse.urlunsplit(result) |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
64 self.assertEqual(result2, url) |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
65 self.assertEqual(result2, result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
66 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
67 # check the fixpoint property of re-parsing the result of geturl() |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
68 result3 = urlparse.urlsplit(result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
69 self.assertEqual(result3.geturl(), result.geturl()) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
70 self.assertEqual(result3, result) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
71 self.assertEqual(result3.scheme, result.scheme) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
72 self.assertEqual(result3.netloc, result.netloc) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
73 self.assertEqual(result3.path, result.path) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
74 self.assertEqual(result3.query, result.query) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
75 self.assertEqual(result3.fragment, result.fragment) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
76 self.assertEqual(result3.username, result.username) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
77 self.assertEqual(result3.password, result.password) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
78 self.assertEqual(result3.hostname, result.hostname) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
79 self.assertEqual(result3.port, result.port) |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
80 |
|
48995
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
81 def test_qsl(self): |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
82 for orig, expect in parse_qsl_test_cases: |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
83 result = urlparse.parse_qsl(orig, keep_blank_values=True) |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
84 self.assertEqual(result, expect, "Error parsing %s" % repr(orig)) |
|
2b855a947f0f
Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents:
48233
diff
changeset
|
85 |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
86 def test_roundtrips(self): |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
87 testcases = [ |
|
25812
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
88 ('file:///tmp/junk.txt', |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
89 ('file', '', '/tmp/junk.txt', '', '', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
90 ('file', '', '/tmp/junk.txt', '', '')), |
|
27100
8226658a63bb
SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents:
25812
diff
changeset
|
91 ('imap://mail.python.org/mbox1', |
|
8226658a63bb
SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents:
25812
diff
changeset
|
92 ('imap', 'mail.python.org', '/mbox1', '', '', ''), |
|
8226658a63bb
SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents:
25812
diff
changeset
|
93 ('imap', 'mail.python.org', '/mbox1', '', '')), |
|
27121
7ec771893410
* add mms (windows media) as another scheme
Skip Montanaro <skip@pobox.com>
parents:
27100
diff
changeset
|
94 ('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf', |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
95 ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
96 '', '', ''), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
97 ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
98 '', '')), |
|
52476
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
48995
diff
changeset
|
99 ('nfs://server/path/to/file.txt', |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
48995
diff
changeset
|
100 ('nfs', 'server', '/path/to/file.txt', '', '', ''), |
|
2ff89f0f1d19
Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents:
48995
diff
changeset
|
101 ('nfs', 'server', '/path/to/file.txt', '', '')), |
|
35290
349a0fd598e0
add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents:
34379
diff
changeset
|
102 ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/', |
|
349a0fd598e0
add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents:
34379
diff
changeset
|
103 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/', |
|
349a0fd598e0
add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents:
34379
diff
changeset
|
104 '', '', ''), |
|
349a0fd598e0
add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents:
34379
diff
changeset
|
105 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/', |
|
349a0fd598e0
add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents:
34379
diff
changeset
|
106 '', '')) |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
107 ] |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
108 for url, parsed, split in testcases: |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
109 self.checkRoundtrips(url, parsed, split) |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
110 |
|
34379
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
111 def test_http_roundtrips(self): |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
112 # urlparse.urlsplit treats 'http:' as an optimized special case, |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
113 # so we test both 'http:' and 'https:' in all the following. |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
114 # Three cheers for white box knowledge! |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
115 testcases = [ |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
116 ('://www.python.org', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
117 ('www.python.org', '', '', '', ''), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
118 ('www.python.org', '', '', '')), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
119 ('://www.python.org#abc', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
120 ('www.python.org', '', '', '', 'abc'), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
121 ('www.python.org', '', '', 'abc')), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
122 ('://www.python.org?q=abc', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
123 ('www.python.org', '', '', 'q=abc', ''), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
124 ('www.python.org', '', 'q=abc', '')), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
125 ('://www.python.org/#abc', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
126 ('www.python.org', '/', '', '', 'abc'), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
127 ('www.python.org', '/', '', 'abc')), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
128 ('://a/b/c/d;p?q#f', |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
129 ('a', '/b/c/d', 'p', 'q', 'f'), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
130 ('a', '/b/c/d;p', 'q', 'f')), |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
131 ] |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
132 for scheme in ('http', 'https'): |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
133 for url, parsed, split in testcases: |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
134 url = scheme + url |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
135 parsed = (scheme,) + parsed |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
136 split = (scheme,) + split |
|
287e71f44d79
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents:
30674
diff
changeset
|
137 self.checkRoundtrips(url, parsed, split) |
|
25812
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
138 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
139 def checkJoin(self, base, relurl, expected): |
|
25785
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
140 self.assertEqual(urlparse.urljoin(base, relurl), expected, |
|
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
141 (base, relurl, expected)) |
|
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
142 |
|
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
143 def test_unparse_parse(self): |
|
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
144 for u in ['Python', './Python']: |
|
25812
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
145 self.assertEqual(urlparse.urlunsplit(urlparse.urlsplit(u)), u) |
|
25785
cf18ca0eea89
Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents:
25425
diff
changeset
|
146 self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u) |
| 22379 | 147 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
148 def test_RFC1808(self): |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
149 # "normal" cases from RFC 1808: |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
150 self.checkJoin(RFC1808_BASE, 'g:h', 'g:h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
151 self.checkJoin(RFC1808_BASE, 'g', 'http://a/b/c/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
152 self.checkJoin(RFC1808_BASE, './g', 'http://a/b/c/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
153 self.checkJoin(RFC1808_BASE, 'g/', 'http://a/b/c/g/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
154 self.checkJoin(RFC1808_BASE, '/g', 'http://a/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
155 self.checkJoin(RFC1808_BASE, '//g', 'http://g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
156 self.checkJoin(RFC1808_BASE, 'g?y', 'http://a/b/c/g?y') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
157 self.checkJoin(RFC1808_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
158 self.checkJoin(RFC1808_BASE, '#s', 'http://a/b/c/d;p?q#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
159 self.checkJoin(RFC1808_BASE, 'g#s', 'http://a/b/c/g#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
160 self.checkJoin(RFC1808_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
161 self.checkJoin(RFC1808_BASE, 'g?y#s', 'http://a/b/c/g?y#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
162 self.checkJoin(RFC1808_BASE, 'g;x', 'http://a/b/c/g;x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
163 self.checkJoin(RFC1808_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
164 self.checkJoin(RFC1808_BASE, '.', 'http://a/b/c/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
165 self.checkJoin(RFC1808_BASE, './', 'http://a/b/c/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
166 self.checkJoin(RFC1808_BASE, '..', 'http://a/b/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
167 self.checkJoin(RFC1808_BASE, '../', 'http://a/b/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
168 self.checkJoin(RFC1808_BASE, '../g', 'http://a/b/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
169 self.checkJoin(RFC1808_BASE, '../..', 'http://a/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
170 self.checkJoin(RFC1808_BASE, '../../', 'http://a/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
171 self.checkJoin(RFC1808_BASE, '../../g', 'http://a/g') |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
172 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
173 # "abnormal" cases from RFC 1808: |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
174 self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
175 self.checkJoin(RFC1808_BASE, '../../../g', 'http://a/../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
176 self.checkJoin(RFC1808_BASE, '../../../../g', 'http://a/../../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
177 self.checkJoin(RFC1808_BASE, '/./g', 'http://a/./g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
178 self.checkJoin(RFC1808_BASE, '/../g', 'http://a/../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
179 self.checkJoin(RFC1808_BASE, 'g.', 'http://a/b/c/g.') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
180 self.checkJoin(RFC1808_BASE, '.g', 'http://a/b/c/.g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
181 self.checkJoin(RFC1808_BASE, 'g..', 'http://a/b/c/g..') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
182 self.checkJoin(RFC1808_BASE, '..g', 'http://a/b/c/..g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
183 self.checkJoin(RFC1808_BASE, './../g', 'http://a/b/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
184 self.checkJoin(RFC1808_BASE, './g/.', 'http://a/b/c/g/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
185 self.checkJoin(RFC1808_BASE, 'g/./h', 'http://a/b/c/g/h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
186 self.checkJoin(RFC1808_BASE, 'g/../h', 'http://a/b/c/h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
187 |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
188 # RFC 1808 and RFC 1630 disagree on these (according to RFC 1808), |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
189 # so we'll not actually run these tests (which expect 1808 behavior). |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
190 #self.checkJoin(RFC1808_BASE, 'http:g', 'http:g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
191 #self.checkJoin(RFC1808_BASE, 'http:', 'http:') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
192 |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
193 def test_RFC2396(self): |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
194 # cases from RFC 2396 |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
195 |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
196 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
197 self.checkJoin(RFC2396_BASE, 'g:h', 'g:h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
198 self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
199 self.checkJoin(RFC2396_BASE, './g', 'http://a/b/c/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
200 self.checkJoin(RFC2396_BASE, 'g/', 'http://a/b/c/g/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
201 self.checkJoin(RFC2396_BASE, '/g', 'http://a/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
202 self.checkJoin(RFC2396_BASE, '//g', 'http://g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
203 self.checkJoin(RFC2396_BASE, 'g?y', 'http://a/b/c/g?y') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
204 self.checkJoin(RFC2396_BASE, '#s', 'http://a/b/c/d;p?q#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
205 self.checkJoin(RFC2396_BASE, 'g#s', 'http://a/b/c/g#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
206 self.checkJoin(RFC2396_BASE, 'g?y#s', 'http://a/b/c/g?y#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
207 self.checkJoin(RFC2396_BASE, 'g;x', 'http://a/b/c/g;x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
208 self.checkJoin(RFC2396_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
209 self.checkJoin(RFC2396_BASE, '.', 'http://a/b/c/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
210 self.checkJoin(RFC2396_BASE, './', 'http://a/b/c/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
211 self.checkJoin(RFC2396_BASE, '..', 'http://a/b/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
212 self.checkJoin(RFC2396_BASE, '../', 'http://a/b/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
213 self.checkJoin(RFC2396_BASE, '../g', 'http://a/b/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
214 self.checkJoin(RFC2396_BASE, '../..', 'http://a/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
215 self.checkJoin(RFC2396_BASE, '../../', 'http://a/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
216 self.checkJoin(RFC2396_BASE, '../../g', 'http://a/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
217 self.checkJoin(RFC2396_BASE, '', RFC2396_BASE) |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
218 self.checkJoin(RFC2396_BASE, '../../../g', 'http://a/../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
219 self.checkJoin(RFC2396_BASE, '../../../../g', 'http://a/../../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
220 self.checkJoin(RFC2396_BASE, '/./g', 'http://a/./g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
221 self.checkJoin(RFC2396_BASE, '/../g', 'http://a/../g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
222 self.checkJoin(RFC2396_BASE, 'g.', 'http://a/b/c/g.') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
223 self.checkJoin(RFC2396_BASE, '.g', 'http://a/b/c/.g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
224 self.checkJoin(RFC2396_BASE, 'g..', 'http://a/b/c/g..') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
225 self.checkJoin(RFC2396_BASE, '..g', 'http://a/b/c/..g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
226 self.checkJoin(RFC2396_BASE, './../g', 'http://a/b/g') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
227 self.checkJoin(RFC2396_BASE, './g/.', 'http://a/b/c/g/') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
228 self.checkJoin(RFC2396_BASE, 'g/./h', 'http://a/b/c/g/h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
229 self.checkJoin(RFC2396_BASE, 'g/../h', 'http://a/b/c/h') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
230 self.checkJoin(RFC2396_BASE, 'g;x=1/./y', 'http://a/b/c/g;x=1/y') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
231 self.checkJoin(RFC2396_BASE, 'g;x=1/../y', 'http://a/b/c/y') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
232 self.checkJoin(RFC2396_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
233 self.checkJoin(RFC2396_BASE, 'g?y/../x', 'http://a/b/c/g?y/../x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
234 self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
235 self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x') |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
236 |
|
48233
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
237 #The following scenarios have been updated in RFC3986 |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
238 #self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y') |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
239 #self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x') |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
240 |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
241 def test_RFC3986(self): |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
242 self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y') |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
243 self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x') |
|
af7388ad3164
Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents:
44510
diff
changeset
|
244 |
|
25812
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
245 def test_urldefrag(self): |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
246 for url, defrag, frag in [ |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
247 ('http://python.org#frag', 'http://python.org', 'frag'), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
248 ('http://python.org', 'http://python.org', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
249 ('http://python.org/#frag', 'http://python.org/', 'frag'), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
250 ('http://python.org/', 'http://python.org/', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
251 ('http://python.org/?q#frag', 'http://python.org/?q', 'frag'), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
252 ('http://python.org/?q', 'http://python.org/?q', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
253 ('http://python.org/p#frag', 'http://python.org/p', 'frag'), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
254 ('http://python.org/p?q', 'http://python.org/p?q', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
255 (RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
256 (RFC2396_BASE, 'http://a/b/c/d;p?q', ''), |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
257 ]: |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
258 self.assertEqual(urlparse.urldefrag(url), (defrag, frag)) |
|
5d352de94415
Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents:
25785
diff
changeset
|
259 |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
260 def test_urlsplit_attributes(self): |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
261 url = "HTTP://WWW.PYTHON.ORG/doc/#frag" |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
262 p = urlparse.urlsplit(url) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
263 self.assertEqual(p.scheme, "http") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
264 self.assertEqual(p.netloc, "WWW.PYTHON.ORG") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
265 self.assertEqual(p.path, "/doc/") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
266 self.assertEqual(p.query, "") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
267 self.assertEqual(p.fragment, "frag") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
268 self.assertEqual(p.username, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
269 self.assertEqual(p.password, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
270 self.assertEqual(p.hostname, "www.python.org") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
271 self.assertEqual(p.port, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
272 # geturl() won't return exactly the original URL in this case |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
273 # since the scheme is always case-normalized |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
274 #self.assertEqual(p.geturl(), url) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
275 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
276 url = "http://User:Pass@www.python.org:080/doc/?query=yes#frag" |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
277 p = urlparse.urlsplit(url) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
278 self.assertEqual(p.scheme, "http") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
279 self.assertEqual(p.netloc, "User:Pass@www.python.org:080") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
280 self.assertEqual(p.path, "/doc/") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
281 self.assertEqual(p.query, "query=yes") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
282 self.assertEqual(p.fragment, "frag") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
283 self.assertEqual(p.username, "User") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
284 self.assertEqual(p.password, "Pass") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
285 self.assertEqual(p.hostname, "www.python.org") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
286 self.assertEqual(p.port, 80) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
287 self.assertEqual(p.geturl(), url) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
288 |
|
44483
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
289 # Addressing issue1698, which suggests Username can contain |
| 44489 | 290 # "@" characters. Though not RFC compliant, many ftp sites allow |
| 44487 | 291 # and request email addresses as usernames. |
|
44483
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
292 |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
293 url = "http://User@example.com:Pass@www.python.org:080/doc/?query=yes#frag" |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
294 p = urlparse.urlsplit(url) |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
295 self.assertEqual(p.scheme, "http") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
296 self.assertEqual(p.netloc, "User@example.com:Pass@www.python.org:080") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
297 self.assertEqual(p.path, "/doc/") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
298 self.assertEqual(p.query, "query=yes") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
299 self.assertEqual(p.fragment, "frag") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
300 self.assertEqual(p.username, "User@example.com") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
301 self.assertEqual(p.password, "Pass") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
302 self.assertEqual(p.hostname, "www.python.org") |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
303 self.assertEqual(p.port, 80) |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
304 self.assertEqual(p.geturl(), url) |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
305 |
|
2e2fa291914c
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents:
44284
diff
changeset
|
306 |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
307 def test_attributes_bad_port(self): |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
308 """Check handling of non-integer ports.""" |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
309 p = urlparse.urlsplit("http://www.example.net:foo") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
310 self.assertEqual(p.netloc, "www.example.net:foo") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
311 self.assertRaises(ValueError, lambda: p.port) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
312 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
313 p = urlparse.urlparse("http://www.example.net:foo") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
314 self.assertEqual(p.netloc, "www.example.net:foo") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
315 self.assertRaises(ValueError, lambda: p.port) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
316 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
317 def test_attributes_without_netloc(self): |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
318 # This example is straight from RFC 3261. It looks like it |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
319 # should allow the username, hostname, and port to be filled |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
320 # in, but doesn't. Since it's a URI and doesn't use the |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
321 # scheme://netloc syntax, the netloc and related attributes |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
322 # should be left empty. |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
323 uri = "sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15" |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
324 p = urlparse.urlsplit(uri) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
325 self.assertEqual(p.netloc, "") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
326 self.assertEqual(p.username, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
327 self.assertEqual(p.password, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
328 self.assertEqual(p.hostname, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
329 self.assertEqual(p.port, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
330 self.assertEqual(p.geturl(), uri) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
331 |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
332 p = urlparse.urlparse(uri) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
333 self.assertEqual(p.netloc, "") |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
334 self.assertEqual(p.username, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
335 self.assertEqual(p.password, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
336 self.assertEqual(p.hostname, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
337 self.assertEqual(p.port, None) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
338 self.assertEqual(p.geturl(), uri) |
|
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
339 |
|
44284
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
340 def test_caching(self): |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
341 # Test case for bug #1313119 |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
342 uri = "http://example.com/doc/" |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
343 unicode_uri = unicode(uri) |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
344 |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
345 urlparse.urlparse(unicode_uri) |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
346 p = urlparse.urlparse(uri) |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
347 self.assertEqual(type(p.scheme), type(uri)) |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
348 self.assertEqual(type(p.hostname), type(uri)) |
|
6ae94a2ba5df
Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
37393
diff
changeset
|
349 self.assertEqual(type(p.path), type(uri)) |
|
37393
a6bce7aebe05
Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents:
35290
diff
changeset
|
350 |
|
44510
65fe6e56d4f8
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents:
44489
diff
changeset
|
351 def test_noslash(self): |
|
65fe6e56d4f8
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents:
44489
diff
changeset
|
352 # Issue 1637: http://foo.com?query is legal |
|
65fe6e56d4f8
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents:
44489
diff
changeset
|
353 self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"), |
|
65fe6e56d4f8
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents:
44489
diff
changeset
|
354 ('http', 'example.com', '', '', 'blahblah=/foo', '')) |
|
65fe6e56d4f8
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents:
44489
diff
changeset
|
355 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
356 def test_main(): |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
357 test_support.run_unittest(UrlParseTestCase) |
|
15742
abb94609318e
Add test cases based on RFC 1808. So now we actually have a test suite
Fred Drake <fdrake@acm.org>
parents:
13832
diff
changeset
|
358 |
|
22474
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
359 if __name__ == "__main__": |
|
7aded6d0696e
added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents:
22379
diff
changeset
|
360 test_main() |
