def create_default_context(purpose=None, **kwargs):
    """Create a new SSL context in the most secure way available on the current
    Python version. See :func:`ssl.create_default_context`."""
    if hasattr(ssl, 'create_default_context'):
        # Python 2.7.9+, Python 3.4+: take a server_side boolean or None, in
        # addition to the ssl.Purpose.XX values. This allows a user to write
        # code that works on all supported Python versions.
        if purpose is None or purpose is False:
            purpose = ssl.Purpose.SERVER_AUTH
        elif purpose is True:
            purpose = ssl.Purpose.CLIENT_AUTH
        return ssl.create_default_context(purpose, **kwargs)
    # Python 2.7.8, Python 3.3
    context = SSLContext(ssl.PROTOCOL_SSLv23)
    if kwargs.get('cafile'):
        context.load_verify_locations(kwargs['cafile'])
    return context
Create a new SSL context in the most secure way available on the current
    Python version. See :func:`ssl.create_default_context`.