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.
This commit is contained in:
Greg Stein 2001-08-18 09:20:23 +00:00
parent 6cb0d4c632
commit 81937a4a12
1 changed files with 26 additions and 15 deletions

View File

@ -663,7 +663,7 @@ class HTTP:
_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."
# some joker passed 0 explicitly, meaning default port
@ -673,18 +673,19 @@ def __init__(self, host='', port=None, **x509):
# 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
# will call connect before then, with a proper host.
self._conn = self._connection_class(host, port)
# set up delegation to flesh out interface
self.send = self._conn.send
self.putrequest = self._conn.putrequest
self.endheaders = self._conn.endheaders
self._conn._http_vsn = self._http_vsn
self._conn._http_vsn_str = self._http_vsn_str
self._setup(self._connection_class(host, port))
# 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')
def _setup(self, conn):
self._conn = conn
# set up delegation to flesh out interface
self.send = conn.send
self.putrequest = conn.putrequest
self.endheaders = conn.endheaders
self.set_debuglevel = conn.set_debuglevel
conn._http_vsn = self._http_vsn
conn._http_vsn_str = self._http_vsn_str
self.file = None
@ -695,9 +696,6 @@ def connect(self, host=None, port=None):
self._conn._set_hostport(host, port)
self._conn.connect()
def set_debuglevel(self, debuglevel):
self._conn.set_debuglevel(debuglevel)
def getfile(self):
"Provide a getfile, since the superclass' does not use this concept."
return self.file
@ -755,6 +753,19 @@ class HTTPS(HTTP):
_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):
pass