summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_SimpleHTTPServer.py4
-rw-r--r--Lib/test/test___all__.py10
-rw-r--r--Lib/test/test_docxmlrpc.py4
-rw-r--r--Lib/test/test_http_cookiejar.py (renamed from Lib/test/test_cookielib.py)205
-rw-r--r--Lib/test/test_http_cookies.py (renamed from Lib/test/test_cookie.py)12
-rw-r--r--Lib/test/test_httplib.py4
-rw-r--r--Lib/test/test_httpservers.py13
-rw-r--r--Lib/test/test_pyclbr.py1
-rw-r--r--Lib/test/test_shelve.py2
-rw-r--r--Lib/test/test_socket.py2
-rw-r--r--Lib/test/test_ssl.py3
-rw-r--r--Lib/test/test_sundry.py1
-rw-r--r--Lib/test/test_urllib.py10
-rw-r--r--Lib/test/test_urllib2.py11
-rw-r--r--Lib/test/test_urllib2_localnet.py16
-rw-r--r--Lib/test/test_urllib2net.py8
-rw-r--r--Lib/test/test_xmlrpc.py6
-rw-r--r--Lib/test/test_xmlrpc_net.py2
18 files changed, 104 insertions, 210 deletions
diff --git a/Lib/test/test_SimpleHTTPServer.py b/Lib/test/test_SimpleHTTPServer.py
index d285f27..36c2b89 100644
--- a/Lib/test/test_SimpleHTTPServer.py
+++ b/Lib/test/test_SimpleHTTPServer.py
@@ -4,11 +4,11 @@ We don't want to require the 'network' resource.
"""
import os, unittest
-from SimpleHTTPServer import SimpleHTTPRequestHandler
+from http.server import SimpleHTTPRequestHandler
from test import support
-class SocketlessRequestHandler (SimpleHTTPRequestHandler):
+class SocketlessRequestHandler(SimpleHTTPRequestHandler):
def __init__(self):
pass
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index f3f7ba3..89395be 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -33,12 +33,10 @@ class AllTest(unittest.TestCase):
# than an AttributeError somewhere deep in CGIHTTPServer.
import _socket
- self.check_all("BaseHTTPServer")
- self.check_all("CGIHTTPServer")
+ self.check_all("http.server")
self.check_all("configparser")
- self.check_all("Cookie")
- self.check_all("Queue")
- self.check_all("SimpleHTTPServer")
+ self.check_all("http.cookies")
+ self.check_all("queue")
self.check_all("socketserver")
self.check_all("aifc")
self.check_all("base64")
@@ -77,7 +75,7 @@ class AllTest(unittest.TestCase):
self.check_all("gzip")
self.check_all("heapq")
self.check_all("htmllib")
- self.check_all("httplib")
+ self.check_all("http.client")
self.check_all("ihooks")
self.check_all("imaplib")
self.check_all("imghdr")
diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py
index 9cb9ffb..d1799a2 100644
--- a/Lib/test/test_docxmlrpc.py
+++ b/Lib/test/test_docxmlrpc.py
@@ -1,5 +1,5 @@
from xmlrpc.server import DocXMLRPCServer
-import httplib
+import http.client
from test import support
import threading
import time
@@ -65,7 +65,7 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
time.sleep(0.001)
n -= 1
- self.client = httplib.HTTPConnection("localhost:%d" % PORT)
+ self.client = http.client.HTTPConnection("localhost:%d" % PORT)
def tearDown(self):
self.client.close()
diff --git a/Lib/test/test_cookielib.py b/Lib/test/test_http_cookiejar.py
index e400bfa..09fb0c6 100644
--- a/Lib/test/test_cookielib.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -1,15 +1,20 @@
-"""Tests for cookielib.py."""
+"""Tests for http/cookiejar.py."""
-import re, os, time
+import re, os, time, urllib2
from unittest import TestCase
from test import support
+from http.cookiejar import time2isoz, http2time, time2netscape, \
+ parse_ns_headers, join_header_words, split_header_words, Cookie, \
+ CookieJar, DefaultCookiePolicy, LWPCookieJar, MozillaCookieJar, \
+ LoadError, lwp_cookie_str, DEFAULT_HTTP_PORT, escape_path, \
+ reach, is_HDN, domain_match, user_domain_match, request_path, \
+ request_port, request_host
+
class DateTimeTests(TestCase):
def test_time2isoz(self):
- from cookielib import time2isoz
-
base = 1019227000
day = 24*3600
self.assertEquals(time2isoz(base), "2002-04-19 14:36:40Z")
@@ -24,8 +29,6 @@ class DateTimeTests(TestCase):
"bad time2isoz format: %s %s" % (az, bz))
def test_http2time(self):
- from cookielib import http2time
-
def parse_date(text):
return time.gmtime(http2time(text))[:6]
@@ -38,8 +41,6 @@ class DateTimeTests(TestCase):
self.assertEquals(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))
def test_http2time_formats(self):
- from cookielib import http2time, time2isoz
-
# test http2time for supported dates. Test cases with 2 digit year
# will probably break in year 2044.
tests = [
@@ -77,8 +78,6 @@ class DateTimeTests(TestCase):
"'%s' => %s, %s, %s (%s)" % (s, t, t2, t3, test_t))
def test_http2time_garbage(self):
- from cookielib import http2time
-
for test in [
'',
'Garbage',
@@ -99,8 +98,6 @@ class DateTimeTests(TestCase):
class HeaderTests(TestCase):
def test_parse_ns_headers(self):
- from cookielib import parse_ns_headers
-
# quotes should be stripped
expected = [[('foo', 'bar'), ('expires', 2209069412), ('version', '0')]]
for hdr in [
@@ -112,24 +109,18 @@ class HeaderTests(TestCase):
def test_parse_ns_headers_special_names(self):
# names such as 'expires' are not special in first name=value pair
# of Set-Cookie: header
- from cookielib import parse_ns_headers
-
# Cookie with name 'expires'
hdr = 'expires=01 Jan 2040 22:23:32 GMT'
expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]]
self.assertEquals(parse_ns_headers([hdr]), expected)
def test_join_header_words(self):
- from cookielib import join_header_words
-
joined = join_header_words([[("foo", None), ("bar", "baz")]])
self.assertEquals(joined, "foo; bar=baz")
self.assertEquals(join_header_words([[]]), "")
def test_split_header_words(self):
- from cookielib import split_header_words
-
tests = [
("foo", [[("foo", None)]]),
("foo=bar", [[("foo", "bar")]]),
@@ -164,8 +155,6 @@ Got: '%s'
""" % (arg, expect, result))
def test_roundtrip(self):
- from cookielib import split_header_words, join_header_words
-
tests = [
("foo", "foo"),
("foo=bar", "foo=bar"),
@@ -218,8 +207,7 @@ def interact_netscape(cookiejar, url, *set_cookie_hdrs):
def _interact(cookiejar, url, set_cookie_hdrs, hdr_name):
"""Perform a single request / response cycle, returning Cookie: header."""
- from urllib2 import Request
- req = Request(url)
+ req = urllib2.Request(url)
cookiejar.add_cookie_header(req)
cookie_hdr = req.get_header("Cookie", "")
headers = []
@@ -233,7 +221,6 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name):
class FileCookieJarTests(TestCase):
def test_lwp_valueless_cookie(self):
# cookies with no value should be saved and loaded consistently
- from cookielib import LWPCookieJar
filename = support.TESTFN
c = LWPCookieJar()
interact_netscape(c, "http://www.acme.com/", 'boo')
@@ -248,7 +235,6 @@ class FileCookieJarTests(TestCase):
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
def test_bad_magic(self):
- from cookielib import LWPCookieJar, MozillaCookieJar, LoadError
# IOErrors (eg. file doesn't exist) are allowed to propagate
filename = support.TESTFN
for cookiejar_class in LWPCookieJar, MozillaCookieJar:
@@ -326,8 +312,7 @@ class CookieTests(TestCase):
# may require disk access -- in particular, with MSIECookieJar)
# This is only a rough check for performance reasons, so it's not too
# critical as long as it's sufficiently liberal.
- import cookielib, urllib2
- pol = cookielib.DefaultCookiePolicy()
+ pol = DefaultCookiePolicy()
for url, domain, ok in [
("http://foo.bar.com/", "blah.com", False),
("http://foo.bar.com/", "rhubarb.blah.com", False),
@@ -352,10 +337,8 @@ class CookieTests(TestCase):
else: self.assert_(not r)
def test_missing_value(self):
- from cookielib import MozillaCookieJar, lwp_cookie_str
-
# missing = sign in Cookie: header is regarded by Mozilla as a missing
- # name, and by cookielib as a missing value
+ # name, and by http.cookiejar as a missing value
filename = support.TESTFN
c = MozillaCookieJar(filename)
interact_netscape(c, "http://www.acme.com/", 'eggs')
@@ -388,8 +371,6 @@ class CookieTests(TestCase):
def test_rfc2109_handling(self):
# RFC 2109 cookies are handled as RFC 2965 or Netscape cookies,
# dependent on policy settings
- from cookielib import CookieJar, DefaultCookiePolicy
-
for rfc2109_as_netscape, rfc2965, version in [
# default according to rfc2965 if not explicitly specified
(None, False, 0),
@@ -419,8 +400,6 @@ class CookieTests(TestCase):
self.assertEqual(cookie2965.version, 1)
def test_ns_parser(self):
- from cookielib import CookieJar, DEFAULT_HTTP_PORT
-
c = CookieJar()
interact_netscape(c, "http://www.acme.com/",
'spam=eggs; DoMain=.acme.com; port; blArgh="feep"')
@@ -458,8 +437,6 @@ class CookieTests(TestCase):
def test_ns_parser_special_names(self):
# names such as 'expires' are not special in first name=value pair
# of Set-Cookie: header
- from cookielib import CookieJar
-
c = CookieJar()
interact_netscape(c, "http://www.acme.com/", 'expires=eggs')
interact_netscape(c, "http://www.acme.com/", 'version=eggs; spam=eggs')
@@ -469,8 +446,6 @@ class CookieTests(TestCase):
self.assert_('version' in cookies)
def test_expires(self):
- from cookielib import time2netscape, CookieJar
-
# if expires is in future, keep cookie...
c = CookieJar()
future = time2netscape(time.time()+3600)
@@ -509,8 +484,6 @@ class CookieTests(TestCase):
# XXX RFC 2965 expiry rules (some apply to V0 too)
def test_default_path(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
# RFC 2965
pol = DefaultCookiePolicy(rfc2965=True)
@@ -551,7 +524,6 @@ class CookieTests(TestCase):
self.assert_("/blah/rhubarb" in c._cookies["www.acme.com"])
def test_escape_path(self):
- from cookielib import escape_path
cases = [
# quoted safe
("/foo%2f/bar", "/foo%2F/bar"),
@@ -575,57 +547,50 @@ class CookieTests(TestCase):
self.assertEquals(escape_path(arg), result)
def test_request_path(self):
- from urllib2 import Request
- from cookielib import request_path
# with parameters
- req = Request("http://www.example.com/rheum/rhaponicum;"
- "foo=bar;sing=song?apples=pears&spam=eggs#ni")
+ req = urllib2.Request("http://www.example.com/rheum/rhaponicum;"
+ "foo=bar;sing=song?apples=pears&spam=eggs#ni")
self.assertEquals(request_path(req), "/rheum/rhaponicum;"
"foo=bar;sing=song?apples=pears&spam=eggs#ni")
# without parameters
- req = Request("http://www.example.com/rheum/rhaponicum?"
- "apples=pears&spam=eggs#ni")
+ req = urllib2.Request("http://www.example.com/rheum/rhaponicum?"
+ "apples=pears&spam=eggs#ni")
self.assertEquals(request_path(req), "/rheum/rhaponicum?"
"apples=pears&spam=eggs#ni")
# missing final slash
- req = Request("http://www.example.com")
+ req = urllib2.Request("http://www.example.com")
self.assertEquals(request_path(req), "/")
def test_request_port(self):
- from urllib2 import Request
- from cookielib import request_port, DEFAULT_HTTP_PORT
- req = Request("http://www.acme.com:1234/",
- headers={"Host": "www.acme.com:4321"})
+ req = urllib2.Request("http://www.acme.com:1234/",
+ headers={"Host": "www.acme.com:4321"})
self.assertEquals(request_port(req), "1234")
- req = Request("http://www.acme.com/",
- headers={"Host": "www.acme.com:4321"})
+ req = urllib2.Request("http://www.acme.com/",
+ headers={"Host": "www.acme.com:4321"})
self.assertEquals(request_port(req), DEFAULT_HTTP_PORT)
def test_request_host(self):
- from urllib2 import Request
- from cookielib import request_host
# this request is illegal (RFC2616, 14.2.3)
- req = Request("http://1.1.1.1/",
- headers={"Host": "www.acme.com:80"})
+ req = urllib2.Request("http://1.1.1.1/",
+ headers={"Host": "www.acme.com:80"})
# libwww-perl wants this response, but that seems wrong (RFC 2616,
# section 5.2, point 1., and RFC 2965 section 1, paragraph 3)
#self.assertEquals(request_host(req), "www.acme.com")
self.assertEquals(request_host(req), "1.1.1.1")
- req = Request("http://www.acme.com/",
- headers={"Host": "irrelevant.com"})
+ req = urllib2.Request("http://www.acme.com/",
+ headers={"Host": "irrelevant.com"})
self.assertEquals(request_host(req), "www.acme.com")
# not actually sure this one is valid Request object, so maybe should
# remove test for no host in url in request_host function?
- req = Request("/resource.html",
- headers={"Host": "www.acme.com"})
+ req = urllib2.Request("/resource.html",
+ headers={"Host": "www.acme.com"})
self.assertEquals(request_host(req), "www.acme.com")
# port shouldn't be in request-host
- req = Request("http://www.acme.com:2345/resource.html",
- headers={"Host": "www.acme.com:5432"})
+ req = urllib2.Request("http://www.acme.com:2345/resource.html",
+ headers={"Host": "www.acme.com:5432"})
self.assertEquals(request_host(req), "www.acme.com")
def test_is_HDN(self):
- from cookielib import is_HDN
self.assert_(is_HDN("foo.bar.com"))
self.assert_(is_HDN("1foo2.3bar4.5com"))
self.assert_(not is_HDN("192.168.1.1"))
@@ -636,7 +601,6 @@ class CookieTests(TestCase):
self.assert_(not is_HDN("foo."))
def test_reach(self):
- from cookielib import reach
self.assertEquals(reach("www.acme.com"), ".acme.com")
self.assertEquals(reach("acme.com"), "acme.com")
self.assertEquals(reach("acme.local"), ".local")
@@ -647,7 +611,6 @@ class CookieTests(TestCase):
self.assertEquals(reach("192.168.0.1"), "192.168.0.1")
def test_domain_match(self):
- from cookielib import domain_match, user_domain_match
self.assert_(domain_match("192.168.1.1", "192.168.1.1"))
self.assert_(not domain_match("192.168.1.1", ".168.1.1"))
self.assert_(domain_match("x.y.com", "x.Y.com"))
@@ -688,7 +651,6 @@ class CookieTests(TestCase):
# domain are rejected.
# XXX far from complete
- from cookielib import CookieJar
c = CookieJar()
interact_2965(c, "http://www.nasty.com/",
'foo=bar; domain=friendly.org; Version="1"')
@@ -697,8 +659,6 @@ class CookieTests(TestCase):
def test_strict_domain(self):
# Cookies whose domain is a country-code tld like .co.uk should
# not be set if CookiePolicy.strict_domain is true.
- from cookielib import CookieJar, DefaultCookiePolicy
-
cp = DefaultCookiePolicy(strict_domain=True)
cj = CookieJar(policy=cp)
interact_netscape(cj, "http://example.co.uk/", 'no=problemo')
@@ -714,8 +674,6 @@ class CookieTests(TestCase):
# Netscape: .www.bar.com, www.bar.com, .bar.com, bar.com, no domain
# should all get accepted, as should .acme.com, acme.com and no domain
# for 2-component domains like acme.com.
- from cookielib import CookieJar, DefaultCookiePolicy
-
c = CookieJar()
# two-component V0 domain is OK
@@ -761,8 +719,6 @@ class CookieTests(TestCase):
self.assertEquals(len(c), 4)
def test_two_component_domain_rfc2965(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
pol = DefaultCookiePolicy(rfc2965=True)
c = CookieJar(pol)
@@ -807,31 +763,28 @@ class CookieTests(TestCase):
self.assertEquals(len(c), 3)
def test_domain_allow(self):
- from cookielib import CookieJar, DefaultCookiePolicy
- from urllib2 import Request
-
c = CookieJar(policy=DefaultCookiePolicy(
blocked_domains=["acme.com"],
allowed_domains=["www.acme.com"]))
- req = Request("http://acme.com/")
+ req = urllib2.Request("http://acme.com/")
headers = ["Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/"]
res = FakeResponse(headers, "http://acme.com/")
c.extract_cookies(res, req)
self.assertEquals(len(c), 0)
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
self.assertEquals(len(c), 1)
- req = Request("http://www.coyote.com/")
+ req = urllib2.Request("http://www.coyote.com/")
res = FakeResponse(headers, "http://www.coyote.com/")
c.extract_cookies(res, req)
self.assertEquals(len(c), 1)
# set a cookie with non-allowed domain...
- req = Request("http://www.coyote.com/")
+ req = urllib2.Request("http://www.coyote.com/")
res = FakeResponse(headers, "http://www.coyote.com/")
cookies = c.make_cookies(res, req)
c.set_cookie(cookies[0])
@@ -841,15 +794,12 @@ class CookieTests(TestCase):
self.assert_(not req.has_header("Cookie"))
def test_domain_block(self):
- from cookielib import CookieJar, DefaultCookiePolicy
- from urllib2 import Request
-
pol = DefaultCookiePolicy(
rfc2965=True, blocked_domains=[".acme.com"])
c = CookieJar(policy=pol)
headers = ["Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/"]
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
self.assertEquals(len(c), 0)
@@ -859,11 +809,11 @@ class CookieTests(TestCase):
self.assertEquals(len(c), 1)
c.clear()
- req = Request("http://www.roadrunner.net/")
+ req = urllib2.Request("http://www.roadrunner.net/")
res = FakeResponse(headers, "http://www.roadrunner.net/")
c.extract_cookies(res, req)
self.assertEquals(len(c), 1)
- req = Request("http://www.roadrunner.net/")
+ req = urllib2.Request("http://www.roadrunner.net/")
c.add_cookie_header(req)
self.assert_((req.has_header("Cookie") and
req.has_header("Cookie2")))
@@ -874,7 +824,7 @@ class CookieTests(TestCase):
self.assertEquals(len(c), 1)
# set a cookie with blocked domain...
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
cookies = c.make_cookies(res, req)
c.set_cookie(cookies[0])
@@ -884,8 +834,6 @@ class CookieTests(TestCase):
self.assert_(not req.has_header("Cookie"))
def test_secure(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
for ns in True, False:
for whitespace in " ", "":
c = CookieJar()
@@ -909,7 +857,6 @@ class CookieTests(TestCase):
"secure cookie registered non-secure")
def test_quote_cookie_value(self):
- from cookielib import CookieJar, DefaultCookiePolicy
c = CookieJar(policy=DefaultCookiePolicy(rfc2965=True))
interact_2965(c, "http://www.acme.com/", r'foo=\b"a"r; Version=1')
h = interact_2965(c, "http://www.acme.com/")
@@ -917,19 +864,15 @@ class CookieTests(TestCase):
def test_missing_final_slash(self):
# Missing slash from request URL's abs_path should be assumed present.
- from cookielib import CookieJar, DefaultCookiePolicy
- from urllib2 import Request
url = "http://www.acme.com"
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
interact_2965(c, url, "foo=bar; Version=1")
- req = Request(url)
+ req = urllib2.Request(url)
self.assertEquals(len(c), 1)
c.add_cookie_header(req)
self.assert_(req.has_header("Cookie"))
def test_domain_mirror(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
pol = DefaultCookiePolicy(rfc2965=True)
c = CookieJar(pol)
@@ -953,8 +896,6 @@ class CookieTests(TestCase):
self.assert_('$Domain="bar.com"' in h, "domain not returned")
def test_path_mirror(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
pol = DefaultCookiePolicy(rfc2965=True)
c = CookieJar(pol)
@@ -971,8 +912,6 @@ class CookieTests(TestCase):
self.assert_('$Path="/"' in h, "path not returned")
def test_port_mirror(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
pol = DefaultCookiePolicy(rfc2965=True)
c = CookieJar(pol)
@@ -1005,8 +944,6 @@ class CookieTests(TestCase):
"values")
def test_no_return_comment(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
url = "http://foo.bar.com/"
interact_2965(c, url, 'spam=eggs; Version=1; '
@@ -1018,8 +955,6 @@ class CookieTests(TestCase):
"Comment or CommentURL cookie-attributes returned to server")
def test_Cookie_iterator(self):
- from cookielib import CookieJar, Cookie, DefaultCookiePolicy
-
cs = CookieJar(DefaultCookiePolicy(rfc2965=True))
# add some random cookies
interact_2965(cs, "http://blah.spam.org/", 'foo=eggs; Version=1; '
@@ -1052,8 +987,6 @@ class CookieTests(TestCase):
i = i + 1
def test_parse_ns_headers(self):
- from cookielib import parse_ns_headers
-
# missing domain value (invalid cookie)
self.assertEquals(
parse_ns_headers(["foo=bar; path=/; domain"]),
@@ -1076,10 +1009,8 @@ class CookieTests(TestCase):
def test_bad_cookie_header(self):
def cookiejar_from_cookie_headers(headers):
- from cookielib import CookieJar
- from urllib2 import Request
c = CookieJar()
- req = Request("http://www.example.com/")
+ req = urllib2.Request("http://www.example.com/")
r = FakeResponse(headers, "http://www.example.com/")
c.extract_cookies(r, req)
return c
@@ -1108,9 +1039,6 @@ class LWPCookieTests(TestCase):
# Tests taken from libwww-perl, with a few modifications and additions.
def test_netscape_example_1(self):
- from cookielib import CookieJar, DefaultCookiePolicy
- from urllib2 import Request
-
#-------------------------------------------------------------------
# First we check that it works for the original example at
# http://www.netscape.com/newsref/std/cookie_spec.html
@@ -1153,9 +1081,9 @@ class LWPCookieTests(TestCase):
c = CookieJar(DefaultCookiePolicy(rfc2965 = True))
- #req = Request("http://1.1.1.1/",
+ #req = urllib2.Request("http://1.1.1.1/",
# headers={"Host": "www.acme.com:80"})
- req = Request("http://www.acme.com:80/",
+ req = urllib2.Request("http://www.acme.com:80/",
headers={"Host": "www.acme.com:80"})
headers.append(
@@ -1164,7 +1092,7 @@ class LWPCookieTests(TestCase):
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
c.add_cookie_header(req)
self.assertEqual(req.get_header("Cookie"), "CUSTOMER=WILE_E_COYOTE")
@@ -1174,7 +1102,7 @@ class LWPCookieTests(TestCase):
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- req = Request("http://www.acme.com/foo/bar")
+ req = urllib2.Request("http://www.acme.com/foo/bar")
c.add_cookie_header(req)
h = req.get_header("Cookie")
@@ -1185,7 +1113,7 @@ class LWPCookieTests(TestCase):
res = FakeResponse(headers, "http://www.acme.com")
c.extract_cookies(res, req)
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
c.add_cookie_header(req)
h = req.get_header("Cookie")
@@ -1193,7 +1121,7 @@ class LWPCookieTests(TestCase):
"CUSTOMER=WILE_E_COYOTE" in h and
"SHIPPING=FEDEX" not in h)
- req = Request("http://www.acme.com/foo/")
+ req = urllib2.Request("http://www.acme.com/foo/")
c.add_cookie_header(req)
h = req.get_header("Cookie")
@@ -1202,9 +1130,6 @@ class LWPCookieTests(TestCase):
h.startswith("SHIPPING=FEDEX;")))
def test_netscape_example_2(self):
- from cookielib import CookieJar
- from urllib2 import Request
-
# Second Example transaction sequence:
#
# Assume all mappings from above have been cleared.
@@ -1231,13 +1156,13 @@ class LWPCookieTests(TestCase):
c = CookieJar()
headers = []
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
headers.append("Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/")
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- req = Request("http://www.acme.com/")
+ req = urllib2.Request("http://www.acme.com/")
c.add_cookie_header(req)
self.assertEquals(req.get_header("Cookie"),
@@ -1248,7 +1173,7 @@ class LWPCookieTests(TestCase):
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- req = Request("http://www.acme.com/ammo")
+ req = urllib2.Request("http://www.acme.com/ammo")
c.add_cookie_header(req)
self.assert_(re.search(r"PART_NUMBER=RIDING_ROCKET_0023;\s*"
@@ -1256,7 +1181,6 @@ class LWPCookieTests(TestCase):
req.get_header("Cookie")))
def test_ietf_example_1(self):
- from cookielib import CookieJar, DefaultCookiePolicy
#-------------------------------------------------------------------
# Then we test with the examples from draft-ietf-http-state-man-mec-03.txt
#
@@ -1371,8 +1295,6 @@ class LWPCookieTests(TestCase):
# contains all the cookies received so far.
def test_ietf_example_2(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
# 5.2 Example 2
#
# This example illustrates the effect of the Path attribute. All detail
@@ -1428,8 +1350,6 @@ class LWPCookieTests(TestCase):
def test_rejection(self):
# Test rejection of Set-Cookie2 responses based on domain, path, port.
- from cookielib import DefaultCookiePolicy, LWPCookieJar
-
pol = DefaultCookiePolicy(rfc2965=True)
c = LWPCookieJar(policy=pol)
@@ -1522,8 +1442,6 @@ class LWPCookieTests(TestCase):
def test_url_encoding(self):
# Try some URL encodings of the PATHs.
# (the behaviour here has changed from libwww-perl)
- from cookielib import CookieJar, DefaultCookiePolicy
-
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
interact_2965(c, "http://www.acme.com/foo%2f%25/%3c%3c%0Anew%E5/%E5",
"foo = bar; version = 1")
@@ -1543,8 +1461,6 @@ class LWPCookieTests(TestCase):
def test_mozilla(self):
# Save / load Mozilla/Netscape cookie file format.
- from cookielib import MozillaCookieJar, DefaultCookiePolicy
-
year_plus_one = time.localtime()[0] + 1
filename = support.TESTFN
@@ -1586,12 +1502,9 @@ class LWPCookieTests(TestCase):
def test_netscape_misc(self):
# Some additional Netscape cookies tests.
- from cookielib import CookieJar
- from urllib2 import Request
-
c = CookieJar()
headers = []
- req = Request("http://foo.bar.acme.com/foo")
+ req = urllib2.Request("http://foo.bar.acme.com/foo")
# Netscape allows a host part that contains dots
headers.append("Set-Cookie: Customer=WILE_E_COYOTE; domain=.acme.com")
@@ -1605,7 +1518,7 @@ class LWPCookieTests(TestCase):
res = FakeResponse(headers, "http://www.acme.com/foo")
c.extract_cookies(res, req)
- req = Request("http://foo.bar.acme.com/foo")
+ req = urllib2.Request("http://foo.bar.acme.com/foo")
c.add_cookie_header(req)
self.assert_(
"PART_NUMBER=3,4" in req.get_header("Cookie") and
@@ -1613,8 +1526,6 @@ class LWPCookieTests(TestCase):
def test_intranet_domains_2965(self):
# Test handling of local intranet hostnames without a dot.
- from cookielib import CookieJar, DefaultCookiePolicy
-
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
interact_2965(c, "http://example/",
"foo1=bar; PORT; Discard; Version=1;")
@@ -1627,8 +1538,6 @@ class LWPCookieTests(TestCase):
self.assert_("foo2=bar" in cookie and len(c) == 3)
def test_intranet_domains_ns(self):
- from cookielib import CookieJar, DefaultCookiePolicy
-
c = CookieJar(DefaultCookiePolicy(rfc2965 = False))
interact_netscape(c, "http://example/", "foo1=bar")
cookie = interact_netscape(c, "http://example/",
@@ -1641,9 +1550,6 @@ class LWPCookieTests(TestCase):
self.assertEquals(len(c), 2)
def test_empty_path(self):
- from cookielib import CookieJar, DefaultCookiePolicy
- from urllib2 import Request
-
# Test for empty path
# Broken web-server ORION/1.3.38 returns to the client response like
#
@@ -1654,12 +1560,12 @@ class LWPCookieTests(TestCase):
c = CookieJar(DefaultCookiePolicy(rfc2965 = True))
headers = []
- req = Request("http://www.ants.com/")
+ req = urllib2.Request("http://www.ants.com/")
headers.append("Set-Cookie: JSESSIONID=ABCDERANDOM123; Path=")
res = FakeResponse(headers, "http://www.ants.com/")
c.extract_cookies(res, req)
- req = Request("http://www.ants.com/")
+ req = urllib2.Request("http://www.ants.com/")
c.add_cookie_header(req)
self.assertEquals(req.get_header("Cookie"),
@@ -1667,7 +1573,7 @@ class LWPCookieTests(TestCase):
self.assertEquals(req.get_header("Cookie2"), '$Version="1"')
# missing path in the request URI
- req = Request("http://www.ants.com:8080")
+ req = urllib2.Request("http://www.ants.com:8080")
c.add_cookie_header(req)
self.assertEquals(req.get_header("Cookie"),
@@ -1675,15 +1581,12 @@ class LWPCookieTests(TestCase):
self.assertEquals(req.get_header("Cookie2"), '$Version="1"')
def test_session_cookies(self):
- from cookielib import CookieJar
- from urllib2 import Request
-
year_plus_one = time.localtime()[0] + 1
# Check session cookies are deleted properly by
# CookieJar.clear_session_cookies method
- req = Request('http://www.perlmeister.com/scripts')
+ req = urllib2.Request('http://www.perlmeister.com/scripts')
headers = []
headers.append("Set-Cookie: s1=session;Path=/scripts")
headers.append("Set-Cookie: p1=perm; Domain=.perlmeister.com;"
diff --git a/Lib/test/test_cookie.py b/Lib/test/test_http_cookies.py
index 07d29e1..a336c82 100644
--- a/Lib/test/test_cookie.py
+++ b/Lib/test/test_http_cookies.py
@@ -1,8 +1,8 @@
-# Simple test suite for Cookie.py
+# Simple test suite for http/cookies.py
from test.support import run_unittest, run_doctest
import unittest
-import Cookie
+from http import cookies
import warnings
warnings.filterwarnings("ignore",
@@ -34,7 +34,7 @@ class CookieTests(unittest.TestCase):
]
for case in cases:
- C = Cookie.SimpleCookie()
+ C = cookies.SimpleCookie()
C.load(case['data'])
self.assertEqual(repr(C), case['repr'])
self.assertEqual(C.output(sep='\n'), case['output'])
@@ -42,7 +42,7 @@ class CookieTests(unittest.TestCase):
self.assertEqual(C[k].value, v)
def test_load(self):
- C = Cookie.SimpleCookie()
+ C = cookies.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
@@ -68,7 +68,7 @@ class CookieTests(unittest.TestCase):
def test_quoted_meta(self):
# Try cookie with quoted meta-data
- C = Cookie.SimpleCookie()
+ C = cookies.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
self.assertEqual(C['Customer']['version'], '1')
@@ -76,7 +76,7 @@ class CookieTests(unittest.TestCase):
def test_main():
run_unittest(CookieTests)
- run_doctest(Cookie)
+ run_doctest(cookies)
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 7a77cff..ff4cf9b 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1,4 +1,4 @@
-import httplib
+import http.client as httplib
import io
import socket
@@ -48,8 +48,6 @@ class HeaderTests(TestCase):
# Some headers are added automatically, but should not be added by
# .request() if they are explicitly set.
- import httplib
-
class HeaderCountingBuffer(list):
def __init__(self):
self.count = {}
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index cc79cb8..02be57a 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -4,16 +4,15 @@ Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
"""
-from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
-from CGIHTTPServer import CGIHTTPRequestHandler
+from http.server import BaseHTTPRequestHandler, HTTPServer, \
+ SimpleHTTPRequestHandler, CGIHTTPRequestHandler
import os
import sys
import base64
import shutil
import urllib
-import httplib
+import http.client
import tempfile
import threading
@@ -59,7 +58,7 @@ class BaseTestCase(unittest.TestCase):
self.thread.stop()
def request(self, uri, method='GET', body=None, headers={}):
- self.connection = httplib.HTTPConnection('localhost', self.PORT)
+ self.connection = http.client.HTTPConnection('localhost', self.PORT)
self.connection.request(method, uri, body, headers)
return self.connection.getresponse()
@@ -92,7 +91,7 @@ class BaseHTTPServerTestCase(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
- self.con = httplib.HTTPConnection('localhost', self.PORT)
+ self.con = http.client.HTTPConnection('localhost', self.PORT)
self.con.connect()
def test_command(self):
@@ -343,7 +342,7 @@ class CGIHTTPServerTestCase(BaseTestCase):
def test_main(verbose=None):
try:
cwd = os.getcwd()
- support.run_unittest(#BaseHTTPServerTestCase,
+ support.run_unittest(BaseHTTPServerTestCase,
SimpleHTTPServerTestCase,
CGIHTTPServerTestCase
)
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index ca0aefc..e8eb94e 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -168,7 +168,6 @@ class PyclbrTest(TestCase):
'getproxies_internetconfig',)) # not on all platforms
cm('pickle')
cm('aifc', ignore=('openfp',)) # set with = in module
- cm('Cookie', ignore=('Cookie',)) # Cookie is an alias for SmartCookie
cm('sre_parse', ignore=('dump',)) # from sre_constants import *
cm('pdb')
cm('pydoc')
diff --git a/Lib/test/test_shelve.py b/Lib/test/test_shelve.py
index 5fb4641..b2ed87d 100644
--- a/Lib/test/test_shelve.py
+++ b/Lib/test/test_shelve.py
@@ -3,7 +3,7 @@ import shelve
import glob
from test import support
from collections import MutableMapping
-from test.test_anydbm import dbm_iterator
+from test.test_dbm import dbm_iterator
def L1(s):
return s.decode("latin-1")
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index d12968c..d664582 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -855,7 +855,7 @@ class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase):
In this case (and in this case only), it should be possible to
create a file object, read a line from it, create another file
object, read another line from it, without loss of data in the
- first file object's buffer. Note that httplib relies on this
+ first file object's buffer. Note that http.client relies on this
when reading multiple requests from the same socket."""
bufsize = 0 # Use unbuffered mode
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 4f884f0..ea3efd6 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -15,8 +15,7 @@ import shutil
import traceback
import asyncore
-from BaseHTTPServer import HTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
+from http.server import HTTPServer, SimpleHTTPRequestHandler
# Optionally test SSL support, if we have it in the tested platform
skip_expected = False
diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py
index 292722d..18101e7 100644
--- a/Lib/test/test_sundry.py
+++ b/Lib/test/test_sundry.py
@@ -8,7 +8,6 @@ import warnings
class TestUntestedModules(unittest.TestCase):
def test_at_least_import_untested_modules(self):
with support.catch_warning():
- import CGIHTTPServer
import aifc
import bdb
import cgitb
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 7db281c..b14510f 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1,7 +1,7 @@
"""Regresssion tests for urllib"""
import urllib
-import httplib
+import http.client
import io
import unittest
from test import support
@@ -107,14 +107,14 @@ class urlopen_HttpTests(unittest.TestCase):
def readline(self, length=None):
if self.closed: return b""
return io.BytesIO.readline(self, length)
- class FakeHTTPConnection(httplib.HTTPConnection):
+ class FakeHTTPConnection(http.client.HTTPConnection):
def connect(self):
self.sock = FakeSocket(fakedata)
- self._connection_class = httplib.HTTPConnection
- httplib.HTTPConnection = FakeHTTPConnection
+ self._connection_class = http.client.HTTPConnection
+ http.client.HTTPConnection = FakeHTTPConnection
def unfakehttp(self):
- httplib.HTTPConnection = self._connection_class
+ http.client.HTTPConnection = self._connection_class
def test_read(self):
self.fakehttp(b"Hello!")
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index cb730e2..3386800 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -77,7 +77,7 @@ def test_request_headers_methods():
Note the case normalization of header names here, to .capitalize()-case.
This should be preserved for backwards-compatibility. (In the HTTP case,
normalization to .title()-case is done by urllib2 before sending headers to
- httplib).
+ http.client).
>>> url = "http://example.com"
>>> r = Request(url, headers={"Spam-eggs": "blah"})
@@ -348,12 +348,12 @@ class MockHTTPHandler(urllib2.BaseHandler):
self._count = 0
self.requests = []
def http_open(self, req):
- import mimetools, httplib, copy
+ import mimetools, http.client, copy
from io import StringIO
self.requests.append(copy.deepcopy(req))
if self._count == 0:
self._count = self._count + 1
- name = httplib.responses[self.code]
+ name = http.client.responses[self.code]
msg = mimetools.Message(StringIO(self.headers))
return self.parent.error(
"http", req, MockFile(), self.code, name, msg)
@@ -875,9 +875,8 @@ class HandlerTests(unittest.TestCase):
def test_cookie_redirect(self):
# cookies shouldn't leak into redirected requests
- from cookielib import CookieJar
-
- from test.test_cookielib import interact_netscape
+ from http.cookiejar import CookieJar
+ from test.test_http_cookiejar import interact_netscape
cj = CookieJar()
interact_netscape(cj, "http://www.example.com/", "spam=eggs")
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 6bf1820..6c877d9 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -4,29 +4,29 @@ import mimetools
import threading
import urlparse
import urllib2
-import BaseHTTPServer
+import http.server
import unittest
import hashlib
from test import support
# Loopback http server infrastructure
-class LoopbackHttpServer(BaseHTTPServer.HTTPServer):
+class LoopbackHttpServer(http.server.HTTPServer):
"""HTTP server w/ a few modifications that make it useful for
loopback testing purposes.
"""
def __init__(self, server_address, RequestHandlerClass):
- BaseHTTPServer.HTTPServer.__init__(self,
- server_address,
- RequestHandlerClass)
+ http.server.HTTPServer.__init__(self,
+ server_address,
+ RequestHandlerClass)
# Set the timeout of our listening socket really low so
# that we can stop the server easily.
self.socket.settimeout(1.0)
def get_request(self):
- """BaseHTTPServer method, overridden."""
+ """HTTPServer method, overridden."""
request, client_address = self.socket.accept()
@@ -188,7 +188,7 @@ class DigestAuthHandler:
# Proxy test infrastructure
-class FakeProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+class FakeProxyHandler(http.server.BaseHTTPRequestHandler):
"""This is a 'fake proxy' that makes it look like the entire
internet has gone down due to a sudden zombie invasion. It main
utility is in providing us with authentication support for
@@ -283,7 +283,7 @@ class ProxyAuthTests(unittest.TestCase):
def GetRequestHandler(responses):
- class FakeHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+ class FakeHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
server_version = "TestHTTP/"
requests = []
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index 89e48cb..990d3da 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -33,7 +33,7 @@ class AuthTests(unittest.TestCase):
## could be used to HTTP authentication.
#
# def test_basic_auth(self):
-# import httplib
+# import http.client
#
# test_url = "http://www.python.org/test/test_urllib2/basic_auth"
# test_hostport = "www.python.org"
@@ -61,14 +61,14 @@ class AuthTests(unittest.TestCase):
# # reasons, let's not implement it! (it's already implemented for proxy
# # specification strings (that is, URLs or authorities specifying a
# # proxy), so we must keep that)
-# self.assertRaises(httplib.InvalidURL,
+# self.assertRaises(http.client.InvalidURL,
# urllib2.urlopen, "http://evil:thing@example.com")
class CloseSocketTest(unittest.TestCase):
def test_close(self):
- import socket, httplib, gc
+ import socket, http.client, gc
# calling .close() on urllib2's response objects should close the
# underlying socket
@@ -77,7 +77,7 @@ class CloseSocketTest(unittest.TestCase):
response = _urlopen_with_retry("http://www.python.org/")
abused_fileobject = response.fp
httpresponse = abused_fileobject.raw
- self.assert_(httpresponse.__class__ is httplib.HTTPResponse)
+ self.assert_(httpresponse.__class__ is http.client.HTTPResponse)
fileobject = httpresponse.fp
self.assert_(not fileobject.closed)
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 25a9c9d..8325496 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -7,7 +7,7 @@ import xmlrpc.client as xmlrpclib
import xmlrpc.server
import threading
import mimetools
-import httplib
+import http.client
import socket
import os
from test import support
@@ -340,9 +340,9 @@ class SimpleServerTestCase(unittest.TestCase):
# [ch] The test 404 is causing lots of false alarms.
def XXXtest_404(self):
- # send POST with httplib, it should return 404 header and
+ # send POST with http.client, it should return 404 header and
# 'Not Found' message.
- conn = httplib.HTTPConnection('localhost', PORT)
+ conn = http.client.HTTPConnection('localhost', PORT)
conn.request('POST', '/this-is-not-valid')
response = conn.getresponse()
conn.close()
diff --git a/Lib/test/test_xmlrpc_net.py b/Lib/test/test_xmlrpc_net.py
index 2525254..f6ebbf0 100644
--- a/Lib/test/test_xmlrpc_net.py
+++ b/Lib/test/test_xmlrpc_net.py
@@ -6,7 +6,7 @@ import sys
import unittest
from test import support
-import xmlrpclib.client as xmlrpclib
+import xmlrpc.client as xmlrpclib
class CurrentTimeTest(unittest.TestCase):