Commit 81937a4a authored by Greg Stein's avatar Greg Stein

Resolve patch #449367.

For the HTTPS class (when available), ensure that the x509 certificate data
gets passed through to the HTTPSConnection class. Create a new
HTTPS.__init__ to do this, and refactor the HTTP.__init__ into a new _setup
method for both init's to call.

Note: this is solved differently from the patch, which advocated a new
**x509 parameter on the base HTTPConnection class. But that would open
HTTPConnection to arbitrary (ignored) parameters, so was not as desirable.
parent 6cb0d4c6
...@@ -663,7 +663,7 @@ class HTTP: ...@@ -663,7 +663,7 @@ class HTTP:
_connection_class = HTTPConnection _connection_class = HTTPConnection
def __init__(self, host='', port=None, **x509): def __init__(self, host='', port=None):
"Provide a default host, since the superclass requires one." "Provide a default host, since the superclass requires one."
# some joker passed 0 explicitly, meaning default port # some joker passed 0 explicitly, meaning default port
...@@ -673,18 +673,19 @@ class HTTP: ...@@ -673,18 +673,19 @@ class HTTP:
# Note that we may pass an empty string as the host; this will throw # Note that we may pass an empty string as the host; this will throw
# an error when we attempt to connect. Presumably, the client code # an error when we attempt to connect. Presumably, the client code
# will call connect before then, with a proper host. # will call connect before then, with a proper host.
self._conn = self._connection_class(host, port) self._setup(self._connection_class(host, port))
def _setup(self, conn):
self._conn = conn
# set up delegation to flesh out interface # set up delegation to flesh out interface
self.send = self._conn.send self.send = conn.send
self.putrequest = self._conn.putrequest self.putrequest = conn.putrequest
self.endheaders = self._conn.endheaders self.endheaders = conn.endheaders
self._conn._http_vsn = self._http_vsn self.set_debuglevel = conn.set_debuglevel
self._conn._http_vsn_str = self._http_vsn_str
conn._http_vsn = self._http_vsn
# we never actually use these for anything, but we keep them here for conn._http_vsn_str = self._http_vsn_str
# compatibility with post-1.5.2 CVS.
self.key_file = x509.get('key_file')
self.cert_file = x509.get('cert_file')
self.file = None self.file = None
...@@ -695,9 +696,6 @@ class HTTP: ...@@ -695,9 +696,6 @@ class HTTP:
self._conn._set_hostport(host, port) self._conn._set_hostport(host, port)
self._conn.connect() self._conn.connect()
def set_debuglevel(self, debuglevel):
self._conn.set_debuglevel(debuglevel)
def getfile(self): def getfile(self):
"Provide a getfile, since the superclass' does not use this concept." "Provide a getfile, since the superclass' does not use this concept."
return self.file return self.file
...@@ -755,6 +753,19 @@ if hasattr(socket, 'ssl'): ...@@ -755,6 +753,19 @@ if hasattr(socket, 'ssl'):
_connection_class = HTTPSConnection _connection_class = HTTPSConnection
def __init__(self, host='', port=None, **x509):
# provide a default host, pass the X509 cert info
# urf. compensate for bad input.
if port == 0:
port = None
self._setup(self._connection_class(host, port, **x509))
# we never actually use these for anything, but we keep them
# here for compatibility with post-1.5.2 CVS.
self.key_file = x509.get('key_file')
self.cert_file = x509.get('cert_file')
class HTTPException(Exception): class HTTPException(Exception):
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment