cpython: Lib/test/test_urllib.py annotate (original) (raw)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1 """Regresssion tests for urllib"""
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
3 import urllib.parse
4 import urllib.request
5 import urllib.error
6 import http.client
f31e32a2013cPatch for issue 2848, mostly by Humberto Diogenes, with a couple of
Barry Warsaw barry@python.org
7 import email.message
8 import io
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
9 import unittest
10 from test import support
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
11 import os
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
12 import sys
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
13 import tempfile
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
15 def hexescape(char):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
16 """Escape char as RFC 2396 specifies"""
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
17 hex_repr = hex(ord(char))[2:].upper()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
18 if len(hex_repr) == 1:
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
19 hex_repr = "0%s" % hex_repr
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
20 return "%" + hex_repr
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
22 # Shortcut for testing FancyURLopener
23 _urlopener = None
24 def urlopen(url, data=None, proxies=None):
25 """urlopen(url [, data]) -> open file-like object"""
26 global _urlopener
27 if proxies is not None:
28 opener = urllib.request.FancyURLopener(proxies=proxies)
29 elif not _urlopener:
30 opener = urllib.request.FancyURLopener()
31 _urlopener = opener
32 else:
33 opener = _urlopener
34 if data is None:
35 return opener.open(url)
36 else:
37 return opener.open(url, data)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
39 class urlopen_FileTests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
40 """Test urlopen() opening a temporary file.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
42 Try to test as much functionality as possible so as to cut down on reliance
43 on connecting to the Net for testing.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
45 """
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
47 def setUp(self):
48 # Create a temp file to use for testing
49 self.text = bytes("test_urllib: %s\n" % self.__class__.__name__,
50 "ascii")
51 f = open(support.TESTFN, 'wb')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
52 try:
53 f.write(self.text)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
54 finally:
55 f.close()
56 self.pathname = support.TESTFN
57 self.returned_obj = urlopen("file:%s" % self.pathname)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
59 def tearDown(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
60 """Shut down the open object"""
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
61 self.returned_obj.close()
62 os.remove(support.TESTFN)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64 def test_interface(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
65 # Make sure object returned by urlopen() has the specified methods
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
66 for attr in ("read", "readline", "readlines", "fileno",
67 "close", "info", "geturl", "getcode", "__iter__"):
68 self.assertTrue(hasattr(self.returned_obj, attr),
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
69 "object returned by urlopen() lacks %s attribute" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
70 attr)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
72 def test_read(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
73 self.assertEqual(self.text, self.returned_obj.read())
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
75 def test_readline(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
76 self.assertEqual(self.text, self.returned_obj.readline())
77 self.assertEqual(b'', self.returned_obj.readline(),
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
78 "calling readline() after exhausting the file did not"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
79 " return an empty string")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
81 def test_readlines(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
82 lines_list = self.returned_obj.readlines()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
83 self.assertEqual(len(lines_list), 1,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
84 "readlines() returned the wrong number of lines")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
85 self.assertEqual(lines_list[0], self.text,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
86 "readlines() returned improper text")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
88 def test_fileno(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
89 file_num = self.returned_obj.fileno()
90 self.assertIsInstance(file_num, int, "fileno() did not return an int")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
91 self.assertEqual(os.read(file_num, len(self.text)), self.text,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
92 "Reading on the file descriptor returned by fileno() "
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
93 "did not return the expected text")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
95 def test_close(self):
edc3d3b07435Closes issue11563 - test_urllibnet ResourceWarning. Patch by Jeff McNeil.
Senthil Kumaran orsenthil@gmail.com
96 # Test close() by calling it here and then having it be called again
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
97 # by the tearDown() method for the test
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
98 self.returned_obj.close()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
100 def test_info(self):
101 self.assertIsInstance(self.returned_obj.info(), email.message.Message)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
103 def test_geturl(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
104 self.assertEqual(self.returned_obj.geturl(), self.pathname)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
106 def test_getcode(self):
656fe6292f9fMerged revisions 83212,83829,83833,83838-83839,83878,84019,84025,84028,84032,84036 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
107 self.assertIsNone(self.returned_obj.getcode())
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
109 def test_iter(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
110 # Test iterator
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
111 # Don't need to count number of iterations since test would fail the
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
112 # instant it returned anything beyond the first line from the
c0a68b948f5dIssue #4608: urllib.request.urlopen does not return an iterable object
Raymond Hettinger python@rcn.com
113 # comparison.
c0a68b948f5dIssue #4608: urllib.request.urlopen does not return an iterable object
Raymond Hettinger python@rcn.com
114 # Use the iterator in the usual implicit way to test for ticket #4608.
c0a68b948f5dIssue #4608: urllib.request.urlopen does not return an iterable object
Raymond Hettinger python@rcn.com
115 for line in self.returned_obj:
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
116 self.assertEqual(line, self.text)
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
118 class ProxyTests(unittest.TestCase):
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
120 def setUp(self):
121 # Records changes to env vars
122 self.env = support.EnvironmentVarGuard()
89a9dd8c628dMerged revisions 77209,77229,77359-77360,77371 via svnmerge from
Benjamin Peterson benjamin@python.org
123 # Delete all proxy related env vars
124 for k in list(os.environ):
125 if 'proxy' in k.lower():
89a9dd8c628dMerged revisions 77209,77229,77359-77360,77371 via svnmerge from
Benjamin Peterson benjamin@python.org
126 self.env.unset(k)
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
128 def tearDown(self):
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
129 # Restore all proxy related env vars
130 self.env.__exit__()
131 del self.env
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
133 def test_getproxies_environment_keep_no_proxies(self):
134 self.env.set('NO_PROXY', 'localhost')
135 proxies = urllib.request.getproxies_environment()
136 # getproxies_environment use lowered case truncated (no '_proxy') keys
656fe6292f9fMerged revisions 83212,83829,83833,83838-83839,83878,84019,84025,84028,84032,84036 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
137 self.assertEqual('localhost', proxies['no'])
1d4bd059a9b6Fix closes issue12698 - make the no_proxy environment variable handling a bit lenient (accomodate spaces in between the items)
Senthil Kumaran senthil@uthcode.com
138 # List of no_proxies with space.
1d4bd059a9b6Fix closes issue12698 - make the no_proxy environment variable handling a bit lenient (accomodate spaces in between the items)
Senthil Kumaran senthil@uthcode.com
139 self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com')
1d4bd059a9b6Fix closes issue12698 - make the no_proxy environment variable handling a bit lenient (accomodate spaces in between the items)
Senthil Kumaran senthil@uthcode.com
140 self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com'))
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
142 class urlopen_HttpTests(unittest.TestCase):
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
143 """Test urlopen() opening a fake http connection."""
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
145 def fakehttp(self, fakedata):
146 class FakeSocket(io.BytesIO):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
147 io_refs = 1
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
148 def sendall(self, str): pass
149 def makefile(self, *args, **kwds):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
150 self.io_refs += 1
151 return self
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
152 def read(self, amt=None):
153 if self.closed: return b""
154 return io.BytesIO.read(self, amt)
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
155 def readline(self, length=None):
156 if self.closed: return b""
157 return io.BytesIO.readline(self, length)
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
158 def close(self):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
159 self.io_refs -= 1
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
160 if self.io_refs == 0:
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
161 io.BytesIO.close(self)
162 class FakeHTTPConnection(http.client.HTTPConnection):
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
163 def connect(self):
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
164 self.sock = FakeSocket(fakedata)
165 self._connection_class = http.client.HTTPConnection
166 http.client.HTTPConnection = FakeHTTPConnection
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
168 def unfakehttp(self):
169 http.client.HTTPConnection = self._connection_class
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
171 def check_read(self, ver):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
172 self.fakehttp(b"HTTP/" + ver + b" 200 OK\r\n\r\nHello!")
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
173 try:
174 fp = urlopen("http://python.org/")
175 self.assertEqual(fp.readline(), b"Hello!")
176 self.assertEqual(fp.readline(), b"")
177 self.assertEqual(fp.geturl(), 'http://python.org/')
178 self.assertEqual(fp.getcode(), 200)
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
179 finally:
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
180 self.unfakehttp()
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
182 def test_url_fragment(self):
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
183 # Issue #11703: geturl() omits fragments in the original URL.
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
184 url = 'http://docs.python.org/library/urllib.html#OK'
185 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
186 try:
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
187 fp = urllib.request.urlopen(url)
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
188 self.assertEqual(fp.geturl(), url)
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
189 finally:
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
190 self.unfakehttp()
3f240a1cd245Fix Issue11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
Senthil Kumaran orsenthil@gmail.com
edc3d3b07435Closes issue11563 - test_urllibnet ResourceWarning. Patch by Jeff McNeil.
Senthil Kumaran orsenthil@gmail.com
192 def test_willclose(self):
edc3d3b07435Closes issue11563 - test_urllibnet ResourceWarning. Patch by Jeff McNeil.
Senthil Kumaran orsenthil@gmail.com
193 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
5c83a375a23eCall unfakehttp in order to close connection while opening the connection through a fakehttp object.
Senthil Kumaran orsenthil@gmail.com
194 try:
5c83a375a23eCall unfakehttp in order to close connection while opening the connection through a fakehttp object.
Senthil Kumaran orsenthil@gmail.com
195 resp = urlopen("http://www.python.org")
5c83a375a23eCall unfakehttp in order to close connection while opening the connection through a fakehttp object.
Senthil Kumaran orsenthil@gmail.com
196 self.assertTrue(resp.fp.will_close)
5c83a375a23eCall unfakehttp in order to close connection while opening the connection through a fakehttp object.
Senthil Kumaran orsenthil@gmail.com
197 finally:
5c83a375a23eCall unfakehttp in order to close connection while opening the connection through a fakehttp object.
Senthil Kumaran orsenthil@gmail.com
198 self.unfakehttp()
edc3d3b07435Closes issue11563 - test_urllibnet ResourceWarning. Patch by Jeff McNeil.
Senthil Kumaran orsenthil@gmail.com
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
200 def test_read_0_9(self):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
201 # "0.9" response accepted (but not "simple responses" without
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
202 # a status line)
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
203 self.check_read(b"0.9")
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
205 def test_read_1_0(self):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
206 self.check_read(b"1.0")
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
208 def test_read_1_1(self):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
209 self.check_read(b"1.1")
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
211 def test_read_bogus(self):
212 # urlopen() should raise IOError for many error codes.
213 self.fakehttp(b'''HTTP/1.1 401 Authentication Required
214 Date: Wed, 02 Jan 2008 03:03:54 GMT
215 Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
216 Connection: close
217 Content-Type: text/html; charset=iso-8859-1
218 ''')
219 try:
220 self.assertRaises(IOError, urlopen, "http://python.org/")
221 finally:
222 self.unfakehttp()
224 def test_invalid_redirect(self):
225 # urlopen() should raise IOError for many error codes.
226 self.fakehttp(b'''HTTP/1.1 302 Found
227 Date: Wed, 02 Jan 2008 03:03:54 GMT
228 Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
229 Location: file://guidocomputer.athome.com:/python/license
230 Connection: close
231 Content-Type: text/html; charset=iso-8859-1
232 ''')
233 try:
234 self.assertRaises(urllib.error.HTTPError, urlopen,
236 finally:
237 self.unfakehttp()
239 def test_empty_socket(self):
240 # urlopen() raises IOError if the underlying socket does not send any
241 # data. (#1680230)
242 self.fakehttp(b'')
243 try:
244 self.assertRaises(IOError, urlopen, "http://something")
245 finally:
246 self.unfakehttp()
248 def test_userpass_inurl(self):
b6d3fe70802fIssue #10711: Remove HTTP 0.9 support from http.client. The `strict`
Antoine Pitrou solipsis@pitrou.net
249 self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
250 try:
251 fp = urlopen("http://user:pass@python.org/")
252 self.assertEqual(fp.readline(), b"Hello!")
253 self.assertEqual(fp.readline(), b"")
254 self.assertEqual(fp.geturl(), 'http://user:pass@python.org/')
255 self.assertEqual(fp.getcode(), 200)
256 finally:
257 self.unfakehttp()
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
259 class urlretrieve_FileTests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
260 """Test urllib.urlretrieve() on local files"""
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
262 def setUp(self):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
263 # Create a list of temporary files. Each item in the list is a file
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
264 # name (absolute path or relative to the current working directory).
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
265 # All files in this list will be deleted in the tearDown method. Note,
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
266 # this only helps to makes sure temporary files get deleted, but it
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
267 # does nothing about trying to close files that may still be open. It
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
268 # is the responsibility of the developer to properly close files even
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
269 # when exceptional conditions occur.
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
270 self.tempFiles = []
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
272 # Create a temporary file.
273 self.registerFileForCleanUp(support.TESTFN)
274 self.text = b'testing urllib.urlretrieve'
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
275 try:
276 FILE = open(support.TESTFN, 'wb')
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
277 FILE.write(self.text)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
278 FILE.close()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
279 finally:
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
280 try: FILE.close()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
281 except: pass
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
283 def tearDown(self):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
284 # Delete the temporary files.
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
285 for each in self.tempFiles:
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
286 try: os.remove(each)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
287 except: pass
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
289 def constructLocalFileUrl(self, filePath):
7608532f933aIssue #9425: skip tests if a filename is not encodable
Victor Stinner victor.stinner@haypocalc.com
290 filePath = os.path.abspath(filePath)
7608532f933aIssue #9425: skip tests if a filename is not encodable
Victor Stinner victor.stinner@haypocalc.com
291 try:
292 filePath.encode("utf-8")
7608532f933aIssue #9425: skip tests if a filename is not encodable
Victor Stinner victor.stinner@haypocalc.com
293 except UnicodeEncodeError:
7608532f933aIssue #9425: skip tests if a filename is not encodable
Victor Stinner victor.stinner@haypocalc.com
294 raise unittest.SkipTest("filePath is not encodable to utf8")
7608532f933aIssue #9425: skip tests if a filename is not encodable
Victor Stinner victor.stinner@haypocalc.com
295 return "file://%s" % urllib.request.pathname2url(filePath)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
297 def createNewTempFile(self, data=b""):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
298 """Creates a new temporary file containing the specified data,
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
299 registers the file for deletion during the test fixture tear down, and
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
300 returns the absolute path of the file."""
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
302 newFd, newFilePath = tempfile.mkstemp()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
303 try:
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
304 self.registerFileForCleanUp(newFilePath)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
305 newFile = os.fdopen(newFd, "wb")
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
306 newFile.write(data)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
307 newFile.close()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
308 finally:
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
309 try: newFile.close()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
310 except: pass
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
311 return newFilePath
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
313 def registerFileForCleanUp(self, fileName):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
314 self.tempFiles.append(fileName)
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
316 def test_basic(self):
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
317 # Make sure that a local file just gets its own location returned and
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
318 # a headers value is returned.
319 result = urllib.request.urlretrieve("file:%s" % support.TESTFN)
320 self.assertEqual(result[0], support.TESTFN)
321 self.assertIsInstance(result[1], email.message.Message,
322 "did not get a email.message.Message instance "
323 "as second returned value")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
325 def test_copy(self):
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
326 # Test that setting the filename argument works.
327 second_temp = "%s.2" % support.TESTFN
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
328 self.registerFileForCleanUp(second_temp)
329 result = urllib.request.urlretrieve(self.constructLocalFileUrl(
330 support.TESTFN), second_temp)
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
331 self.assertEqual(second_temp, result[0])
332 self.assertTrue(os.path.exists(second_temp), "copy of the file was not "
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
333 "made")
dceea41f4a6dAnna Ravenscroft identified many occurrences of "file" used to open a file
Alex Martelli aleaxit@gmail.com
334 FILE = open(second_temp, 'rb')
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
335 try:
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
336 text = FILE.read()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
337 FILE.close()
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
338 finally:
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
339 try: FILE.close()
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
340 except: pass
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
341 self.assertEqual(self.text, text)
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
343 def test_reporthook(self):
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
344 # Make sure that the reporthook works.
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
345 def hooktester(count, block_size, total_size, count_holder=[0]):
346 self.assertIsInstance(count, int)
347 self.assertIsInstance(block_size, int)
348 self.assertIsInstance(total_size, int)
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
349 self.assertEqual(count, count_holder[0])
9eb5be937990Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
Brett Cannon bcannon@gmail.com
350 count_holder[0] = count_holder[0] + 1
351 second_temp = "%s.2" % support.TESTFN
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
352 self.registerFileForCleanUp(second_temp)
353 urllib.request.urlretrieve(
354 self.constructLocalFileUrl(support.TESTFN),
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
355 second_temp, hooktester)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
357 def test_reporthook_0_bytes(self):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
358 # Test on zero length file. Should call reporthook only 1 time.
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
359 report = []
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
360 def hooktester(count, block_size, total_size, _report=report):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
361 _report.append((count, block_size, total_size))
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
362 srcFileName = self.createNewTempFile()
363 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
364 support.TESTFN, hooktester)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
365 self.assertEqual(len(report), 1)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
366 self.assertEqual(report[0][2], 0)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
368 def test_reporthook_5_bytes(self):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
369 # Test on 5 byte file. Should call reporthook only 2 times (once when
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
370 # the "network connection" is established and once when the block is
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
371 # read). Since the block size is 8192 bytes, only one block read is
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
372 # required to read the entire file.
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
373 report = []
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
374 def hooktester(count, block_size, total_size, _report=report):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
375 _report.append((count, block_size, total_size))
376 srcFileName = self.createNewTempFile(b"x" * 5)
377 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
378 support.TESTFN, hooktester)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
379 self.assertEqual(len(report), 2)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
380 self.assertEqual(report[0][1], 8192)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
381 self.assertEqual(report[0][2], 5)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
383 def test_reporthook_8193_bytes(self):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
384 # Test on 8193 byte file. Should call reporthook only 3 times (once
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
385 # when the "network connection" is established, once for the next 8192
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
386 # bytes, and once for the last byte).
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
387 report = []
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
388 def hooktester(count, block_size, total_size, _report=report):
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
389 _report.append((count, block_size, total_size))
390 srcFileName = self.createNewTempFile(b"x" * 8193)
391 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
392 support.TESTFN, hooktester)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
393 self.assertEqual(len(report), 3)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
394 self.assertEqual(report[0][1], 8192)
9d41afa63b79backport patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Georg Brandl georg@python.org
395 self.assertEqual(report[0][2], 8193)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
397 class QuotingTests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
398 """Tests for urllib.quote() and urllib.quote_plus()
400 According to RFC 2396 (Uniform Resource Identifiers), to escape a
401 character you write it as '%' + <2 character US-ASCII hex value>.
402 The Python code of ``'%' + hex(ord())[2:]`` escapes a
403 character properly. Case does not matter on the hex letters.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
405 The various character sets specified are:
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
407 Reserved characters : ";/?:@&=+$,"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
408 Have special meaning in URIs and must be escaped if not being used for
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
409 their special meaning
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
410 Data characters : letters, digits, and "-_.!~*'()"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
411 Unreserved and do not need to be escaped; can be, though, if desired
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
412 Control characters : 0x00 - 0x1F, 0x7F
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
413 Have no use in URIs so must be escaped
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
414 space : 0x20
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
415 Must be escaped
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
416 Delimiters : '<>#%"'
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
417 Must be escaped
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
418 Unwise : "{}|\^[]`"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
419 Must be escaped
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
421 """
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
423 def test_never_quote(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
424 # Make sure quote() does not quote letters, digits, and "_,.-"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
425 do_not_quote = '' .join(["ABCDEFGHIJKLMNOPQRSTUVWXYZ",
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
426 "abcdefghijklmnopqrstuvwxyz",
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
427 "0123456789",
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
428 "_.-"])
429 result = urllib.parse.quote(do_not_quote)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
430 self.assertEqual(do_not_quote, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
431 "using quote(): %r != %r" % (do_not_quote, result))
432 result = urllib.parse.quote_plus(do_not_quote)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
433 self.assertEqual(do_not_quote, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
434 "using quote_plus(): %r != %r" % (do_not_quote, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
436 def test_default_safe(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
437 # Test '/' is default value for 'safe' parameter
438 self.assertEqual(urllib.parse.quote.__defaults__[0], '/')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
440 def test_safe(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
441 # Test setting 'safe' parameter does what it should do
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
442 quote_by_default = "<>"
443 result = urllib.parse.quote(quote_by_default, safe=quote_by_default)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
444 self.assertEqual(quote_by_default, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
445 "using quote(): %r != %r" % (quote_by_default, result))
446 result = urllib.parse.quote_plus(quote_by_default,
447 safe=quote_by_default)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
448 self.assertEqual(quote_by_default, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
449 "using quote_plus(): %r != %r" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
450 (quote_by_default, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
451 # Safe expressed as bytes rather than str
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
452 result = urllib.parse.quote(quote_by_default, safe=b"<>")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
453 self.assertEqual(quote_by_default, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
454 "using quote(): %r != %r" % (quote_by_default, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
455 # "Safe" non-ASCII characters should have no effect
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
456 # (Since URIs are not allowed to have non-ASCII characters)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
457 result = urllib.parse.quote("a\xfcb", encoding="latin-1", safe="\xfc")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
458 expect = urllib.parse.quote("a\xfcb", encoding="latin-1", safe="")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
459 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
460 "using quote(): %r != %r" %
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
461 (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
462 # Same as above, but using a bytes rather than str
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
463 result = urllib.parse.quote("a\xfcb", encoding="latin-1", safe=b"\xfc")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
464 expect = urllib.parse.quote("a\xfcb", encoding="latin-1", safe="")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
465 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
466 "using quote(): %r != %r" %
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
467 (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
469 def test_default_quoting(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
470 # Make sure all characters that should be quoted are by default sans
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
471 # space (separate test for that).
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
472 should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
473 should_quote.append('<>#%"{}|\^[]`')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
474 should_quote.append(chr(127)) # For 0x7F
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
475 should_quote = ''.join(should_quote)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
476 for char in should_quote:
477 result = urllib.parse.quote(char)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
478 self.assertEqual(hexescape(char), result,
479 "using quote(): "
480 "%s should be escaped to %s, not %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
481 (char, hexescape(char), result))
482 result = urllib.parse.quote_plus(char)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
483 self.assertEqual(hexescape(char), result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
484 "using quote_plus(): "
485 "%s should be escapes to %s, not %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
486 (char, hexescape(char), result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
487 del should_quote
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
488 partial_quote = "ab[]cd"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
489 expected = "ab%5B%5Dcd"
490 result = urllib.parse.quote(partial_quote)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
491 self.assertEqual(expected, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
492 "using quote(): %r != %r" % (expected, result))
493 result = urllib.parse.quote_plus(partial_quote)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
494 self.assertEqual(expected, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
495 "using quote_plus(): %r != %r" % (expected, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
497 def test_quoting_space(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
498 # Make sure quote() and quote_plus() handle spaces as specified in
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
499 # their unique way
500 result = urllib.parse.quote(' ')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
501 self.assertEqual(result, hexescape(' '),
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
502 "using quote(): %r != %r" % (result, hexescape(' ')))
503 result = urllib.parse.quote_plus(' ')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
504 self.assertEqual(result, '+',
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
505 "using quote_plus(): %r != +" % result)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
506 given = "a b cd e f"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
507 expect = given.replace(' ', hexescape(' '))
508 result = urllib.parse.quote(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
509 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
510 "using quote(): %r != %r" % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
511 expect = given.replace(' ', '+')
512 result = urllib.parse.quote_plus(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
513 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
514 "using quote_plus(): %r != %r" % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
516 def test_quoting_plus(self):
517 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma'),
518 'alpha%2Bbeta+gamma')
519 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma', '+'),
520 'alpha+beta+gamma')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
521 # Test with bytes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
522 self.assertEqual(urllib.parse.quote_plus(b'alpha+beta gamma'),
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
523 'alpha%2Bbeta+gamma')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
524 # Test with safe bytes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
525 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma', b'+'),
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
526 'alpha+beta+gamma')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
528 def test_quote_bytes(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
529 # Bytes should quote directly to percent-encoded values
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
530 given = b"\xa2\xd8ab\xff"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
531 expect = "%A2%D8ab%FF"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
532 result = urllib.parse.quote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
533 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
534 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
535 # Encoding argument should raise type error on bytes input
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
536 self.assertRaises(TypeError, urllib.parse.quote, given,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
537 encoding="latin-1")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
538 # quote_from_bytes should work the same
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
539 result = urllib.parse.quote_from_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
540 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
541 "using quote_from_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
542 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
544 def test_quote_with_unicode(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
545 # Characters in Latin-1 range, encoded by default in UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
546 given = "\xa2\xd8ab\xff"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
547 expect = "%C2%A2%C3%98ab%C3%BF"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
548 result = urllib.parse.quote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
549 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
550 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
551 # Characters in Latin-1 range, encoded by with None (default)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
552 result = urllib.parse.quote(given, encoding=None, errors=None)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
553 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
554 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
555 # Characters in Latin-1 range, encoded with Latin-1
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
556 given = "\xa2\xd8ab\xff"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
557 expect = "%A2%D8ab%FF"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
558 result = urllib.parse.quote(given, encoding="latin-1")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
559 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
560 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
561 # Characters in BMP, encoded by default in UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
562 given = "\u6f22\u5b57" # "Kanji"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
563 expect = "%E6%BC%A2%E5%AD%97"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
564 result = urllib.parse.quote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
565 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
566 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
567 # Characters in BMP, encoded with Latin-1
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
568 given = "\u6f22\u5b57"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
569 self.assertRaises(UnicodeEncodeError, urllib.parse.quote, given,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
570 encoding="latin-1")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
571 # Characters in BMP, encoded with Latin-1, with replace error handling
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
572 given = "\u6f22\u5b57"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
573 expect = "%3F%3F" # "??"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
574 result = urllib.parse.quote(given, encoding="latin-1",
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
575 errors="replace")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
576 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
577 "using quote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
578 # Characters in BMP, Latin-1, with xmlcharref error handling
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
579 given = "\u6f22\u5b57"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
580 expect = "%26%2328450%3B%26%2323383%3B" # "æ¼¢å—"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
581 result = urllib.parse.quote(given, encoding="latin-1",
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
582 errors="xmlcharrefreplace")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
583 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
584 "using quote(): %r != %r" % (expect, result))
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
586 def test_quote_plus_with_unicode(self):
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
587 # Encoding (latin-1) test for quote_plus
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
588 given = "\xa2\xd8 \xff"
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
589 expect = "%A2%D8+%FF"
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
590 result = urllib.parse.quote_plus(given, encoding="latin-1")
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
591 self.assertEqual(expect, result,
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
592 "using quote_plus(): %r != %r" % (expect, result))
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
593 # Errors test for quote_plus
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
594 given = "ab\u6f22\u5b57 cd"
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
595 expect = "ab%3F%3F+cd"
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
596 result = urllib.parse.quote_plus(given, encoding="latin-1",
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
597 errors="replace")
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
598 self.assertEqual(expect, result,
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
599 "using quote_plus(): %r != %r" % (expect, result))
2721be7be365#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().
Georg Brandl georg@python.org
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
602 class UnquotingTests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
603 """Tests for unquote() and unquote_plus()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
605 See the doc string for quoting_Tests for details on quoting and such.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
607 """
28df4f45967fRemove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton jeremy@alum.mit.edu
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
609 def test_unquoting(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
610 # Make sure unquoting of all ASCII values works
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
611 escape_list = []
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
612 for num in range(128):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
613 given = hexescape(chr(num))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
614 expect = chr(num)
615 result = urllib.parse.unquote(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
616 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
617 "using unquote(): %r != %r" % (expect, result))
618 result = urllib.parse.unquote_plus(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
619 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
620 "using unquote_plus(): %r != %r" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
621 (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
622 escape_list.append(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
623 escape_string = ''.join(escape_list)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
624 del escape_list
625 result = urllib.parse.unquote(escape_string)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
626 self.assertEqual(result.count('%'), 1,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
627 "using unquote(): not all characters escaped: "
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
628 "%s" % result)
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
629 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, None)
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
630 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, ())
631 with support.check_warnings(('', BytesWarning), quiet=True):
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
632 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, b'')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
634 def test_unquoting_badpercent(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
635 # Test unquoting on bad percent-escapes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
636 given = '%xab'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
637 expect = given
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
638 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
639 self.assertEqual(expect, result, "using unquote(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
640 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
641 given = '%x'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
642 expect = given
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
643 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
644 self.assertEqual(expect, result, "using unquote(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
645 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
646 given = '%'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
647 expect = given
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
648 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
649 self.assertEqual(expect, result, "using unquote(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
650 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
651 # unquote_to_bytes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
652 given = '%xab'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
653 expect = bytes(given, 'ascii')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
654 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
655 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
656 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
657 given = '%x'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
658 expect = bytes(given, 'ascii')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
659 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
660 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
661 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
662 given = '%'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
663 expect = bytes(given, 'ascii')
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
664 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
665 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
666 % (expect, result))
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
667 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote_to_bytes, None)
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
668 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote_to_bytes, ())
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
670 def test_unquoting_mixed_case(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
671 # Test unquoting on mixed-case hex digits in the percent-escapes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
672 given = '%Ab%eA'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
673 expect = b'\xab\xea'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
674 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
675 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
676 "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
677 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
679 def test_unquoting_parts(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
680 # Make sure unquoting works when have non-quoted characters
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
681 # interspersed
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
682 given = 'ab%sd' % hexescape('c')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
683 expect = "abcd"
684 result = urllib.parse.unquote(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
685 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
686 "using quote(): %r != %r" % (expect, result))
687 result = urllib.parse.unquote_plus(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
688 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
689 "using unquote_plus(): %r != %r" % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
691 def test_unquoting_plus(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
692 # Test difference between unquote() and unquote_plus()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
693 given = "are+there+spaces..."
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
694 expect = given
695 result = urllib.parse.unquote(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
696 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
697 "using unquote(): %r != %r" % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
698 expect = given.replace('+', ' ')
699 result = urllib.parse.unquote_plus(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
700 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
701 "using unquote_plus(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
703 def test_unquote_to_bytes(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
704 given = 'br%C3%BCckner_sapporo_20050930.doc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
705 expect = b'br\xc3\xbcckner_sapporo_20050930.doc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
706 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
707 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
708 "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
709 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
710 # Test on a string with unescaped non-ASCII characters
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
711 # (Technically an invalid URI; expect those characters to be UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
712 # encoded).
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
713 result = urllib.parse.unquote_to_bytes("\u6f22%C3%BC")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
714 expect = b'\xe6\xbc\xa2\xc3\xbc' # UTF-8 for "\u6f22\u00fc"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
715 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
716 "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
717 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
718 # Test with a bytes as input
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
719 given = b'%A2%D8ab%FF'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
720 expect = b'\xa2\xd8ab\xff'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
721 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
722 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
723 "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
724 % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
725 # Test with a bytes as input, with unescaped non-ASCII bytes
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
726 # (Technically an invalid URI; expect those bytes to be preserved)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
727 given = b'%A2\xd8ab%FF'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
728 expect = b'\xa2\xd8ab\xff'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
729 result = urllib.parse.unquote_to_bytes(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
730 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
731 "using unquote_to_bytes(): %r != %r"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
732 % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
734 def test_unquote_with_unicode(self):
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
735 # Characters in the Latin-1 range, encoded with UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
736 given = 'br%C3%BCckner_sapporo_20050930.doc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
737 expect = 'br\u00fcckner_sapporo_20050930.doc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
738 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
739 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
740 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
741 # Characters in the Latin-1 range, encoded with None (default)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
742 result = urllib.parse.unquote(given, encoding=None, errors=None)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
743 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
744 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
746 # Characters in the Latin-1 range, encoded with Latin-1
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
747 result = urllib.parse.unquote('br%FCckner_sapporo_20050930.doc',
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
748 encoding="latin-1")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
749 expect = 'br\u00fcckner_sapporo_20050930.doc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
750 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
751 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
753 # Characters in BMP, encoded with UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
754 given = "%E6%BC%A2%E5%AD%97"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
755 expect = "\u6f22\u5b57" # "Kanji"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
756 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
757 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
758 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
760 # Decode with UTF-8, invalid sequence
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
761 given = "%F3%B1"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
762 expect = "\ufffd" # Replacement character
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
763 result = urllib.parse.unquote(given)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
764 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
765 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
767 # Decode with UTF-8, invalid sequence, replace errors
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
768 result = urllib.parse.unquote(given, errors="replace")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
769 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
770 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
772 # Decode with UTF-8, invalid sequence, ignoring errors
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
773 given = "%F3%B1"
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
774 expect = ""
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
775 result = urllib.parse.unquote(given, errors="ignore")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
776 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
777 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
779 # A mix of non-ASCII and percent-encoded characters, UTF-8
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
780 result = urllib.parse.unquote("\u6f22%C3%BC")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
781 expect = '\u6f22\u00fc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
782 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
783 "using unquote(): %r != %r" % (expect, result))
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
785 # A mix of non-ASCII and percent-encoded characters, Latin-1
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
786 # (Note, the string contains non-Latin-1-representable characters)
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
787 result = urllib.parse.unquote("\u6f22%FC", encoding="latin-1")
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
788 expect = '\u6f22\u00fc'
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
789 self.assertEqual(expect, result,
428d384ed626- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Guido van Rossum guido@python.org
790 "using unquote(): %r != %r" % (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
792 class urlencode_Tests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
793 """Tests for urlencode()"""
28df4f45967fRemove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton jeremy@alum.mit.edu
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
795 def help_inputtype(self, given, test_type):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
796 """Helper method for testing different input types.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
798 'given' must lead to only the pairs:
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
799 * 1st, 1
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
800 * 2nd, 2
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
801 * 3rd, 3
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
803 Test cannot assume anything about order. Docs make no guarantee and
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
804 have possible dictionary input.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
806 """
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
807 expect_somewhere = ["1st=1", "2nd=2", "3rd=3"]
808 result = urllib.parse.urlencode(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
809 for expected in expect_somewhere:
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
810 self.assertIn(expected, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
811 "testing %s: %s not found in %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
812 (test_type, expected, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
813 self.assertEqual(result.count('&'), 2,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
814 "testing %s: expected 2 '&'s; got %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
815 (test_type, result.count('&')))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
816 amp_location = result.index('&')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
817 on_amp_left = result[amp_location - 1]
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
818 on_amp_right = result[amp_location + 1]
819 self.assertTrue(on_amp_left.isdigit() and on_amp_right.isdigit(),
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
820 "testing %s: '&' not located in proper place in %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
821 (test_type, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
822 self.assertEqual(len(result), (5 * 3) + 2, #5 chars per thing and amps
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
823 "testing %s: "
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
824 "unexpected number of characters: %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
825 (test_type, len(result), (5 * 3) + 2))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
827 def test_using_mapping(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
828 # Test passing in a mapping object as an argument.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
829 self.help_inputtype({"1st":'1', "2nd":'2', "3rd":'3'},
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
830 "using dict as input type")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
832 def test_using_sequence(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
833 # Test passing in a sequence of two-item sequences as an argument.
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
834 self.help_inputtype([('1st', '1'), ('2nd', '2'), ('3rd', '3')],
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
835 "using sequence of two-item tuples as input")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
837 def test_quoting(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
838 # Make sure keys and values are quoted using quote_plus()
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
839 given = {"&":"="}
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
840 expect = "%s=%s" % (hexescape('&'), hexescape('='))
841 result = urllib.parse.urlencode(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
842 self.assertEqual(expect, result)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
843 given = {"key name":"A bunch of pluses"}
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
844 expect = "key+name=A+bunch+of+pluses"
845 result = urllib.parse.urlencode(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
846 self.assertEqual(expect, result)
28df4f45967fRemove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton jeremy@alum.mit.edu
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
848 def test_doseq(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
849 # Test that passing True for 'doseq' parameter works correctly
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
850 given = {'sequence':['1', '2', '3']}
851 expect = "sequence=%s" % urllib.parse.quote_plus(str(['1', '2', '3']))
852 result = urllib.parse.urlencode(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
853 self.assertEqual(expect, result)
854 result = urllib.parse.urlencode(given, True)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
855 for value in given["sequence"]:
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
856 expect = "sequence=%s" % value
1e7dcfc04061Merged revisions 76719,81270-81272,83294,83319,84038-84039 via svnmerge from
Florent Xicluna florent.xicluna@gmail.com
857 self.assertIn(expect, result)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
858 self.assertEqual(result.count('&'), 2,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
859 "Expected 2 '&'s, got %s" % result.count('&'))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
861 def test_empty_sequence(self):
862 self.assertEqual("", urllib.parse.urlencode({}))
863 self.assertEqual("", urllib.parse.urlencode([]))
865 def test_nonstring_values(self):
866 self.assertEqual("a=1", urllib.parse.urlencode({"a": 1}))
867 self.assertEqual("a=None", urllib.parse.urlencode({"a": None}))
869 def test_nonstring_seq_values(self):
870 self.assertEqual("a=1&a=2", urllib.parse.urlencode({"a": [1, 2]}, True))
871 self.assertEqual("a=None&a=a",
872 urllib.parse.urlencode({"a": [None, "a"]}, True))
873 self.assertEqual("a=a&a=b",
874 urllib.parse.urlencode({"a": {"a": 1, "b": 1}}, True))
876 def test_urlencode_encoding(self):
877 # ASCII encoding. Expect %3F with errors="replace'
878 given = (('\u00a0', '\u00c1'),)
879 expect = '%3F=%3F'
880 result = urllib.parse.urlencode(given, encoding="ASCII", errors="replace")
881 self.assertEqual(expect, result)
883 # Default is UTF-8 encoding.
884 given = (('\u00a0', '\u00c1'),)
885 expect = '%C2%A0=%C3%81'
886 result = urllib.parse.urlencode(given)
887 self.assertEqual(expect, result)
889 # Latin-1 encoding.
890 given = (('\u00a0', '\u00c1'),)
891 expect = '%A0=%C1'
892 result = urllib.parse.urlencode(given, encoding="latin-1")
893 self.assertEqual(expect, result)
895 def test_urlencode_encoding_doseq(self):
896 # ASCII Encoding. Expect %3F with errors="replace'
897 given = (('\u00a0', '\u00c1'),)
898 expect = '%3F=%3F'
899 result = urllib.parse.urlencode(given, doseq=True,
900 encoding="ASCII", errors="replace")
901 self.assertEqual(expect, result)
903 # ASCII Encoding. On a sequence of values.
904 given = (("\u00a0", (1, "\u00c1")),)
905 expect = '%3F=1&%3F=%3F'
906 result = urllib.parse.urlencode(given, True,
907 encoding="ASCII", errors="replace")
908 self.assertEqual(expect, result)
910 # Utf-8
911 given = (("\u00a0", "\u00c1"),)
912 expect = '%C2%A0=%C3%81'
913 result = urllib.parse.urlencode(given, True)
914 self.assertEqual(expect, result)
916 given = (("\u00a0", (42, "\u00c1")),)
917 expect = '%C2%A0=42&%C2%A0=%C3%81'
918 result = urllib.parse.urlencode(given, True)
919 self.assertEqual(expect, result)
921 # latin-1
922 given = (("\u00a0", "\u00c1"),)
923 expect = '%A0=%C1'
924 result = urllib.parse.urlencode(given, True, encoding="latin-1")
925 self.assertEqual(expect, result)
927 given = (("\u00a0", (42, "\u00c1")),)
928 expect = '%A0=42&%A0=%C1'
929 result = urllib.parse.urlencode(given, True, encoding="latin-1")
930 self.assertEqual(expect, result)
932 def test_urlencode_bytes(self):
933 given = ((b'\xa0\x24', b'\xc1\x24'),)
934 expect = '%A0%24=%C1%24'
935 result = urllib.parse.urlencode(given)
936 self.assertEqual(expect, result)
937 result = urllib.parse.urlencode(given, True)
938 self.assertEqual(expect, result)
940 # Sequence of values
941 given = ((b'\xa0\x24', (42, b'\xc1\x24')),)
942 expect = '%A0%24=42&%A0%24=%C1%24'
943 result = urllib.parse.urlencode(given, True)
944 self.assertEqual(expect, result)
946 def test_urlencode_encoding_safe_parameter(self):
948 # Send '$' (\x24) as safe character
949 # Default utf-8 encoding
951 given = ((b'\xa0\x24', b'\xc1\x24'),)
952 result = urllib.parse.urlencode(given, safe=":$")
953 expect = '%A0$=%C1$'
954 self.assertEqual(expect, result)
956 given = ((b'\xa0\x24', b'\xc1\x24'),)
957 result = urllib.parse.urlencode(given, doseq=True, safe=":$")
958 expect = '%A0$=%C1$'
959 self.assertEqual(expect, result)
961 # Safe parameter in sequence
962 given = ((b'\xa0\x24', (b'\xc1\x24', 0xd, 42)),)
963 expect = '%A0$=%C1$&%A0$=13&%A0$=42'
964 result = urllib.parse.urlencode(given, True, safe=":$")
965 self.assertEqual(expect, result)
967 # Test all above in latin-1 encoding
969 given = ((b'\xa0\x24', b'\xc1\x24'),)
970 result = urllib.parse.urlencode(given, safe=":$",
971 encoding="latin-1")
972 expect = '%A0$=%C1$'
973 self.assertEqual(expect, result)
975 given = ((b'\xa0\x24', b'\xc1\x24'),)
976 expect = '%A0$=%C1$'
977 result = urllib.parse.urlencode(given, doseq=True, safe=":$",
978 encoding="latin-1")
980 given = ((b'\xa0\x24', (b'\xc1\x24', 0xd, 42)),)
981 expect = '%A0$=%C1$&%A0$=13&%A0$=42'
982 result = urllib.parse.urlencode(given, True, safe=":$",
983 encoding="latin-1")
984 self.assertEqual(expect, result)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
986 class Pathname_Tests(unittest.TestCase):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
987 """Test pathname2url() and url2pathname()"""
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
989 def test_basic(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
990 # Make sure simple tests pass
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
991 expected_path = os.path.join("parts", "of", "a", "path")
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
992 expected_url = "parts/of/a/path"
993 result = urllib.request.pathname2url(expected_path)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
994 self.assertEqual(expected_url, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
995 "pathname2url() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
996 (result, expected_url))
997 result = urllib.request.url2pathname(expected_url)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
998 self.assertEqual(expected_path, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
999 "url2pathame() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1000 (result, expected_path))
28df4f45967fRemove "," from the list of always_safe characters. It is a reserved
Jeremy Hylton jeremy@alum.mit.edu
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1002 def test_quoting(self):
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1003 # Test automatic quoting and unquoting works for pathnam2url() and
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1004 # url2pathname() respectively
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1005 given = os.path.join("needs", "quot=ing", "here")
1006 expect = "needs/%s/here" % urllib.parse.quote("quot=ing")
1007 result = urllib.request.pathname2url(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1008 self.assertEqual(expect, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1009 "pathname2url() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1010 (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1011 expect = given
1012 result = urllib.request.url2pathname(result)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1013 self.assertEqual(expect, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1014 "url2pathname() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1015 (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1016 given = os.path.join("make sure", "using_quote")
1017 expect = "%s/using_quote" % urllib.parse.quote("make sure")
1018 result = urllib.request.pathname2url(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1019 self.assertEqual(expect, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1020 "pathname2url() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1021 (expect, result))
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1022 given = "make+sure/using_unquote"
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1023 expect = os.path.join("make+sure", "using_unquote")
1024 result = urllib.request.url2pathname(given)
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1025 self.assertEqual(expect, result,
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1026 "url2pathname() failed; %s != %s" %
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1027 (expect, result))
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1029 @unittest.skipUnless(sys.platform == 'win32',
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1030 'test specific to the urllib.url2path function.')
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1031 def test_ntpath(self):
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1032 given = ('/C:/', '///C:/', '/C|//')
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1033 expect = 'C:\\'
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1034 for url in given:
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1035 result = urllib.request.url2pathname(url)
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1036 self.assertEqual(expect, result,
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1037 'urllib.request..url2pathname() failed; %s != %s' %
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1038 (expect, result))
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1039 given = '///C|/path'
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1040 expect = 'C:\\path'
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1041 result = urllib.request.url2pathname(given)
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1042 self.assertEqual(expect, result,
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1043 'urllib.request.url2pathname() failed; %s != %s' %
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1044 (expect, result))
de0da2759c8cFix Issue11474 - fix url2pathname() handling of '/C|/' on Windows
Senthil Kumaran orsenthil@gmail.com
1046 class Utility_Tests(unittest.TestCase):
1047 """Testcase to test the various utility functions in the urllib."""
1049 def test_splitpasswd(self):
1050 """Some of password examples are not sensible, but it is added to
1051 confirming to RFC2617 and addressing issue4675.
1052 """
1053 self.assertEqual(('user', 'ab'),urllib.parse.splitpasswd('user:ab'))
1054 self.assertEqual(('user', 'a\nb'),urllib.parse.splitpasswd('user:a\nb'))
1055 self.assertEqual(('user', 'a\tb'),urllib.parse.splitpasswd('user:a\tb'))
1056 self.assertEqual(('user', 'a\rb'),urllib.parse.splitpasswd('user:a\rb'))
1057 self.assertEqual(('user', 'a\fb'),urllib.parse.splitpasswd('user:a\fb'))
1058 self.assertEqual(('user', 'a\vb'),urllib.parse.splitpasswd('user:a\vb'))
1059 self.assertEqual(('user', 'a:b'),urllib.parse.splitpasswd('user:a:b'))
805a0a1e3c2bIssue13104 - Fix urllib.request.thishost() utility function.
Senthil Kumaran senthil@uthcode.com
1061 def test_thishost(self):
805a0a1e3c2bIssue13104 - Fix urllib.request.thishost() utility function.
Senthil Kumaran senthil@uthcode.com
1062 """Test the urllib.request.thishost utility function returns a tuple"""
805a0a1e3c2bIssue13104 - Fix urllib.request.thishost() utility function.
Senthil Kumaran senthil@uthcode.com
1063 self.assertIsInstance(urllib.request.thishost(), tuple)
805a0a1e3c2bIssue13104 - Fix urllib.request.thishost() utility function.
Senthil Kumaran senthil@uthcode.com
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1066 class URLopener_Tests(unittest.TestCase):
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1067 """Testcase to test the open method of URLopener class."""
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1069 def test_quoted_open(self):
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1070 class DummyURLopener(urllib.request.URLopener):
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1071 def open_spam(self, url):
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1072 return url
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1074 self.assertEqual(DummyURLopener().open(
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1075 'spam://example/ /'),'//example/%20/')
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1077 # test the safe characters are not quoted by urlopen
1078 self.assertEqual(DummyURLopener().open(
1079 "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
1080 "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
1082 # Just commented them out.
1083 # Can't really tell why keep failing in windows and sparc.
1084 # Everywhere else they work ok, but on those machines, sometimes
1085 # fail in one of the tests, sometimes in other. I have a linux, and
1086 # the tests go ok.
1087 # If anybody has one of the problematic enviroments, please help!
1088 # . Facundo
1089 #
1090 # def server(evt):
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1091 # import socket, time
1092 # serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1093 # serv.settimeout(3)
1094 # serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1095 # serv.bind(("", 9093))
1096 # serv.listen(5)
1097 # try:
1098 # conn, addr = serv.accept()
1099 # conn.send("1 Hola mundo\n")
1100 # cantdata = 0
1101 # while cantdata < 13:
1102 # data = conn.recv(13-cantdata)
1103 # cantdata += len(data)
1104 # time.sleep(.3)
1105 # conn.send("2 No more lines\n")
1106 # conn.close()
1107 # except socket.timeout:
1108 # pass
1109 # finally:
1110 # serv.close()
1111 # evt.set()
1112 #
1113 # class FTPWrapperTests(unittest.TestCase):
1114 #
1115 # def setUp(self):
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1116 # import ftplib, time, threading
1117 # ftplib.FTP.port = 9093
1118 # self.evt = threading.Event()
1119 # threading.Thread(target=server, args=(self.evt,)).start()
1120 # time.sleep(.1)
1121 #
1122 # def tearDown(self):
1123 # self.evt.wait()
1124 #
1125 # def testBasic(self):
1126 # # connects
1127 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1128 # ftp.close()
1129 #
1130 # def testTimeoutNone(self):
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1131 # # global default timeout is ignored
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1132 # import socket
1133 # self.assertTrue(socket.getdefaulttimeout() is None)
1134 # socket.setdefaulttimeout(30)
1135 # try:
1136 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
1137 # finally:
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1138 # socket.setdefaulttimeout(None)
1139 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1140 # ftp.close()
1141 #
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1142 # def testTimeoutDefault(self):
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1143 # # global default timeout is used
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1144 # import socket
1145 # self.assertTrue(socket.getdefaulttimeout() is None)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1146 # socket.setdefaulttimeout(30)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1147 # try:
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1148 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1149 # finally:
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1150 # socket.setdefaulttimeout(None)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1151 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1152 # ftp.close()
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1153 #
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1154 # def testTimeoutValue(self):
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1155 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1156 # timeout=30)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1157 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
2925b568aaccMerged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl georg@python.org
1158 # ftp.close()
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1160 class RequestTests(unittest.TestCase):
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1161 """Unit tests for urllib.request.Request."""
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1163 def test_default_values(self):
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1164 Request = urllib.request.Request
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1165 request = Request("http://www.python.org")
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1166 self.assertEqual(request.get_method(), 'GET')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1167 request = Request("http://www.python.org", {})
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1168 self.assertEqual(request.get_method(), 'POST')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1170 def test_with_method_arg(self):
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1171 Request = urllib.request.Request
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1172 request = Request("http://www.python.org", method='HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1173 self.assertEqual(request.method, 'HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1174 self.assertEqual(request.get_method(), 'HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1175 request = Request("http://www.python.org", {}, method='HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1176 self.assertEqual(request.method, 'HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1177 self.assertEqual(request.get_method(), 'HEAD')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1178 request = Request("http://www.python.org", method='GET')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1179 self.assertEqual(request.get_method(), 'GET')
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1180 request.method = 'HEAD'
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1181 self.assertEqual(request.get_method(), 'HEAD')
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1184 def test_main():
1185 support.run_unittest(
1186 urlopen_FileTests,
a72bc4257336Fix a bug that robotparser starves memory when the server responses
Hye-Shik Chang hyeshik@gmail.com
1187 urlopen_HttpTests,
1188 urlretrieve_FileTests,
1d5c3bcf35adMerged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
Benjamin Peterson benjamin@python.org
1189 ProxyTests,
1190 QuotingTests,
1191 UnquotingTests,
1192 urlencode_Tests,
1193 Pathname_Tests,
1194 Utility_Tests,
bbe2aa431692Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Senthil Kumaran orsenthil@gmail.com
1195 URLopener_Tests,
1196 #FTPWrapperTests,
0a0aafaa9bf5Fix closes issue 1673007 urllib.request to support HEAD requests with a new method arg.
Senthil Kumaran senthil@uthcode.com
1197 RequestTests,
1198 )
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1202 if __name__ == '__main__':
64cb657b0338Complete rewrite of module. Only has tests using temporary files; net tests
Brett Cannon bcannon@gmail.com
1203 test_main()