Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions superlance/timeoutconn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from superlance.compat import httplib
import socket
import ssl


class TimeoutHTTPConnection(httplib.HTTPConnection):
"""A customised HTTPConnection allowing a per-connection
Expand All @@ -12,7 +14,7 @@ def connect(self):

e = "getaddrinfo returns an empty list"
for res in socket.getaddrinfo(self.host, self.port,
0, socket.SOCK_STREAM):
0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.sock = socket.socket(af, socktype, proto)
Expand All @@ -28,6 +30,7 @@ def connect(self):
if not self.sock:
raise socket.error(e)


class TimeoutHTTPSConnection(httplib.HTTPSConnection):
timeout = None

Expand All @@ -36,7 +39,6 @@ def connect(self):

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.timeout:
self.sock.settimeout(self.timeout)
sock.settimeout(self.timeout)
sock.connect((self.host, self.port))
ssl = socket.ssl(sock, self.key_file, self.cert_file)
self.sock = httplib.FakeSocket(sock, ssl)
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)