(server_side=False, ciphers=None)
return context
Backport create_default_context for older python versions.

    The SSLContext has some default security options, you can disable them
    manually, for example::

        from thriftpy.transport import _ssl
        context = _ssl.create_thriftpy_context()
        context.options &= ~_ssl.OP_NO_SSLv3

    You can do the same to enable compression.
Backport create_default_context for older python versions.
Backport create_default_context for older python versions .
def create_thriftpy_context(server_side=False, ciphers=None):
    """Backport create_default_context for older python versions.

    The SSLContext has some default security options, you can disable them
    manually, for example::

        from thriftpy.transport import _ssl
        context = _ssl.create_thriftpy_context()
        context.options &= ~_ssl.OP_NO_SSLv3

    You can do the same to enable compression.
    """
    if MODERN_SSL:
        if server_side:
            context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
        else:
            context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)

        if ciphers:
            context.set_ciphers(ciphers)

    else:
        context = SSLContext(ssl.PROTOCOL_SSLv23)
        context.options |= OP_NO_SSLv2
        context.options |= OP_NO_SSLv3
        context.options |= OP_NO_COMPRESSION

        # server/client default options
        if server_side:
            context.options |= OP_CIPHER_SERVER_PREFERENCE
            context.options |= OP_SINGLE_DH_USE
            context.options |= OP_SINGLE_ECDH_USE
        else:
            context.verify_mode = ssl.CERT_REQUIRED
            # context.check_hostname = True
            warnings.warn(
                "ssl check hostname support disabled, upgrade your python",
                InsecurePlatformWarning)

        if ciphers:
            context.set_ciphers(ciphers)

    return context
def create_thriftpy_context ( server_side = False , ciphers = None ) : if MODERN_SSL : if server_side : context = ssl . create_default_context ( ssl . Purpose . CLIENT_AUTH ) else : context = ssl . create_default_context ( ssl . Purpose . SERVER_AUTH ) if ciphers : context . set_ciphers ( ciphers ) else : context = SSLContext ( ssl . PROTOCOL_SSLv23 ) context . options |= OP_NO_SSLv2 context . options |= OP_NO_SSLv3 context . options |= OP_NO_COMPRESSION # server/client default options if server_side : context . options |= OP_CIPHER_SERVER_PREFERENCE context . options |= OP_SINGLE_DH_USE context . options |= OP_SINGLE_ECDH_USE else : context . verify_mode = ssl . CERT_REQUIRED # context.check_hostname = True warnings . warn ( "ssl check hostname support disabled, upgrade your python" , InsecurePlatformWarning ) if ciphers : context . set_ciphers ( ciphers ) return context