annotate Lib/test/test_urlparse.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 988903cf24c5
children ff0426b5d75e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
61355
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
9 RFC3986_BASE = 'http://a/b/c/d;p?q'
63022
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
10 SIMPLE_BASE = 'http://a/b/c/d'
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
11
72984
86e3943d0d5b Remove duplication.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 71737
diff changeset
12 # A list of test cases. Each test case is a two-tuple that contains
48995
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
13 # 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
14
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
15 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
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 ("=", [('', '')]),
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=", [('a', '')]),
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
24 ("&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
25 ("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
26 ("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
27 ]
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
28
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
29 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
30
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
31 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
32 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
33 self.assertEqual(result, parsed)
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
34 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
35 result.params, result.query, result.fragment)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
36 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
37 # 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
38 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
39 self.assertEqual(result2, url)
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
40 self.assertEqual(result2, result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
41
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
42 # 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
43 # again to get the same result:
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
44 result3 = urlparse.urlparse(result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
45 self.assertEqual(result3.geturl(), result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
46 self.assertEqual(result3, result)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
47 self.assertEqual(result3.scheme, result.scheme)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
48 self.assertEqual(result3.netloc, result.netloc)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
49 self.assertEqual(result3.path, result.path)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
50 self.assertEqual(result3.params, result.params)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
51 self.assertEqual(result3.query, result.query)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
52 self.assertEqual(result3.fragment, result.fragment)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
53 self.assertEqual(result3.username, result.username)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
54 self.assertEqual(result3.password, result.password)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
55 self.assertEqual(result3.hostname, result.hostname)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
56 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
57
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
58 # 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
59 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
60 self.assertEqual(result, split)
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
61 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
62 result.query, result.fragment)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
63 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
64 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
65 self.assertEqual(result2, url)
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
66 self.assertEqual(result2, result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
67
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
68 # 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
69 result3 = urlparse.urlsplit(result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
70 self.assertEqual(result3.geturl(), result.geturl())
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
71 self.assertEqual(result3, result)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
72 self.assertEqual(result3.scheme, result.scheme)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
73 self.assertEqual(result3.netloc, result.netloc)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
74 self.assertEqual(result3.path, result.path)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
75 self.assertEqual(result3.query, result.query)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
76 self.assertEqual(result3.fragment, result.fragment)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
77 self.assertEqual(result3.username, result.username)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
78 self.assertEqual(result3.password, result.password)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
79 self.assertEqual(result3.hostname, result.hostname)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
80 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
81
48995
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
82 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
83 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
84 result = urlparse.parse_qsl(orig, keep_blank_values=True)
71472
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
85 self.assertEqual(result, expect, "Error parsing %r" % orig)
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
86 expect_without_blanks = [v for v in expect if len(v[1])]
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
87 result = urlparse.parse_qsl(orig, keep_blank_values=False)
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
88 self.assertEqual(result, expect_without_blanks,
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
89 "Error parsing %r" % orig)
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
90
48995
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
91
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
92 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
93 testcases = [
25812
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
94 ('file:///tmp/junk.txt',
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
95 ('file', '', '/tmp/junk.txt', '', '', ''),
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
96 ('file', '', '/tmp/junk.txt', '', '')),
27100
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
97 ('imap://mail.python.org/mbox1',
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
98 ('imap', 'mail.python.org', '/mbox1', '', '', ''),
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
99 ('imap', 'mail.python.org', '/mbox1', '', '')),
27121
7ec771893410 * add mms (windows media) as another scheme
Skip Montanaro <skip@pobox.com>
parents: 27100
diff changeset
100 ('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
101 ('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
102 '', '', ''),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
103 ('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
104 '', '')),
52476
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
105 ('nfs://server/path/to/file.txt',
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
106 ('nfs', 'server', '/path/to/file.txt', '', '', ''),
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
107 ('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
108 ('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
109 ('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
110 '', '', ''),
349a0fd598e0 add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents: 34379
diff changeset
111 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
61544
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
112 '', '')),
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
113 ('git+ssh://git@github.com/user/project.git',
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
114 ('git+ssh', 'git@github.com','/user/project.git',
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
115 '','',''),
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
116 ('git+ssh', 'git@github.com','/user/project.git',
2c29cd5668c7 Merged revisions 81130 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61355
diff changeset
117 '', ''))
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
118 ]
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
119 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
120 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
121
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
122 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
123 # 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
124 # 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
125 # 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
126 testcases = [
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',
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
128 ('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
129 ('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
130 ('://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
131 ('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
132 ('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
133 ('://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
134 ('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
135 ('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
136 ('://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
137 ('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
138 ('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
139 ('://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
140 ('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
141 ('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
142 ]
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
143 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
144 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
145 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
146 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
147 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
148 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
149
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
150 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
151 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
152 (base, relurl, expected))
cf18ca0eea89 Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents: 25425
diff changeset
153
cf18ca0eea89 Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents: 25425
diff changeset
154 def test_unparse_parse(self):
60537
bae37903f797 Merged revisions 79988 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 58951
diff changeset
155 for u in ['Python', './Python','x-newscheme://foo.com/stuff','x://y','x:/y','x:/','/',]:
25812
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
156 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
157 self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u)
22379
55512fe1d6f1 amk's fix attached to
Michael W. Hudson <mwh@python.net>
parents: 15742
diff changeset
158
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
159 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
160 # "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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
184 # "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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
199 # 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
200 # 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
201 #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
202 #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
203
69365
7a693e283c68 Issue #11467: Fix urlparse behavior when handling urls which contains scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 68256
diff changeset
204 def test_RFC2368(self):
7a693e283c68 Issue #11467: Fix urlparse behavior when handling urls which contains scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 68256
diff changeset
205 # Issue 11467: path that starts with a number is not parsed correctly
7a693e283c68 Issue #11467: Fix urlparse behavior when handling urls which contains scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 68256
diff changeset
206 self.assertEqual(urlparse.urlparse('mailto:1337@example.org'),
7a693e283c68 Issue #11467: Fix urlparse behavior when handling urls which contains scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 68256
diff changeset
207 ('mailto', '', '1337@example.org', '', '', ''))
7a693e283c68 Issue #11467: Fix urlparse behavior when handling urls which contains scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 68256
diff changeset
208
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
209 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
210 # 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250
48233
af7388ad3164 Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents: 44510
diff changeset
251 def test_RFC3986(self):
61355
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
252 # Test cases from RFC3986
48233
af7388ad3164 Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents: 44510
diff changeset
253 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
254 self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
61355
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
255 self.checkJoin(RFC3986_BASE, 'g:h','g:h')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
256 self.checkJoin(RFC3986_BASE, 'g','http://a/b/c/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
257 self.checkJoin(RFC3986_BASE, './g','http://a/b/c/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
258 self.checkJoin(RFC3986_BASE, 'g/','http://a/b/c/g/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
259 self.checkJoin(RFC3986_BASE, '/g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
260 self.checkJoin(RFC3986_BASE, '//g','http://g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
261 self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
262 self.checkJoin(RFC3986_BASE, 'g?y','http://a/b/c/g?y')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
263 self.checkJoin(RFC3986_BASE, '#s','http://a/b/c/d;p?q#s')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
264 self.checkJoin(RFC3986_BASE, 'g#s','http://a/b/c/g#s')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
265 self.checkJoin(RFC3986_BASE, 'g?y#s','http://a/b/c/g?y#s')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
266 self.checkJoin(RFC3986_BASE, ';x','http://a/b/c/;x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
267 self.checkJoin(RFC3986_BASE, 'g;x','http://a/b/c/g;x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
268 self.checkJoin(RFC3986_BASE, 'g;x?y#s','http://a/b/c/g;x?y#s')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
269 self.checkJoin(RFC3986_BASE, '','http://a/b/c/d;p?q')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
270 self.checkJoin(RFC3986_BASE, '.','http://a/b/c/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
271 self.checkJoin(RFC3986_BASE, './','http://a/b/c/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
272 self.checkJoin(RFC3986_BASE, '..','http://a/b/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
273 self.checkJoin(RFC3986_BASE, '../','http://a/b/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
274 self.checkJoin(RFC3986_BASE, '../g','http://a/b/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
275 self.checkJoin(RFC3986_BASE, '../..','http://a/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
276 self.checkJoin(RFC3986_BASE, '../../','http://a/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
277 self.checkJoin(RFC3986_BASE, '../../g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
278
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
279 #Abnormal Examples
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
280
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
281 # The 'abnormal scenarios' are incompatible with RFC2986 parsing
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
282 # Tests are here for reference.
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
283
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
284 #self.checkJoin(RFC3986_BASE, '../../../g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
285 #self.checkJoin(RFC3986_BASE, '../../../../g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
286 #self.checkJoin(RFC3986_BASE, '/./g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
287 #self.checkJoin(RFC3986_BASE, '/../g','http://a/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
288
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
289 self.checkJoin(RFC3986_BASE, 'g.','http://a/b/c/g.')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
290 self.checkJoin(RFC3986_BASE, '.g','http://a/b/c/.g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
291 self.checkJoin(RFC3986_BASE, 'g..','http://a/b/c/g..')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
292 self.checkJoin(RFC3986_BASE, '..g','http://a/b/c/..g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
293 self.checkJoin(RFC3986_BASE, './../g','http://a/b/g')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
294 self.checkJoin(RFC3986_BASE, './g/.','http://a/b/c/g/')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
295 self.checkJoin(RFC3986_BASE, 'g/./h','http://a/b/c/g/h')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
296 self.checkJoin(RFC3986_BASE, 'g/../h','http://a/b/c/h')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
297 self.checkJoin(RFC3986_BASE, 'g;x=1/./y','http://a/b/c/g;x=1/y')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
298 self.checkJoin(RFC3986_BASE, 'g;x=1/../y','http://a/b/c/y')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
299 self.checkJoin(RFC3986_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
300 self.checkJoin(RFC3986_BASE, 'g?y/../x','http://a/b/c/g?y/../x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
301 self.checkJoin(RFC3986_BASE, 'g#s/./x','http://a/b/c/g#s/./x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
302 self.checkJoin(RFC3986_BASE, 'g#s/../x','http://a/b/c/g#s/../x')
490d1c2036e9 Merged revisions 80908 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 60537
diff changeset
303 #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
61354
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
304 self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') # relaxed parser
48233
af7388ad3164 Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents: 44510
diff changeset
305
66984
69b3a151aec5 Merged revisions 87329 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 63714
diff changeset
306 # Test for issue9721
69b3a151aec5 Merged revisions 87329 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 63714
diff changeset
307 self.checkJoin('http://a/b/c/de', ';x','http://a/b/c/;x')
48233
af7388ad3164 Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents: 44510
diff changeset
308
63022
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
309 def test_urljoins(self):
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
310 self.checkJoin(SIMPLE_BASE, 'g:h','g:h')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
311 self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
312 self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
313 self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
314 self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
315 self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
316 self.checkJoin(SIMPLE_BASE, '/g','http://a/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
317 self.checkJoin(SIMPLE_BASE, '//g','http://g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
318 self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
319 self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
320 self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
321 self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
322 self.checkJoin(SIMPLE_BASE, './','http://a/b/c/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
323 self.checkJoin(SIMPLE_BASE, '..','http://a/b/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
324 self.checkJoin(SIMPLE_BASE, '../','http://a/b/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
325 self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
326 self.checkJoin(SIMPLE_BASE, '../..','http://a/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
327 self.checkJoin(SIMPLE_BASE, '../../g','http://a/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
328 self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
329 self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
330 self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
331 self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
332 self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
333 self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
334 self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
335 self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
336 self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
337 self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y')
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
338 self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x')
71472
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
339 self.checkJoin('http:///', '..','http:///')
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
340 self.checkJoin('', 'http://a/b/c/g?y/./x','http://a/b/c/g?y/./x')
ed79da800b4a merge from 3.2 - Fix closes issue12581 - Increase the urllib.parse test coverage (cases applicable to 2.7). Patch by Petter Haggholm.
Senthil Kumaran <senthil@uthcode.com>
parents: 69365
diff changeset
341 self.checkJoin('', 'http://a/./g', 'http://a/./g')
71729
5278aa2d9d9a Fix closes issue12683 - urljoin to work with relative join of svn scheme.
Senthil Kumaran <senthil@uthcode.com>
parents: 71472
diff changeset
342 self.checkJoin('svn://pathtorepo/dir1','dir2','svn://pathtorepo/dir2')
71737
5a0726fcb18a add svn+ssh testcase for urljoin.
Senthil Kumaran <senthil@uthcode.com>
parents: 71729
diff changeset
343 self.checkJoin('svn+ssh://pathtorepo/dir1','dir2','svn+ssh://pathtorepo/dir2')
63022
0f2431401021 Merged revisions 82883 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61544
diff changeset
344
60613
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
345 def test_RFC2732(self):
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
346 for url, hostname, port in [
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
347 ('http://Test.python.org:5432/foo/', 'test.python.org', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
348 ('http://12.34.56.78:5432/foo/', '12.34.56.78', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
349 ('http://[::1]:5432/foo/', '::1', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
350 ('http://[dead:beef::1]:5432/foo/', 'dead:beef::1', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
351 ('http://[dead:beef::]:5432/foo/', 'dead:beef::', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
352 ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:5432/foo/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
353 'dead:beef:cafe:5417:affe:8fa3:deaf:feed', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
354 ('http://[::12.34.56.78]:5432/foo/', '::12.34.56.78', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
355 ('http://[::ffff:12.34.56.78]:5432/foo/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
356 '::ffff:12.34.56.78', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
357 ('http://Test.python.org/foo/', 'test.python.org', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
358 ('http://12.34.56.78/foo/', '12.34.56.78', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
359 ('http://[::1]/foo/', '::1', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
360 ('http://[dead:beef::1]/foo/', 'dead:beef::1', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
361 ('http://[dead:beef::]/foo/', 'dead:beef::', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
362 ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
363 'dead:beef:cafe:5417:affe:8fa3:deaf:feed', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
364 ('http://[::12.34.56.78]/foo/', '::12.34.56.78', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
365 ('http://[::ffff:12.34.56.78]/foo/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
366 '::ffff:12.34.56.78', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
367 ]:
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
368 urlparsed = urlparse.urlparse(url)
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
369 self.assertEqual((urlparsed.hostname, urlparsed.port) , (hostname, port))
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
370
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
371 for invalid_url in [
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
372 'http://::12.34.56.78]/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
373 'http://[::1/foo/',
60857
9dc864ef6425 Changed tests to only urlparse one, which was enough, addressed Ezio's comment
Senthil Kumaran <orsenthil@gmail.com>
parents: 60783
diff changeset
374 'ftp://[::1/foo/bad]/bad',
60783
7c8eb2ba9129 Issue2987 - Added additional Invalid URL and changed the Invalid URL checking code for better.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60613
diff changeset
375 'http://[::1/foo/bad]/bad',
60613
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
376 'http://[::ffff:12.34.56.78']:
60857
9dc864ef6425 Changed tests to only urlparse one, which was enough, addressed Ezio's comment
Senthil Kumaran <orsenthil@gmail.com>
parents: 60783
diff changeset
377 self.assertRaises(ValueError, urlparse.urlparse, invalid_url)
60613
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
378
25812
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
379 def test_urldefrag(self):
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
380 for url, defrag, frag in [
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
381 ('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
382 ('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
383 ('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
384 ('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
385 ('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
386 ('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
387 ('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
388 ('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
389 (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
390 (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
391 ]:
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
392 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
393
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
394 def test_urlsplit_attributes(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
395 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
396 p = urlparse.urlsplit(url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
397 self.assertEqual(p.scheme, "http")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
398 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
399 self.assertEqual(p.path, "/doc/")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
400 self.assertEqual(p.query, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
401 self.assertEqual(p.fragment, "frag")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
402 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
403 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
404 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
405 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
406 # 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
407 # 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
408 #self.assertEqual(p.geturl(), url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
409
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
410 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
411 p = urlparse.urlsplit(url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
412 self.assertEqual(p.scheme, "http")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
413 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
414 self.assertEqual(p.path, "/doc/")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
415 self.assertEqual(p.query, "query=yes")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
416 self.assertEqual(p.fragment, "frag")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
417 self.assertEqual(p.username, "User")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
418 self.assertEqual(p.password, "Pass")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
419 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
420 self.assertEqual(p.port, 80)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
421 self.assertEqual(p.geturl(), url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
422
44483
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
423 # Addressing issue1698, which suggests Username can contain
44489
e48b469d1d86 Fix comment typo
Andrew M. Kuchling <amk@amk.ca>
parents: 44487
diff changeset
424 # "@" characters. Though not RFC compliant, many ftp sites allow
44487
33a0ae70670f clean up a comment
Fred Drake <fdrake@acm.org>
parents: 44483
diff changeset
425 # 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
426
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439
77119
988903cf24c5 Issue #14036: return None when port in urlparse cross 65535
Senthil Kumaran <senthil@uthcode.com>
parents: 77051
diff changeset
440 # Verify an illegal port of value greater than 65535 is set as None
988903cf24c5 Issue #14036: return None when port in urlparse cross 65535
Senthil Kumaran <senthil@uthcode.com>
parents: 77051
diff changeset
441 url = "http://www.python.org:65536"
988903cf24c5 Issue #14036: return None when port in urlparse cross 65535
Senthil Kumaran <senthil@uthcode.com>
parents: 77051
diff changeset
442 p = urlparse.urlsplit(url)
988903cf24c5 Issue #14036: return None when port in urlparse cross 65535
Senthil Kumaran <senthil@uthcode.com>
parents: 77051
diff changeset
443 self.assertEqual(p.port, None)
988903cf24c5 Issue #14036: return None when port in urlparse cross 65535
Senthil Kumaran <senthil@uthcode.com>
parents: 77051
diff changeset
444
77051
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
445 def test_issue14072(self):
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
446 p1 = urlparse.urlsplit('tel:+31-641044153')
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
447 self.assertEqual(p1.scheme, 'tel')
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
448 self.assertEqual(p1.path, '+31-641044153')
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
449 p2 = urlparse.urlsplit('tel:+31641044153')
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
450 self.assertEqual(p2.scheme, 'tel')
ff0fd7b26219 #14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 77044
diff changeset
451 self.assertEqual(p2.path, '+31641044153')
44483
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
452
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
453 def test_attributes_bad_port(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
454 """Check handling of non-integer ports."""
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
455 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
456 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
457 self.assertRaises(ValueError, lambda: p.port)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
458
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
459 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
460 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
461 self.assertRaises(ValueError, lambda: p.port)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
462
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
463 def test_attributes_without_netloc(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
464 # 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
465 # 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
466 # 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
467 # 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
468 # should be left empty.
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
469 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
470 p = urlparse.urlsplit(uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
471 self.assertEqual(p.netloc, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
472 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
473 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
474 self.assertEqual(p.hostname, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
475 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
476 self.assertEqual(p.geturl(), uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
477
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
478 p = urlparse.urlparse(uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
479 self.assertEqual(p.netloc, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
480 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
481 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
482 self.assertEqual(p.hostname, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
483 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
484 self.assertEqual(p.geturl(), uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
485
44284
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
486 def test_caching(self):
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
487 # Test case for bug #1313119
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
488 uri = "http://example.com/doc/"
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
489 unicode_uri = unicode(uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
490
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
491 urlparse.urlparse(unicode_uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
492 p = urlparse.urlparse(uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
493 self.assertEqual(type(p.scheme), type(uri))
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
494 self.assertEqual(type(p.hostname), type(uri))
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
495 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
496
44512
281c9479142a Backport r59758.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
497 def test_noslash(self):
281c9479142a Backport r59758.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
498 # Issue 1637: http://foo.com?query is legal
281c9479142a Backport r59758.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
499 self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"),
281c9479142a Backport r59758.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
500 ('http', 'example.com', '', '', 'blahblah=/foo', ''))
281c9479142a Backport r59758.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
501
58951
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
502 def test_anyscheme(self):
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
503 # Issue 7904: s3://foo.com/stuff has netloc "foo.com".
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
504 self.assertEqual(urlparse.urlparse("s3://foo.com/stuff"),
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
505 ('s3','foo.com','/stuff','','',''))
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
506 self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff"),
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
507 ('x-newscheme','foo.com','/stuff','','',''))
77044
79e6ff3d9afd Issue9374 - Generic parsing of query and fragment portion of urls for any scheme
Senthil Kumaran <senthil@uthcode.com>
parents: 72984
diff changeset
508 self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff?query#fragment"),
79e6ff3d9afd Issue9374 - Generic parsing of query and fragment portion of urls for any scheme
Senthil Kumaran <senthil@uthcode.com>
parents: 72984
diff changeset
509 ('x-newscheme','foo.com','/stuff','','query','fragment'))
79e6ff3d9afd Issue9374 - Generic parsing of query and fragment portion of urls for any scheme
Senthil Kumaran <senthil@uthcode.com>
parents: 72984
diff changeset
510 self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff?query"),
79e6ff3d9afd Issue9374 - Generic parsing of query and fragment portion of urls for any scheme
Senthil Kumaran <senthil@uthcode.com>
parents: 72984
diff changeset
511 ('x-newscheme','foo.com','/stuff','','query',''))
58951
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
512
63714
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
513 def test_withoutscheme(self):
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
514 # Test urlparse without scheme
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
515 # Issue 754016: urlparse goes wrong with IP:port without scheme
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
516 # RFC 1808 specifies that netloc should start with //, urlparse expects
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
517 # the same, otherwise it classifies the portion of url as path.
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
518 self.assertEqual(urlparse.urlparse("path"),
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
519 ('','','path','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
520 self.assertEqual(urlparse.urlparse("//www.python.org:80"),
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
521 ('','www.python.org:80','','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
522 self.assertEqual(urlparse.urlparse("http://www.python.org:80"),
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
523 ('http','www.python.org:80','','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
524
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
525 def test_portseparator(self):
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
526 # Issue 754016 makes changes for port separator ':' from scheme separator
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
527 self.assertEqual(urlparse.urlparse("path:80"),
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
528 ('','','path:80','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
529 self.assertEqual(urlparse.urlparse("http:"),('http','','','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
530 self.assertEqual(urlparse.urlparse("https:"),('https','','','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
531 self.assertEqual(urlparse.urlparse("http://www.python.org:80"),
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
532 ('http','www.python.org:80','','','',''))
58951
c485e55aaf96 Merged revisions 78234 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
533
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
534 def test_main():
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
535 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
536
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
537 if __name__ == "__main__":
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
538 test_main()