Lines Matching refs:self

70         def sendall(self, data):
73 def makefile(self, *args, **kwds):
74 self.io_refs += 1
75 return self
77 def read(self, amt=None):
78 if self.closed:
80 return io.BytesIO.read(self, amt)
82 def readline(self, length=None):
83 if self.closed:
85 return io.BytesIO.readline(self, length)
87 def close(self):
88 self.io_refs -= 1
89 if self.io_refs == 0:
90 io.BytesIO.close(self)
97 def connect(self):
98 self.sock = FakeSocket(self.fakedata)
99 type(self).fakesock = self.sock
103 # flush(). Problem: flush() calls self.fp.flush() which raises
106 def close(self):
114 def fakehttp(self, fakedata, mock_close=False):
116 self._connection_class = http.client.HTTPConnection
119 def unfakehttp(self):
120 http.client.HTTPConnection = self._connection_class
124 def fakeftp(self):
126 def __init__(self, user, passwd, host, port, dirs, timeout=None,
130 def retrfile(self, file, type):
133 def close(self):
136 self._ftpwrapper_class = urllib.request.ftpwrapper
139 def unfakeftp(self):
140 urllib.request.ftpwrapper = self._ftpwrapper_class
151 def setUp(self):
153 self.text = bytes("test_urllib: %s\n" % self.__class__.__name__,
157 f.write(self.text)
160 self.pathname = os_helper.TESTFN
161 self.quoted_pathname = urllib.parse.quote(self.pathname)
162 self.returned_obj = urlopen("file:%s" % self.quoted_pathname)
164 def tearDown(self):
166 self.returned_obj.close()
169 def test_interface(self):
173 self.assertTrue(hasattr(self.returned_obj, attr),
177 def test_read(self):
178 self.assertEqual(self.text, self.returned_obj.read())
180 def test_readline(self):
181 self.assertEqual(self.text, self.returned_obj.readline())
182 self.assertEqual(b'', self.returned_obj.readline(),
186 def test_readlines(self):
187 lines_list = self.returned_obj.readlines()
188 self.assertEqual(len(lines_list), 1,
190 self.assertEqual(lines_list[0], self.text,
193 def test_fileno(self):
194 file_num = self.returned_obj.fileno()
195 self.assertIsInstance(file_num, int, "fileno() did not return an int")
196 self.assertEqual(os.read(file_num, len(self.text)), self.text,
200 def test_close(self):
203 self.returned_obj.close()
205 def test_headers(self):
206 self.assertIsInstance(self.returned_obj.headers, email.message.Message)
208 def test_url(self):
209 self.assertEqual(self.returned_obj.url, self.quoted_pathname)
211 def test_status(self):
212 self.assertIsNone(self.returned_obj.status)
214 def test_info(self):
215 self.assertIsInstance(self.returned_obj.info(), email.message.Message)
217 def test_geturl(self):
218 self.assertEqual(self.returned_obj.geturl(), self.quoted_pathname)
220 def test_getcode(self):
221 self.assertIsNone(self.returned_obj.getcode())
223 def test_iter(self):
229 for line in self.returned_obj:
230 self.assertEqual(line, self.text)
232 def test_relativelocalfile(self):
233 self.assertRaises(ValueError,urllib.request.urlopen,'./' + self.pathname)
238 def setUp(self):
240 self.env = self.enterContext(os_helper.EnvironmentVarGuard())
244 self.env.unset(k)
246 def test_getproxies_environment_keep_no_proxies(self):
247 self.env.set('NO_PROXY', 'localhost')
250 self.assertEqual('localhost', proxies['no'])
252 self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com:1234')
253 self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com'))
254 self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com:8888'))
255 self.assertTrue(urllib.request.proxy_bypass_environment('newdomain.com:1234'))
257 def test_proxy_cgi_ignore(self):
259 self.env.set('HTTP_PROXY', 'http://somewhere:3128')
261 self.assertEqual('http://somewhere:3128', proxies['http'])
262 self.env.set('REQUEST_METHOD', 'GET')
264 self.assertNotIn('http', proxies)
266 self.env.unset('REQUEST_METHOD')
267 self.env.unset('HTTP_PROXY')
269 def test_proxy_bypass_environment_host_match(self):
271 self.env.set('NO_PROXY',
273 self.assertTrue(bypass('localhost'))
274 self.assertTrue(bypass('LocalHost')) # MixedCase
275 self.assertTrue(bypass('LOCALHOST')) # UPPERCASE
276 self.assertTrue(bypass('.localhost'))
277 self.assertTrue(bypass('newdomain.com:1234'))
278 self.assertTrue(bypass('.newdomain.com:1234'))
279 self.assertTrue(bypass('foo.d.o.t')) # issue 29142
280 self.assertTrue(bypass('d.o.t'))
281 self.assertTrue(bypass('anotherdomain.com:8888'))
282 self.assertTrue(bypass('.anotherdomain.com:8888'))
283 self.assertTrue(bypass('www.newdomain.com:1234'))
284 self.assertFalse(bypass('prelocalhost'))
285 self.assertFalse(bypass('newdomain.com')) # no port
286 self.assertFalse(bypass('newdomain.com:1235')) # wrong port
288 def test_proxy_bypass_environment_always_match(self):
290 self.env.set('NO_PROXY', '*')
291 self.assertTrue(bypass('newdomain.com'))
292 self.assertTrue(bypass('newdomain.com:1234'))
293 self.env.set('NO_PROXY', '*, anotherdomain.com')
294 self.assertTrue(bypass('anotherdomain.com'))
295 self.assertFalse(bypass('newdomain.com'))
296 self.assertFalse(bypass('newdomain.com:1234'))
298 def test_proxy_bypass_environment_newline(self):
300 self.env.set('NO_PROXY',
302 self.assertFalse(bypass('localhost\n'))
303 self.assertFalse(bypass('anotherdomain.com:8888\n'))
304 self.assertFalse(bypass('newdomain.com:1234\n'))
309 def setUp(self):
311 self._saved_env = os.environ
315 def tearDown(self):
316 os.environ = self._saved_env
318 def test_getproxies_environment_prefer_lowercase(self):
322 self.assertFalse(urllib.request.proxy_bypass_environment('localhost'))
323 self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary'))
327 self.assertEqual({}, proxies)
331 self.assertTrue(urllib.request.proxy_bypass_environment('localhost'))
332 self.assertTrue(urllib.request.proxy_bypass_environment('noproxy.com:5678'))
333 self.assertTrue(urllib.request.proxy_bypass_environment('my.proxy:1234'))
334 self.assertFalse(urllib.request.proxy_bypass_environment('my.proxy'))
335 self.assertFalse(urllib.request.proxy_bypass_environment('arbitrary'))
340 self.assertEqual('http://somewhere:3128', proxies['http'])
346 def check_read(self, ver):
347 self.fakehttp(b"HTTP/" + ver + b" 200 OK\r\n\r\nHello!")
350 self.assertEqual(fp.readline(), b"Hello!")
351 self.assertEqual(fp.readline(), b"")
352 self.assertEqual(fp.geturl(), 'http://python.org/')
353 self.assertEqual(fp.getcode(), 200)
355 self.unfakehttp()
357 def test_url_fragment(self):
360 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
363 self.assertEqual(fp.geturl(), url)
365 self.unfakehttp()
367 def test_willclose(self):
368 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
371 self.assertTrue(resp.fp.will_close)
373 self.unfakehttp()
376 def test_url_path_with_control_char_rejected(self):
380 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
390 with self.assertRaisesRegex(
393 with self.assertRaisesRegex(
398 self.assertNotIn(char, resp.geturl())
400 self.unfakehttp()
403 def test_url_path_with_newline_header_injection_rejected(self):
404 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
415 with self.assertRaisesRegex(
418 with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"):
422 self.assertNotIn(' ', resp.geturl())
423 self.assertNotIn('\r', resp.geturl())
424 self.assertNotIn('\n', resp.geturl())
426 self.unfakehttp()
429 def test_url_host_with_control_char_rejected(self):
433 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
437 with self.assertRaisesRegex(
440 with self.assertRaisesRegex(InvalidURL, f"contain control.*{escaped_char_repr}"):
443 self.unfakehttp()
446 def test_url_host_with_newline_header_injection_rejected(self):
447 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
452 with self.assertRaisesRegex(
455 with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"):
458 self.unfakehttp()
460 def test_read_0_9(self):
463 self.check_read(b"0.9")
465 def test_read_1_0(self):
466 self.check_read(b"1.0")
468 def test_read_1_1(self):
469 self.check_read(b"1.1")
471 def test_read_bogus(self):
473 self.fakehttp(b'''HTTP/1.1 401 Authentication Required
480 self.assertRaises(OSError, urlopen, "http://python.org/")
482 self.unfakehttp()
484 def test_invalid_redirect(self):
486 self.fakehttp(b'''HTTP/1.1 302 Found
495 with self.assertRaisesRegex(urllib.error.HTTPError, msg):
498 self.unfakehttp()
500 def test_redirect_limit_independent(self):
504 self.fakehttp(b'''HTTP/1.1 302 Found
509 self.assertRaises(urllib.error.HTTPError, urlopen,
512 self.unfakehttp()
514 def test_empty_socket(self):
517 self.fakehttp(b'')
519 self.assertRaises(OSError, urlopen, "http://something")
521 self.unfakehttp()
523 def test_missing_localfile(self):
525 with self.assertRaises(urllib.error.URLError) as e:
527 self.assertTrue(e.exception.filename)
528 self.assertTrue(e.exception.reason)
530 def test_file_notexists(self):
534 self.assertTrue(os.path.exists(tmp_file))
536 self.assertTrue(fobj)
540 self.assertFalse(os.path.exists(tmp_file))
541 with self.assertRaises(urllib.error.URLError):
544 def test_ftp_nohost(self):
546 with self.assertRaises(urllib.error.URLError) as e:
548 self.assertFalse(e.exception.filename)
549 self.assertTrue(e.exception.reason)
551 def test_ftp_nonexisting(self):
552 with self.assertRaises(urllib.error.URLError) as e:
554 self.assertFalse(e.exception.filename)
555 self.assertTrue(e.exception.reason)
558 def test_ftp_cache_pruning(self):
559 self.fakeftp()
564 self.unfakeftp()
566 def test_userpass_inurl(self):
567 self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
570 self.assertEqual(fp.readline(), b"Hello!")
571 self.assertEqual(fp.readline(), b"")
572 self.assertEqual(fp.geturl(), 'http://user:pass@python.org/')
573 self.assertEqual(fp.getcode(), 200)
575 self.unfakehttp()
577 def test_userpass_inurl_w_spaces(self):
578 self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
587 self.assertIn(authorization, fakehttp_wrapper.buf.decode("UTF-8"))
588 self.assertEqual(fp.readline(), b"Hello!")
589 self.assertEqual(fp.readline(), b"")
591 self.assertNotEqual(fp.geturl(), url)
592 self.assertEqual(fp.getcode(), 200)
594 self.unfakehttp()
596 def test_URLopener_deprecation(self):
601 def test_cafile_and_context(self):
604 with self.assertRaises(ValueError):
613 def setUp(self):
615 self.addCleanup(urllib.request.urlcleanup)
618 self.text = "test data URLs :;,%=& \u00f6 \u00c4 "
620 self.image = (
626 self.text_url = (
629 self.text_url_base64 = (
634 self.image_url = (
639 self.text_url_resp = urllib.request.urlopen(self.text_url)
640 self.text_url_base64_resp = urllib.request.urlopen(
641 self.text_url_base64)
642 self.image_url_resp = urllib.request.urlopen(self.image_url)
644 def test_interface(self):
648 self.assertTrue(hasattr(self.text_url_resp, attr),
652 def test_info(self):
653 self.assertIsInstance(self.text_url_resp.info(), email.message.Message)
654 self.assertEqual(self.text_url_base64_resp.info().get_params(),
656 self.assertEqual(self.image_url_resp.info()['content-length'],
657 str(len(self.image)))
658 self.assertEqual(urllib.request.urlopen("data:,").info().get_params(),
661 def test_geturl(self):
662 self.assertEqual(self.text_url_resp.geturl(), self.text_url)
663 self.assertEqual(self.text_url_base64_resp.geturl(),
664 self.text_url_base64)
665 self.assertEqual(self.image_url_resp.geturl(), self.image_url)
667 def test_read_text(self):
668 self.assertEqual(self.text_url_resp.read().decode(
669 dict(self.text_url_resp.info().get_params())['charset']), self.text)
671 def test_read_text_base64(self):
672 self.assertEqual(self.text_url_base64_resp.read().decode(
673 dict(self.text_url_base64_resp.info().get_params())['charset']),
674 self.text)
676 def test_read_image(self):
677 self.assertEqual(self.image_url_resp.read(), self.image)
679 def test_missing_comma(self):
680 self.assertRaises(ValueError,urllib.request.urlopen,'data:text/plain')
682 def test_invalid_base64_data(self):
684 self.assertRaises(ValueError,urllib.request.urlopen,'data:;base64,Cg=')
690 def setUp(self):
692 self.addCleanup(urllib.request.urlcleanup)
701 self.tempFiles = []
704 self.registerFileForCleanUp(os_helper.TESTFN)
705 self.text = b'testing urllib.urlretrieve'
708 FILE.write(self.text)
714 def tearDown(self):
716 for each in self.tempFiles:
720 def constructLocalFileUrl(self, filePath):
728 def createNewTempFile(self, data=b""):
735 self.registerFileForCleanUp(newFilePath)
744 def registerFileForCleanUp(self, fileName):
745 self.tempFiles.append(fileName)
747 def test_basic(self):
751 self.assertEqual(result[0], os_helper.TESTFN)
752 self.assertIsInstance(result[1], email.message.Message,
756 def test_copy(self):
759 self.registerFileForCleanUp(second_temp)
760 result = urllib.request.urlretrieve(self.constructLocalFileUrl(
762 self.assertEqual(second_temp, result[0])
763 self.assertTrue(os.path.exists(second_temp), "copy of the file was not "
772 self.assertEqual(self.text, text)
774 def test_reporthook(self):
777 self.assertIsInstance(block_count, int)
778 self.assertIsInstance(block_read_size, int)
779 self.assertIsInstance(file_size, int)
780 self.assertEqual(block_count, count_holder[0])
783 self.registerFileForCleanUp(second_temp)
785 self.constructLocalFileUrl(os_helper.TESTFN),
788 def test_reporthook_0_bytes(self):
793 srcFileName = self.createNewTempFile()
794 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
796 self.assertEqual(len(report), 1)
797 self.assertEqual(report[0][2], 0)
799 def test_reporthook_5_bytes(self):
806 srcFileName = self.createNewTempFile(b"x" * 5)
807 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
809 self.assertEqual(len(report), 2)
810 self.assertEqual(report[0][2], 5)
811 self.assertEqual(report[1][2], 5)
813 def test_reporthook_8193_bytes(self):
820 srcFileName = self.createNewTempFile(b"x" * 8193)
821 urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName),
823 self.assertEqual(len(report), 3)
824 self.assertEqual(report[0][2], 8193)
825 self.assertEqual(report[0][1], 8192)
826 self.assertEqual(report[1][1], 8192)
827 self.assertEqual(report[2][1], 8192)
833 def test_short_content_raises_ContentTooShortError(self):
834 self.addCleanup(urllib.request.urlcleanup)
836 self.fakehttp(b'''HTTP/1.1 200 OK
849 with self.assertRaises(urllib.error.ContentTooShortError):
854 self.unfakehttp()
856 def test_short_content_raises_ContentTooShortError_without_reporthook(self):
857 self.addCleanup(urllib.request.urlcleanup)
859 self.fakehttp(b'''HTTP/1.1 200 OK
868 with self.assertRaises(urllib.error.ContentTooShortError):
872 self.unfakehttp()
901 def test_never_quote(self):
908 self.assertEqual(do_not_quote, result,
911 self.assertEqual(do_not_quote, result,
914 def test_default_safe(self):
916 self.assertEqual(urllib.parse.quote.__defaults__[0], '/')
918 def test_safe(self):
922 self.assertEqual(quote_by_default, result,
926 self.assertEqual(quote_by_default, result,
931 self.assertEqual(quote_by_default, result,
937 self.assertEqual(expect, result,
943 self.assertEqual(expect, result,
947 def test_default_quoting(self):
956 self.assertEqual(hexescape(char), result,
961 self.assertEqual(hexescape(char), result,
969 self.assertEqual(expected, result,
972 self.assertEqual(expected, result,
975 def test_quoting_space(self):
979 self.assertEqual(result, hexescape(' '),
982 self.assertEqual(result, '+',
987 self.assertEqual(expect, result,
991 self.assertEqual(expect, result,
994 def test_quoting_plus(self):
995 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma'),
997 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma', '+'),
1000 self.assertEqual(urllib.parse.quote_plus(b'alpha+beta gamma'),
1003 self.assertEqual(urllib.parse.quote_plus('alpha+beta gamma', b'+'),
1006 def test_quote_bytes(self):
1011 self.assertEqual(expect, result,
1014 self.assertRaises(TypeError, urllib.parse.quote, given,
1018 self.assertEqual(expect, result,
1022 def test_quote_with_unicode(self):
1027 self.assertEqual(expect, result,
1031 self.assertEqual(expect, result,
1037 self.assertEqual(expect, result,
1043 self.assertEqual(expect, result,
1047 self.assertRaises(UnicodeEncodeError, urllib.parse.quote, given,
1054 self.assertEqual(expect, result,
1061 self.assertEqual(expect, result,
1064 def test_quote_plus_with_unicode(self):
1069 self.assertEqual(expect, result,
1076 self.assertEqual(expect, result,
1087 def test_unquoting(self):
1094 self.assertEqual(expect, result,
1097 self.assertEqual(expect, result,
1104 self.assertEqual(result.count('%'), 1,
1107 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, None)
1108 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, ())
1110 def test_unquoting_badpercent(self):
1115 self.assertEqual(expect, result, "using unquote(): %r != %r"
1120 self.assertEqual(expect, result, "using unquote(): %r != %r"
1125 self.assertEqual(expect, result, "using unquote(): %r != %r"
1131 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
1136 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
1141 self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
1143 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote_to_bytes, None)
1144 self.assertRaises((TypeError, AttributeError), urllib.parse.unquote_to_bytes, ())
1146 def test_unquoting_mixed_case(self):
1151 self.assertEqual(expect, result,
1155 def test_unquoting_parts(self):
1161 self.assertEqual(expect, result,
1164 self.assertEqual(expect, result,
1167 def test_unquoting_plus(self):
1172 self.assertEqual(expect, result,
1176 self.assertEqual(expect, result,
1179 def test_unquote_to_bytes(self):
1183 self.assertEqual(expect, result,
1191 self.assertEqual(expect, result,
1198 self.assertEqual(expect, result,
1206 self.assertEqual(expect, result,
1210 def test_unquote_with_unicode(self):
1215 self.assertEqual(expect, result,
1219 self.assertEqual(expect, result,
1226 self.assertEqual(expect, result,
1233 self.assertEqual(expect, result,
1240 self.assertEqual(expect, result,
1245 self.assertEqual(expect, result,
1252 self.assertEqual(expect, result,
1258 self.assertEqual(expect, result,
1265 self.assertEqual(expect, result,
1268 def test_unquoting_with_bytes_input(self):
1273 self.assertEqual(expect, result,
1280 self.assertEqual(expect, result,
1287 self.assertEqual(expect, result,
1294 def help_inputtype(self, given, test_type):
1309 self.assertIn(expected, result,
1312 self.assertEqual(result.count('&'), 2,
1318 self.assertTrue(on_amp_left.isdigit() and on_amp_right.isdigit(),
1321 self.assertEqual(len(result), (5 * 3) + 2, #5 chars per thing and amps
1326 def test_using_mapping(self):
1328 self.help_inputtype({"1st":'1', "2nd":'2', "3rd":'3'},
1331 def test_using_sequence(self):
1333 self.help_inputtype([('1st', '1'), ('2nd', '2'), ('3rd', '3')],
1336 def test_quoting(self):
1341 self.assertEqual(expect, result)
1345 self.assertEqual(expect, result)
1347 def test_doseq(self):
1352 self.assertEqual(expect, result)
1356 self.assertIn(expect, result)
1357 self.assertEqual(result.count('&'), 2,
1360 def test_empty_sequence(self):
1361 self.assertEqual("", urllib.parse.urlencode({}))
1362 self.assertEqual("", urllib.parse.urlencode([]))
1364 def test_nonstring_values(self):
1365 self.assertEqual("a=1", urllib.parse.urlencode({"a": 1}))
1366 self.assertEqual("a=None", urllib.parse.urlencode({"a": None}))
1368 def test_nonstring_seq_values(self):
1369 self.assertEqual("a=1&a=2", urllib.parse.urlencode({"a": [1, 2]}, True))
1370 self.assertEqual("a=None&a=a",
1373 self.assertEqual("a=a&a=b",
1376 def test_urlencode_encoding(self):
1381 self.assertEqual(expect, result)
1387 self.assertEqual(expect, result)
1393 self.assertEqual(expect, result)
1395 def test_urlencode_encoding_doseq(self):
1401 self.assertEqual(expect, result)
1408 self.assertEqual(expect, result)
1414 self.assertEqual(expect, result)
1419 self.assertEqual(expect, result)
1425 self.assertEqual(expect, result)
1430 self.assertEqual(expect, result)
1432 def test_urlencode_bytes(self):
1436 self.assertEqual(expect, result)
1438 self.assertEqual(expect, result)
1444 self.assertEqual(expect, result)
1446 def test_urlencode_encoding_safe_parameter(self):
1454 self.assertEqual(expect, result)
1459 self.assertEqual(expect, result)
1465 self.assertEqual(expect, result)
1473 self.assertEqual(expect, result)
1484 self.assertEqual(expect, result)
1489 def test_basic(self):
1494 self.assertEqual(expected_url, result,
1498 self.assertEqual(expected_path, result,
1502 def test_quoting(self):
1508 self.assertEqual(expect, result,
1513 self.assertEqual(expect, result,
1519 self.assertEqual(expect, result,
1525 self.assertEqual(expect, result,
1531 def test_prefixes(self):
1536 self.assertEqual(expect, result,
1542 self.assertEqual(expect, result,
1549 def test_ntpath(self):
1554 self.assertEqual(expect, result,
1560 self.assertEqual(expect, result,
1567 def test_thishost(self):
1569 self.assertIsInstance(urllib.request.thishost(), tuple)
1575 def test_quoted_open(self):
1577 def open_spam(self, url):
1582 self.assertEqual(DummyURLopener().open(
1586 self.assertEqual(DummyURLopener().open(
1591 def test_urlopener_retrieve_file(self):
1598 self.assertEqual(os.path.normcase(filename), os.path.normcase(tmpfile))
1601 def test_urlopener_retrieve_remote(self):
1603 self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
1604 self.addCleanup(self.unfakehttp)
1606 self.assertEqual(os.path.splitext(filename)[1], ".txt")
1609 def test_local_file_open(self):
1612 def open_local_file(self, url):
1615 self.assertRaises(OSError, urllib.request.urlopen, url)
1616 self.assertRaises(OSError, urllib.request.URLopener().open, url)
1617 self.assertRaises(OSError, urllib.request.URLopener().retrieve, url)
1618 self.assertRaises(OSError, DummyURLopener().open, url)
1619 self.assertRaises(OSError, DummyURLopener().retrieve, url)
1625 def test_default_values(self):
1628 self.assertEqual(request.get_method(), 'GET')
1630 self.assertEqual(request.get_method(), 'POST')
1632 def test_with_method_arg(self):
1635 self.assertEqual(request.method, 'HEAD')
1636 self.assertEqual(request.get_method(), 'HEAD')
1638 self.assertEqual(request.method, 'HEAD')
1639 self.assertEqual(request.get_method(), 'HEAD')
1641 self.assertEqual(request.get_method(), 'GET')
1643 self.assertEqual(request.get_method(), 'HEAD')
1648 def test_converting_drive_letter(self):
1649 self.assertEqual(url2pathname("///C|"), 'C:')
1650 self.assertEqual(url2pathname("///C:"), 'C:')
1651 self.assertEqual(url2pathname("///C|/"), 'C:\\')
1653 def test_converting_when_no_drive_letter(self):
1655 self.assertEqual(url2pathname("///C/test/"), r'\\\C\test' '\\')
1656 self.assertEqual(url2pathname("////C/test/"), r'\\C\test' '\\')
1658 def test_simple_compare(self):
1659 self.assertEqual(url2pathname("///C|/foo/bar/spam.foo"),
1662 def test_non_ascii_drive_letter(self):
1663 self.assertRaises(IOError, url2pathname, "///\u00e8|/")
1665 def test_roundtrip_url2pathname(self):
1671 self.assertEqual(url2pathname(pathname2url(path)), path)
1675 def test_converting_drive_letter(self):
1676 self.assertEqual(pathname2url("C:"), '///C:')
1677 self.assertEqual(pathname2url("C:\\"), '///C:')
1679 def test_converting_when_no_drive_letter(self):
1680 self.assertEqual(pathname2url(r"\\\folder\test" "\\"),
1682 self.assertEqual(pathname2url(r"\\folder\test" "\\"),
1684 self.assertEqual(pathname2url(r"\folder\test" "\\"),
1687 def test_simple_compare(self):
1688 self.assertEqual(pathname2url(r'C:\foo\bar\spam.foo'),
1691 def test_long_drive_letter(self):
1692 self.assertRaises(IOError, pathname2url, "XX:\\")
1694 def test_roundtrip_pathname2url(self):
1699 self.assertEqual(pathname2url(url2pathname(path)), path)