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