disabled python 2.6 fix
[sfa.git] / sfa / util / httpsProtocol.py
1 import httplib
2 import socket
3 import sys
4
5
6 def is_python26():
7     return False
8     #return sys.version_info[0] == 2 and sys.version_info[1] == 6
9
10 # wrapper around standartd https modules. Properly supports timeouts.  
11
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)
17
18     def connect(self):
19         """Connect to a host on a given (SSL) port."""
20         if is_python26():
21             from sfa.util.ssl_socket import SSLSocket
22             sock = socket.create_connection((self.host, self.port), self.timeout)
23             if self._tunnel_host:
24                 self.sock = sock
25                 self._tunnel()
26             self.sock = SSLSocket(sock, self.key_file, self.cert_file)
27         else:
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)
33
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.
38         if port == 0:
39             port = None
40         self._setup(HTTPSConnection(host, port, key_file, cert_file, strict, timeout))
41
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
46     
47     def set_timeout(self, timeout):
48         if is_python26():
49             self._conn.timeout = timeout