annotate Lib/test/test_urlparse.py @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents 1489f399aba1
children 69b3a151aec5
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"
61354
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
9 RFC3986_BASE = 'http://a/b/c/d;p?q'
63021
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
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
48995
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
12 # A list of test cases. Each test case is a a two-tuple that contains
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
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 ]
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
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)
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
85 self.assertEqual(result, expect, "Error parsing %s" % repr(orig))
2b855a947f0f Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module
Facundo Batista <facundobatista@gmail.com>
parents: 48233
diff changeset
86
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
87 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
88 testcases = [
25812
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
89 ('file:///tmp/junk.txt',
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
90 ('file', '', '/tmp/junk.txt', '', '', ''),
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
91 ('file', '', '/tmp/junk.txt', '', '')),
27100
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
92 ('imap://mail.python.org/mbox1',
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
93 ('imap', 'mail.python.org', '/mbox1', '', '', ''),
8226658a63bb SF feature #618024, urlparse fails on imap://
Neal Norwitz <nnorwitz@gmail.com>
parents: 25812
diff changeset
94 ('imap', 'mail.python.org', '/mbox1', '', '')),
27121
7ec771893410 * add mms (windows media) as another scheme
Skip Montanaro <skip@pobox.com>
parents: 27100
diff changeset
95 ('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
96 ('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
97 '', '', ''),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
98 ('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
99 '', '')),
52476
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
100 ('nfs://server/path/to/file.txt',
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
101 ('nfs', 'server', '/path/to/file.txt', '', '', ''),
2ff89f0f1d19 Fix for bugs: Issue4675 and Issue4962.
Senthil Kumaran <orsenthil@gmail.com>
parents: 48995
diff changeset
102 ('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
103 ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/',
349a0fd598e0 add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents: 34379
diff changeset
104 ('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
105 '', '', ''),
349a0fd598e0 add support for svn: and svn+ssh: URL schemes to urlparse
Fred Drake <fdrake@acm.org>
parents: 34379
diff changeset
106 ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
61543
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
107 '', '')),
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
108 ('git+ssh://git@github.com/user/project.git',
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
109 ('git+ssh', 'git@github.com','/user/project.git',
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
110 '','',''),
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
111 ('git+ssh', 'git@github.com','/user/project.git',
06c6d3a67c17 Fix Issue8657 - adding git and git+ssh as know schemes.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61354
diff changeset
112 '', ''))
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
113 ]
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
114 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
115 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
116
34379
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
117 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
118 # 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
119 # 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
120 # 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
121 testcases = [
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
122 ('://www.python.org',
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
123 ('www.python.org', '', '', '', ''),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
124 ('www.python.org', '', '', '')),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
125 ('://www.python.org#abc',
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
126 ('www.python.org', '', '', '', 'abc'),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
127 ('www.python.org', '', '', 'abc')),
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
128 ('://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
129 ('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
130 ('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
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', '/', '', '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 ('://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
135 ('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
136 ('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
137 ]
287e71f44d79 Backport patch #712317: In URLs such as http://www.example.com?query=spam,
Johannes Gijsbers <jlg@dds.nl>
parents: 30674
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
145 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
146 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
147 (base, relurl, expected))
cf18ca0eea89 Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents: 25425
diff changeset
148
cf18ca0eea89 Fix for 1.33: urlsplit() should only add '//' if scheme != ''.
Guido van Rossum <guido@python.org>
parents: 25425
diff changeset
149 def test_unparse_parse(self):
60536
5680ba2dc9c2 Adding additional examples of valid urls as per RFC 3986 (for issue8339)
Senthil Kumaran <orsenthil@gmail.com>
parents: 58950
diff changeset
150 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
151 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
152 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
153
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
154 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
155 # "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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
179 # "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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
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/./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
192 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
193
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
194 # 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
195 # 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
196 #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
197 #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
198
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
199 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
200 # 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
201
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
202
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
203 self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
204 self.checkJoin(RFC2396_BASE, '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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242
48233
af7388ad3164 Issue 1432. Fixes a bug caused because of the evolution
Facundo Batista <facundobatista@gmail.com>
parents: 44510
diff changeset
243 def test_RFC3986(self):
61354
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
244 # 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
245 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
246 self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
61354
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
247 self.checkJoin(RFC3986_BASE, 'g:h','g:h')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
248 self.checkJoin(RFC3986_BASE, 'g','http://a/b/c/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
249 self.checkJoin(RFC3986_BASE, './g','http://a/b/c/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
250 self.checkJoin(RFC3986_BASE, 'g/','http://a/b/c/g/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
251 self.checkJoin(RFC3986_BASE, '/g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
252 self.checkJoin(RFC3986_BASE, '//g','http://g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
253 self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
254 self.checkJoin(RFC3986_BASE, 'g?y','http://a/b/c/g?y')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
255 self.checkJoin(RFC3986_BASE, '#s','http://a/b/c/d;p?q#s')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
256 self.checkJoin(RFC3986_BASE, 'g#s','http://a/b/c/g#s')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
257 self.checkJoin(RFC3986_BASE, 'g?y#s','http://a/b/c/g?y#s')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
258 self.checkJoin(RFC3986_BASE, ';x','http://a/b/c/;x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
259 self.checkJoin(RFC3986_BASE, 'g;x','http://a/b/c/g;x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
260 self.checkJoin(RFC3986_BASE, 'g;x?y#s','http://a/b/c/g;x?y#s')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
261 self.checkJoin(RFC3986_BASE, '','http://a/b/c/d;p?q')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
262 self.checkJoin(RFC3986_BASE, '.','http://a/b/c/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
263 self.checkJoin(RFC3986_BASE, './','http://a/b/c/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
264 self.checkJoin(RFC3986_BASE, '..','http://a/b/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
265 self.checkJoin(RFC3986_BASE, '../','http://a/b/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
266 self.checkJoin(RFC3986_BASE, '../g','http://a/b/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
267 self.checkJoin(RFC3986_BASE, '../..','http://a/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
268 self.checkJoin(RFC3986_BASE, '../../','http://a/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
269 self.checkJoin(RFC3986_BASE, '../../g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
270
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
271 #Abnormal Examples
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
272
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
273 # The 'abnormal scenarios' are incompatible with RFC2986 parsing
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
274 # Tests are here for reference.
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
275
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
276 #self.checkJoin(RFC3986_BASE, '../../../g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
277 #self.checkJoin(RFC3986_BASE, '../../../../g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
278 #self.checkJoin(RFC3986_BASE, '/./g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
279 #self.checkJoin(RFC3986_BASE, '/../g','http://a/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
280
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
281 self.checkJoin(RFC3986_BASE, 'g.','http://a/b/c/g.')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
282 self.checkJoin(RFC3986_BASE, '.g','http://a/b/c/.g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
283 self.checkJoin(RFC3986_BASE, 'g..','http://a/b/c/g..')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
284 self.checkJoin(RFC3986_BASE, '..g','http://a/b/c/..g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
285 self.checkJoin(RFC3986_BASE, './../g','http://a/b/g')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
286 self.checkJoin(RFC3986_BASE, './g/.','http://a/b/c/g/')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
287 self.checkJoin(RFC3986_BASE, 'g/./h','http://a/b/c/g/h')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
288 self.checkJoin(RFC3986_BASE, 'g/../h','http://a/b/c/h')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
289 self.checkJoin(RFC3986_BASE, 'g;x=1/./y','http://a/b/c/g;x=1/y')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
290 self.checkJoin(RFC3986_BASE, 'g;x=1/../y','http://a/b/c/y')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
291 self.checkJoin(RFC3986_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
292 self.checkJoin(RFC3986_BASE, 'g?y/../x','http://a/b/c/g?y/../x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
293 self.checkJoin(RFC3986_BASE, 'g#s/./x','http://a/b/c/g#s/./x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
294 self.checkJoin(RFC3986_BASE, 'g#s/../x','http://a/b/c/g#s/../x')
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
295 #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
5c9094792d1a Testsuite for RFC3986 based parsing scenario. Related Issue1462525.
Senthil Kumaran <orsenthil@gmail.com>
parents: 60857
diff changeset
296 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
297
63021
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
298 def test_urljoins(self):
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
299 self.checkJoin(SIMPLE_BASE, 'g:h','g:h')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
300 self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
301 self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
302 self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
303 self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
304 self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
305 self.checkJoin(SIMPLE_BASE, '/g','http://a/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
306 self.checkJoin(SIMPLE_BASE, '//g','http://g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
307 self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
308 self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
309 self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
310 self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
311 self.checkJoin(SIMPLE_BASE, './','http://a/b/c/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
312 self.checkJoin(SIMPLE_BASE, '..','http://a/b/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
313 self.checkJoin(SIMPLE_BASE, '../','http://a/b/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
314 self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
315 self.checkJoin(SIMPLE_BASE, '../..','http://a/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
316 self.checkJoin(SIMPLE_BASE, '../../g','http://a/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
317 self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
318 self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
319 self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
320 self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
321 self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
322 self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
323 self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
324 self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
325 self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
326 self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
327 self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x')
6141cb2e26e1 Merged revisions 82881 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 61543
diff changeset
328
60613
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
329 def test_RFC2732(self):
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
330 for url, hostname, port in [
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
331 ('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
332 ('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
333 ('http://[::1]:5432/foo/', '::1', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
334 ('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
335 ('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
336 ('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
337 '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
338 ('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
339 ('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
340 '::ffff:12.34.56.78', 5432),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
341 ('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
342 ('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
343 ('http://[::1]/foo/', '::1', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
344 ('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
345 ('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
346 ('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
347 '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
348 ('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
349 ('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
350 '::ffff:12.34.56.78', None),
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
351 ]:
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
352 urlparsed = urlparse.urlparse(url)
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
353 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
354
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
355 for invalid_url in [
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
356 'http://::12.34.56.78]/',
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
357 '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
358 '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
359 'http://[::1/foo/bad]/bad',
60613
7b9e328f7533 Fix issue2987: RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran <orsenthil@gmail.com>
parents: 60536
diff changeset
360 '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
361 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
362
25812
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
363 def test_urldefrag(self):
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
364 for url, defrag, frag in [
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
365 ('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
366 ('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
367 ('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
368 ('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
369 ('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
370 ('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
371 ('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
372 ('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
373 (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
374 (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
375 ]:
5d352de94415 Make sure we test urlsplit() / urlunsplit() directly, rather than
Fred Drake <fdrake@acm.org>
parents: 25785
diff changeset
376 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
377
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
378 def test_urlsplit_attributes(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
379 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
380 p = urlparse.urlsplit(url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
381 self.assertEqual(p.scheme, "http")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
382 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
383 self.assertEqual(p.path, "/doc/")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
384 self.assertEqual(p.query, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
385 self.assertEqual(p.fragment, "frag")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
386 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
387 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
388 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
389 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
390 # 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
391 # 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
392 #self.assertEqual(p.geturl(), url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
394 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
395 p = urlparse.urlsplit(url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
396 self.assertEqual(p.scheme, "http")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
397 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
398 self.assertEqual(p.path, "/doc/")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
399 self.assertEqual(p.query, "query=yes")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
400 self.assertEqual(p.fragment, "frag")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
401 self.assertEqual(p.username, "User")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
402 self.assertEqual(p.password, "Pass")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
403 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
404 self.assertEqual(p.port, 80)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
405 self.assertEqual(p.geturl(), url)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
406
44483
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
407 # Addressing issue1698, which suggests Username can contain
44489
e48b469d1d86 Fix comment typo
Andrew M. Kuchling <amk@amk.ca>
parents: 44487
diff changeset
408 # "@" characters. Though not RFC compliant, many ftp sites allow
44487
33a0ae70670f clean up a comment
Fred Drake <fdrake@acm.org>
parents: 44483
diff changeset
409 # 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
410
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423
2e2fa291914c Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
Guido van Rossum <guido@python.org>
parents: 44284
diff changeset
424
37393
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
425 def test_attributes_bad_port(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
426 """Check handling of non-integer ports."""
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
427 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
428 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
429 self.assertRaises(ValueError, lambda: p.port)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
430
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
431 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
432 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
433 self.assertRaises(ValueError, lambda: p.port)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
434
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
435 def test_attributes_without_netloc(self):
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
436 # 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
437 # 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
438 # 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
439 # 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
440 # should be left empty.
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
441 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
442 p = urlparse.urlsplit(uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
443 self.assertEqual(p.netloc, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
444 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
445 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
446 self.assertEqual(p.hostname, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
447 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
448 self.assertEqual(p.geturl(), uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
449
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
450 p = urlparse.urlparse(uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
451 self.assertEqual(p.netloc, "")
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
452 self.assertEqual(p.username, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
453 self.assertEqual(p.password, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
454 self.assertEqual(p.hostname, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
455 self.assertEqual(p.port, None)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
456 self.assertEqual(p.geturl(), uri)
a6bce7aebe05 Patch #624325: urlparse.urlparse() and urlparse.urlsplit() results
Fred Drake <fdrake@acm.org>
parents: 35290
diff changeset
457
44284
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
458 def test_caching(self):
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
459 # Test case for bug #1313119
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
460 uri = "http://example.com/doc/"
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
461 unicode_uri = unicode(uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
462
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
463 urlparse.urlparse(unicode_uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
464 p = urlparse.urlparse(uri)
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
465 self.assertEqual(type(p.scheme), type(uri))
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
466 self.assertEqual(type(p.hostname), type(uri))
6ae94a2ba5df Backport r59480.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 37393
diff changeset
467 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
468
44510
65fe6e56d4f8 Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents: 44489
diff changeset
469 def test_noslash(self):
65fe6e56d4f8 Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents: 44489
diff changeset
470 # Issue 1637: http://foo.com?query is legal
65fe6e56d4f8 Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents: 44489
diff changeset
471 self.assertEqual(urlparse.urlparse("http://example.com?blahblah=/foo"),
65fe6e56d4f8 Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents: 44489
diff changeset
472 ('http', 'example.com', '', '', 'blahblah=/foo', ''))
65fe6e56d4f8 Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Guido van Rossum <guido@python.org>
parents: 44489
diff changeset
473
58950
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
474 def test_anyscheme(self):
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
475 # Issue 7904: s3://foo.com/stuff has netloc "foo.com".
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
476 self.assertEqual(urlparse.urlparse("s3://foo.com/stuff"),
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
477 ('s3','foo.com','/stuff','','',''))
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
478 self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff"),
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
479 ('x-newscheme','foo.com','/stuff','','',''))
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
480
63714
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
481 def test_withoutscheme(self):
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
482 # Test urlparse without scheme
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
483 # 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
484 # 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
485 # 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
486 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
487 ('','','path','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
488 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
489 ('','www.python.org:80','','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
490 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
491 ('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
492
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
493 def test_portseparator(self):
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
494 # 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
495 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
496 ('','','path:80','','',''))
1489f399aba1 Fix Issue754016 - urlparse goes wrong with IP:port without scheme
Senthil Kumaran <orsenthil@gmail.com>
parents: 63021
diff changeset
497 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
498 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
499 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
500 ('http','www.python.org:80','','','',''))
58950
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
501
7da7f9bfdaac Fix for Issue7904. urlparse.urlsplit to handle schemes in the way defined by RFC3986
Senthil Kumaran <orsenthil@gmail.com>
parents: 52476
diff changeset
502
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
503 def test_main():
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
504 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
505
22474
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
506 if __name__ == "__main__":
7aded6d0696e added RFC 2396 tests from Aaron Swartz included in bug # 450225.
Skip Montanaro <skip@pobox.com>
parents: 22379
diff changeset
507 test_main()