Added an optional timeout parameter to function urllib2.urlopen,
with tests in test_urllib2net.py (must have network resource
enabled to execute them). Also modified test_urllib2.py because
testing mock classes must take it into acount. Docs are also
updated.
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 1a2986a..c9dcf5e 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -545,7 +545,7 @@
class NullFTPHandler(urllib2.FTPHandler):
def __init__(self, data): self.data = data
- def connect_ftp(self, user, passwd, host, port, dirs):
+ def connect_ftp(self, user, passwd, host, port, dirs, timeout=None):
self.user, self.passwd = user, passwd
self.host, self.port = host, port
self.dirs = dirs
@@ -568,7 +568,9 @@
"localhost", ftplib.FTP_PORT, "A",
[], "baz.gif", None), # XXX really this should guess image/gif
]:
- r = h.ftp_open(Request(url))
+ req = Request(url)
+ req.timeout = None
+ r = h.ftp_open(req)
# ftp authentication not yet implemented by FTPHandler
self.assert_(h.user == h.passwd == "")
self.assertEqual(h.host, socket.gethostbyname(host))
@@ -683,8 +685,9 @@
self.req_headers = []
self.data = None
self.raise_on_endheaders = False
- def __call__(self, host):
+ def __call__(self, host, timeout=None):
self.host = host
+ self.timeout = timeout
return self
def set_debuglevel(self, level):
self.level = level
@@ -707,6 +710,7 @@
url = "http://example.com/"
for method, data in [("GET", None), ("POST", "blah")]:
req = Request(url, data, {"Foo": "bar"})
+ req.timeout = None
req.add_unredirected_header("Spam", "eggs")
http = MockHTTPClass()
r = h.do_open(http, req)