|
|
|
@ -66,10 +66,9 @@ try:
|
|
|
|
|
import httplib
|
|
|
|
|
except ImportError:
|
|
|
|
|
# Python 3
|
|
|
|
|
import http.client as httplib
|
|
|
|
|
import http.client as httplib # type: ignore[no-redef]
|
|
|
|
|
|
|
|
|
|
import ansible.module_utils.six.moves.http_cookiejar as cookiejar
|
|
|
|
|
import ansible.module_utils.six.moves.urllib.request as urllib_request
|
|
|
|
|
import ansible.module_utils.six.moves.urllib.error as urllib_error
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.common.collections import Mapping
|
|
|
|
@ -84,8 +83,8 @@ try:
|
|
|
|
|
from urllib.request import AbstractHTTPHandler, BaseHandler
|
|
|
|
|
except ImportError:
|
|
|
|
|
# python2
|
|
|
|
|
import urllib2 as urllib_request
|
|
|
|
|
from urllib2 import AbstractHTTPHandler, BaseHandler
|
|
|
|
|
import urllib2 as urllib_request # type: ignore[no-redef]
|
|
|
|
|
from urllib2 import AbstractHTTPHandler, BaseHandler # type: ignore[no-redef]
|
|
|
|
|
|
|
|
|
|
urllib_request.HTTPRedirectHandler.http_error_308 = urllib_request.HTTPRedirectHandler.http_error_307
|
|
|
|
|
|
|
|
|
@ -269,7 +268,7 @@ try:
|
|
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
GSSAPI_IMP_ERR = traceback.format_exc()
|
|
|
|
|
HTTPGSSAPIAuthHandler = None # type: types.ModuleType | None
|
|
|
|
|
HTTPGSSAPIAuthHandler = None # type: types.ModuleType | None # type: ignore[no-redef]
|
|
|
|
|
|
|
|
|
|
if not HAS_MATCH_HOSTNAME:
|
|
|
|
|
# The following block of code is under the terms and conditions of the
|
|
|
|
@ -282,7 +281,7 @@ if not HAS_MATCH_HOSTNAME:
|
|
|
|
|
from _ssl import SSLCertVerificationError
|
|
|
|
|
CertificateError = SSLCertVerificationError # type: ignore[misc]
|
|
|
|
|
except ImportError:
|
|
|
|
|
class CertificateError(ValueError):
|
|
|
|
|
class CertificateError(ValueError): # type: ignore[no-redef]
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def _dnsname_match(dn, hostname):
|
|
|
|
@ -520,7 +519,7 @@ CustomHTTPSHandler = None
|
|
|
|
|
HTTPSClientAuthHandler = None
|
|
|
|
|
UnixHTTPSConnection = None
|
|
|
|
|
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler'):
|
|
|
|
|
class CustomHTTPSConnection(httplib.HTTPSConnection):
|
|
|
|
|
class CustomHTTPSConnection(httplib.HTTPSConnection): # type: ignore[no-redef]
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
|
|
|
|
|
self.context = None
|
|
|
|
@ -555,7 +554,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
|
|
|
|
|
else:
|
|
|
|
|
self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, ssl_version=PROTOCOL)
|
|
|
|
|
|
|
|
|
|
class CustomHTTPSHandler(urllib_request.HTTPSHandler):
|
|
|
|
|
class CustomHTTPSHandler(urllib_request.HTTPSHandler): # type: ignore[no-redef]
|
|
|
|
|
|
|
|
|
|
def https_open(self, req):
|
|
|
|
|
kwargs = {}
|
|
|
|
@ -571,7 +570,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
|
|
|
|
|
|
|
|
|
|
https_request = AbstractHTTPHandler.do_request_
|
|
|
|
|
|
|
|
|
|
class HTTPSClientAuthHandler(urllib_request.HTTPSHandler):
|
|
|
|
|
class HTTPSClientAuthHandler(urllib_request.HTTPSHandler): # type: ignore[no-redef]
|
|
|
|
|
'''Handles client authentication via cert/key
|
|
|
|
|
|
|
|
|
|
This is a fairly lightweight extension on HTTPSHandler, and can be used
|
|
|
|
@ -611,7 +610,7 @@ if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler
|
|
|
|
|
yield
|
|
|
|
|
httplib.HTTPConnection.connect = _connect
|
|
|
|
|
|
|
|
|
|
class UnixHTTPSConnection(httplib.HTTPSConnection):
|
|
|
|
|
class UnixHTTPSConnection(httplib.HTTPSConnection): # type: ignore[no-redef]
|
|
|
|
|
def __init__(self, unix_socket):
|
|
|
|
|
self._unix_socket = unix_socket
|
|
|
|
|
|
|
|
|
|