Move definition of UnixHTTPSConnection behind guard (#60049)

This allows module_utils/urls.py to not immediately fall over when run
against a python without SSL support.
pull/60122/head
Andrew Gaffney 5 years ago committed by GitHub
parent df6b8d2a4a
commit 32a8d8ae2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -397,6 +397,7 @@ class NoSSLError(SSLValidationError):
CustomHTTPSConnection = None
CustomHTTPSHandler = None
HTTPSClientAuthHandler = None
UnixHTTPSConnection = None
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler'):
class CustomHTTPSConnection(httplib.HTTPSConnection):
def __init__(self, *args, **kwargs):
@ -478,7 +479,6 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
return UnixHTTPSConnection(self._unix_socket)(host, **kwargs)
return httplib.HTTPSConnection(host, **kwargs)
@contextmanager
def unix_socket_patch_httpconnection_connect():
'''Monkey patch ``httplib.HTTPConnection.connect`` to be ``UnixHTTPConnection.connect``
@ -490,7 +490,6 @@ def unix_socket_patch_httpconnection_connect():
yield
httplib.HTTPConnection.connect = _connect
class UnixHTTPSConnection(httplib.HTTPSConnection):
def __init__(self, unix_socket):
self._unix_socket = unix_socket
@ -499,6 +498,10 @@ class UnixHTTPSConnection(httplib.HTTPSConnection):
# This method exists simply to ensure we monkeypatch
# httplib.HTTPConnection.connect to call UnixHTTPConnection.connect
with unix_socket_patch_httpconnection_connect():
# Disable pylint check for the super() call. It complains about UnixHTTPSConnection
# being a NoneType because of the initial definition above, but it won't actually
# be a NoneType when this code runs
# pylint: disable=bad-super-call
super(UnixHTTPSConnection, self).connect()
def __call__(self, *args, **kwargs):

Loading…
Cancel
Save