7 return sys.version_info[0] == 2 and sys.version_info[1] == 6
9 # wrapper around standartd https modules. Properly supports timeouts.
11 class HTTPSConnection(httplib.HTTPSConnection):
12 def __init__(self, host, port=None, key_file=None, cert_file=None,
13 strict=None, timeout = None):
14 httplib.HTTPSConnection.__init__(self, host, port, key_file, cert_file, strict)
15 self.timeout = float(timeout)
18 """Connect to a host on a given (SSL) port."""
20 from sfa.util.ssl_socket import SSLSocket
21 sock = socket.create_connection((self.host, self.port), self.timeout)
25 self.sock = SSLSocket(sock, self.key_file, self.cert_file)
27 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
28 sock.settimeout(self.timeout)
29 sock.connect((self.host, self.port))
30 ssl = socket.ssl(sock, self.key_file, self.cert_file)
31 self.sock = httplib.FakeSocket(sock, ssl)
33 class HTTPS(httplib.HTTPS):
34 def __init__(self, host='', port=None, key_file=None, cert_file=None,
35 strict=None, timeout = None):
36 # urf. compensate for bad input.
39 self._setup(HTTPSConnection(host, port, key_file, cert_file, strict, timeout))
41 # we never actually use these for anything, but we keep them
42 # here for compatibility with post-1.5.2 CVS.
43 self.key_file = key_file
44 self.cert_file = cert_file
46 def set_timeout(self, timeout):
48 self._conn.timeout = timeout