From 81937a4a12cfb316c196603c6bfd6bf0fdc73f41 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Sat, 18 Aug 2001 09:20:23 +0000 Subject: [PATCH] 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. --- Lib/httplib.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/Lib/httplib.py b/Lib/httplib.py index 7ab914953a0..0e0ec56d28e 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -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