Added timeout support to HTTPSConnection, through the
socket.create_connection function. Also added a small
test for this, and updated NEWS file.
diff --git a/Lib/httplib.py b/Lib/httplib.py
index d420f46..badaf1a 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -1124,16 +1124,15 @@
default_port = HTTPS_PORT
def __init__(self, host, port=None, key_file=None, cert_file=None,
- strict=None):
- HTTPConnection.__init__(self, host, port, strict)
+ strict=None, timeout=None):
+ HTTPConnection.__init__(self, host, port, strict, timeout)
self.key_file = key_file
self.cert_file = cert_file
def connect(self):
"Connect to a host on a given (SSL) port."
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((self.host, self.port))
+ sock = socket.create_connection((self.host, self.port), self.timeout)
ssl = socket.ssl(sock, self.key_file, self.cert_file)
self.sock = FakeSocket(sock, ssl)
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 035f0b9..9238eea 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -194,8 +194,16 @@
httpConn.close()
+class HTTPSTimeoutTest(TestCase):
+# XXX Here should be tests for HTTPS, there isn't any right now!
+
+ def test_attributes(self):
+ # simple test to check it's storing it
+ h = httplib.HTTPSConnection(HOST, PORT, timeout=30)
+ self.assertEqual(h.timeout, 30)
+
def test_main(verbose=None):
- test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest)
+ test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, HTTPSTimeoutTest)
if __name__ == '__main__':
test_main()