# Path: Custom/events/Zabbix/API/requests/packages/urllib3/util/ssl_.py
# def resolve_cert_reqs(candidate):
#     """
#     Resolves the argument to a numeric constant, which can be passed to
#     the wrap_socket function/method from the ssl module.
#     Defaults to :data:`ssl.CERT_NONE`.
#     If given a string it is assumed to be the name of the constant in the
#     :mod:`ssl` module or its abbrevation.
#     (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
#     If it's neither `None` nor a string we assume it is already the numeric
#     constant which can directly be passed to wrap_socket.
#     """
#     if candidate is None:
#         return CERT_NONE
# 
#     if isinstance(candidate, str):
#         res = getattr(ssl, candidate, None)
#         if res is None:
#             res = getattr(ssl, 'CERT_' + candidate)
#         return res
# 
#     return candidate
# 
# def resolve_ssl_version(candidate):
#     """
#     like resolve_cert_reqs
#     """
#     if candidate is None:
#         return PROTOCOL_SSLv23
# 
#     if isinstance(candidate, str):
#         res = getattr(ssl, candidate, None)
#         if res is None:
#             res = getattr(ssl, 'PROTOCOL_' + candidate)
#         return res
# 
#     return candidate
# 
# def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
#                     ca_certs=None, server_hostname=None,
#                     ssl_version=None):
#     """
#     All arguments except `server_hostname` have the same meaning as for
#     :func:`ssl.wrap_socket`
# 
#     :param server_hostname:
#         Hostname of the expected certificate
#     """
#     context = SSLContext(ssl_version)
#     context.verify_mode = cert_reqs
# 
#     # Disable TLS compression to migitate CRIME attack (issue #309)
#     OP_NO_COMPRESSION = 0x20000
#     context.options |= OP_NO_COMPRESSION
# 
#     if ca_certs:
#         try:
#             context.load_verify_locations(ca_certs)
#         # Py32 raises IOError
#         # Py33 raises FileNotFoundError
#         except Exception as e:  # Reraise as SSLError
#             raise SSLError(e)
#     if certfile:
#         # FIXME: This block needs a test.
#         context.load_cert_chain(certfile, keyfile)
#     if HAS_SNI:  # Platform-specific: OpenSSL with enabled SNI
#         return context.wrap_socket(sock, server_hostname=server_hostname)
#     return context.wrap_socket(sock)
# 
# def assert_fingerprint(cert, fingerprint):
#     """
#     Checks if given fingerprint matches the supplied certificate.
# 
#     :param cert:
#         Certificate as bytes object.
#     :param fingerprint:
#         Fingerprint as string of hexdigits, can be interspersed by colons.
#     """
# 
#     # Maps the length of a digest to a possible hash function producing
#     # this digest.
#     hashfunc_map = {
#         16: md5,
#         20: sha1
#     }
# 
#     fingerprint = fingerprint.replace(':', '').lower()
#     digest_length, odd = divmod(len(fingerprint), 2)
# 
#     if odd or digest_length not in hashfunc_map:
#         raise SSLError('Fingerprint is of invalid length.')
# 
#     # We need encode() here for py32; works on py2 and p33.
#     fingerprint_bytes = unhexlify(fingerprint.encode())
# 
#     hashfunc = hashfunc_map[digest_length]
# 
#     cert_digest = hashfunc(cert).digest()
# 
#     if not cert_digest == fingerprint_bytes:
#         raise SSLError('Fingerprints did not match. Expected "{0}", got "{1}".'
#                        .format(hexlify(fingerprint_bytes),
#                                hexlify(cert_digest)))


import datetime
import sys
import socket
import warnings
    import ssl
from socket import timeout as SocketTimeout
    from http.client import HTTPConnection as _HTTPConnection, HTTPException
    from httplib import HTTPConnection as _HTTPConnection, HTTPException
from .exceptions import (
    ConnectTimeoutError,
    SystemTimeWarning,
)
from .packages.ssl_match_hostname import match_hostname
from .packages import six
from .util.ssl_ import (
    resolve_cert_reqs,
    resolve_ssl_version,
    ssl_wrap_socket,
    assert_fingerprint,
)
from .util import connection

        self._prepare_conn(conn)
        self.sock = ssl.wrap_socket(conn, self.key_file, self.cert_file)


class VerifiedHTTPSConnection(HTTPSConnection):
    """
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    """
    cert_reqs = None
    ca_certs = None
    ssl_version = None
    assert_fingerprint = None

    def set_cert(self, key_file=None, cert_file=None,
                 cert_reqs=None, ca_certs=None,
                 assert_hostname=None, assert_fingerprint=None):

        self.key_file = key_file
        self.cert_file = cert_file
        self.cert_reqs = cert_reqs
        self.ca_certs = ca_certs
        self.assert_hostname = assert_hostname
        self.assert_fingerprint = assert_fingerprint

    def connect(self):
        # Add certificate verification
        conn = self._new_conn()

        resolved_cert_reqs = resolve_cert_reqs(self.cert_reqs)

# Path: Custom/events/Zabbix/API/requests/packages/urllib3/util/ssl_.py
# def resolve_cert_reqs(candidate):
#     """
#     Resolves the argument to a numeric constant, which can be passed to
#     the wrap_socket function/method from the ssl module.
#     Defaults to :data:`ssl.CERT_NONE`.
#     If given a string it is assumed to be the name of the constant in the
#     :mod:`ssl` module or its abbrevation.
#     (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
#     If it's neither `None` nor a string we assume it is already the numeric
#     constant which can directly be passed to wrap_socket.
#     """
#     if candidate is None:
#         return CERT_NONE
# 
#     if isinstance(candidate, str):
#         res = getattr(ssl, candidate, None)
#         if res is None:
#             res = getattr(ssl, 'CERT_' + candidate)
#         return res
# 
#     return candidate
# 
# def resolve_ssl_version(candidate):
#     """
#     like resolve_cert_reqs
#     """
#     if candidate is None:
#         return PROTOCOL_SSLv23
# 
#     if isinstance(candidate, str):
#         res = getattr(ssl, candidate, None)
#         if res is None:
#             res = getattr(ssl, 'PROTOCOL_' + candidate)
#         return res
# 
#     return candidate
# 
# def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
#                     ca_certs=None, server_hostname=None,
#                     ssl_version=None):
#     """
#     All arguments except `server_hostname` have the same meaning as for
#     :func:`ssl.wrap_socket`
# 
#     :param server_hostname:
#         Hostname of the expected certificate
#     """
#     context = SSLContext(ssl_version)
#     context.verify_mode = cert_reqs
# 
#     # Disable TLS compression to migitate CRIME attack (issue #309)
#     OP_NO_COMPRESSION = 0x20000
#     context.options |= OP_NO_COMPRESSION
# 
#     if ca_certs:
#         try:
#             context.load_verify_locations(ca_certs)
#         # Py32 raises IOError
#         # Py33 raises FileNotFoundError
#         except Exception as e:  # Reraise as SSLError
#             raise SSLError(e)
#     if certfile:
#         # FIXME: This block needs a test.
#         context.load_cert_chain(certfile, keyfile)
#     if HAS_SNI:  # Platform-specific: OpenSSL with enabled SNI
#         return context.wrap_socket(sock, server_hostname=server_hostname)
#     return context.wrap_socket(sock)
# 
# def assert_fingerprint(cert, fingerprint):
#     """
#     Checks if given fingerprint matches the supplied certificate.
# 
#     :param cert:
#         Certificate as bytes object.
#     :param fingerprint:
#         Fingerprint as string of hexdigits, can be interspersed by colons.
#     """
# 
#     # Maps the length of a digest to a possible hash function producing
#     # this digest.
#     hashfunc_map = {
#         16: md5,
#         20: sha1
#     }
# 
#     fingerprint = fingerprint.replace(':', '').lower()
#     digest_length, odd = divmod(len(fingerprint), 2)
# 
#     if odd or digest_length not in hashfunc_map:
#         raise SSLError('Fingerprint is of invalid length.')
# 
#     # We need encode() here for py32; works on py2 and p33.
#     fingerprint_bytes = unhexlify(fingerprint.encode())
# 
#     hashfunc = hashfunc_map[digest_length]
# 
#     cert_digest = hashfunc(cert).digest()
# 
#     if not cert_digest == fingerprint_bytes:
#         raise SSLError('Fingerprints did not match. Expected "{0}", got "{1}".'
#                        .format(hexlify(fingerprint_bytes),
#                                hexlify(cert_digest)))


# Path: Custom/events/Zabbix/API/requests/packages/urllib3/connection.py
import datetime
import sys
import socket
import warnings
    import ssl
from socket import timeout as SocketTimeout
    from http.client import HTTPConnection as _HTTPConnection, HTTPException
    from httplib import HTTPConnection as _HTTPConnection, HTTPException
from .exceptions import (
    ConnectTimeoutError,
    SystemTimeWarning,
)
from .packages.ssl_match_hostname import match_hostname
from .packages import six
from .util.ssl_ import (
    resolve_cert_reqs,
    resolve_ssl_version,
    ssl_wrap_socket,
    assert_fingerprint,
)
from .util import connection

        self._prepare_conn(conn)
        self.sock = ssl.wrap_socket(conn, self.key_file, self.cert_file)


class VerifiedHTTPSConnection(HTTPSConnection):
    """
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    """
    cert_reqs = None
    ca_certs = None
    ssl_version = None
    assert_fingerprint = None

    def set_cert(self, key_file=None, cert_file=None,
                 cert_reqs=None, ca_certs=None,
                 assert_hostname=None, assert_fingerprint=None):

        self.key_file = key_file
        self.cert_file = cert_file
        self.cert_reqs = cert_reqs
        self.ca_certs = ca_certs
        self.assert_hostname = assert_hostname
        self.assert_fingerprint = assert_fingerprint

    def connect(self):
        # Add certificate verification
        conn = self._new_conn()

        resolved_cert_reqs = resolve_cert_reqs(self.cert_reqs)

        resolved_ssl_version = resolve_ssl_version(self.ssl_version)
