]> granicus.if.org Git - python/commitdiff
Added timeout support to HTTPSConnection, through the
authorFacundo Batista <facundobatista@gmail.com>
Mon, 21 May 2007 17:32:32 +0000 (17:32 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Mon, 21 May 2007 17:32:32 +0000 (17:32 +0000)
socket.create_connection function. Also added a small
test for this, and updated NEWS file.

Lib/httplib.py
Lib/test/test_httplib.py
Misc/NEWS

index d420f46710c706d0331a152b5beed51e2306f229..badaf1aadf692d66b6758528a58f80d96cb438d7 100644 (file)
@@ -1124,16 +1124,15 @@ class HTTPSConnection(HTTPConnection):
     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)
 
index 035f0b909e811db2eb79ef133ef38f41706ead8a..9238eea2029edb598d8e6678e2cb521718e6be25 100644 (file)
@@ -194,8 +194,16 @@ class TimeoutTest(TestCase):
         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()
index 264e5e790c0edd55fba86f1eff208dadd5ce2895..a0692c46e90ff308ab738566f6fc6bac731664a2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -259,7 +259,7 @@ Library
 
 - Patch #1676823: Added create_connection() to socket.py, which may be
   called with a timeout, and use it from httplib (whose HTTPConnection
-  now accepts an optional timeout).
+  and HTTPSConnection now accept an optional timeout).
 
 - Bug #978833: Revert r50844, as it broke _socketobject.dup.