summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGreg Stein <gstein@lyra.org>2001-08-18 09:20:23 (GMT)
committerGreg Stein <gstein@lyra.org>2001-08-18 09:20:23 (GMT)
commit81937a4a12cfb316c196603c6bfd6bf0fdc73f41 (patch)
tree41058a5399d5d9ea261c4ae9298f7ce8ac9e6ca9 /Lib
parent6cb0d4c632eb3a502d3097b133c1056788dc9b2c (diff)
downloadcpython-81937a4a12cfb316c196603c6bfd6bf0fdc73f41.zip
cpython-81937a4a12cfb316c196603c6bfd6bf0fdc73f41.tar.gz
cpython-81937a4a12cfb316c196603c6bfd6bf0fdc73f41.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/httplib.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 7ab9149..0e0ec56 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 @@ class HTTP:
# 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)
+ self._setup(self._connection_class(host, port))
+
+ def _setup(self, conn):
+ self._conn = conn
+
# 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
-
- # 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')
+ 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 @@ class HTTP:
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 @@ if hasattr(socket, 'ssl'):
_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