(protocol=None, *, cert_reqs=CERT_NONE,
                           check_hostname=False, purpose=Purpose.SERVER_AUTH,
                           certfile=None, keyfile=None,
                           cafile=None, capath=None, cadata=None)
return context
Create a SSLContext object for Python stdlib modules

    All Python stdlib modules shall use this function to create SSLContext
    objects in order to keep common settings in one place. The configuration
    is less restrict than create_default_context()'s to increase backward
    compatibility.
Create a SSLContext object for Python stdlib modules
Create a SSLContext object for Python stdlib modules
def _create_unverified_context(protocol=None, *, cert_reqs=CERT_NONE,
                           check_hostname=False, purpose=Purpose.SERVER_AUTH,
                           certfile=None, keyfile=None,
                           cafile=None, capath=None, cadata=None):
    """Create a SSLContext object for Python stdlib modules

    All Python stdlib modules shall use this function to create SSLContext
    objects in order to keep common settings in one place. The configuration
    is less restrict than create_default_context()'s to increase backward
    compatibility.
    """
    if not isinstance(purpose, _ASN1Object):
        raise TypeError(purpose)

    # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
    # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
    # by default.
    if purpose == Purpose.SERVER_AUTH:
        # verify certs and host name in client mode
        if protocol is None:
            protocol = PROTOCOL_TLS_CLIENT
    elif purpose == Purpose.CLIENT_AUTH:
        if protocol is None:
            protocol = PROTOCOL_TLS_SERVER
    else:
        raise ValueError(purpose)

    context = SSLContext(protocol)
    context.check_hostname = check_hostname
    if cert_reqs is not None:
        context.verify_mode = cert_reqs
    if check_hostname:
        context.check_hostname = True

    if keyfile and not certfile:
        raise ValueError("certfile must be specified")
    if certfile or keyfile:
        context.load_cert_chain(certfile, keyfile)

    # load CA root certs
    if cafile or capath or cadata:
        context.load_verify_locations(cafile, capath, cadata)
    elif context.verify_mode != CERT_NONE:
        # no explicit cafile, capath or cadata but the verify mode is
        # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system
        # root CA certificates for the given purpose. This may fail silently.
        context.load_default_certs(purpose)
    # OpenSSL 1.1.1 keylog file
    if hasattr(context, 'keylog_filename'):
        keylogfile = os.environ.get('SSLKEYLOGFILE')
        if keylogfile and not sys.flags.ignore_environment:
            context.keylog_filename = keylogfile
    return context
def _create_unverified_context ( protocol = None , * , cert_reqs = CERT_NONE , check_hostname = False , purpose = Purpose . SERVER_AUTH , certfile = None , keyfile = None , cafile = None , capath = None , cadata = None ) : if not isinstance ( purpose , _ASN1Object ) : raise TypeError ( purpose ) # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION, # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE # by default. if purpose == Purpose . SERVER_AUTH : # verify certs and host name in client mode if protocol is None : protocol = PROTOCOL_TLS_CLIENT elif purpose == Purpose . CLIENT_AUTH : if protocol is None : protocol = PROTOCOL_TLS_SERVER else : raise ValueError ( purpose ) context = SSLContext ( protocol ) context . check_hostname = check_hostname if cert_reqs is not None : context . verify_mode = cert_reqs if check_hostname : context . check_hostname = True if keyfile and not certfile : raise ValueError ( "certfile must be specified" ) if certfile or keyfile : context . load_cert_chain ( certfile , keyfile ) # load CA root certs if cafile or capath or cadata : context . load_verify_locations ( cafile , capath , cadata ) elif context . verify_mode != CERT_NONE : # no explicit cafile, capath or cadata but the verify mode is # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system # root CA certificates for the given purpose. This may fail silently. context . load_default_certs ( purpose ) # OpenSSL 1.1.1 keylog file if hasattr ( context , 'keylog_filename' ) : keylogfile = os . environ . get ( 'SSLKEYLOGFILE' ) if keylogfile and not sys . flags . ignore_environment : context . keylog_filename = keylogfile return context