def create_default_context(purpose=Purpose.SERVER_AUTH, cafile=None, capath=None, cadata=None):
 if (not isinstance(purpose, _ASN1Object)):
  raise TypeError(purpose)
 context = SSLContext(PROTOCOL_SSLv23)
 context.options |= OP_NO_SSLv2
 context.options |= OP_NO_SSLv3
 context.options |= getattr(_ssl, 'OP_NO_COMPRESSION', 0)
 if (purpose == Purpose.SERVER_AUTH):
  context.verify_mode = CERT_REQUIRED
  context.check_hostname = True
 elif (purpose == Purpose.CLIENT_AUTH):
  context.options |= getattr(_ssl, 'OP_CIPHER_SERVER_PREFERENCE', 0)
  context.options |= getattr(_ssl, 'OP_SINGLE_DH_USE', 0)
  context.options |= getattr(_ssl, 'OP_SINGLE_ECDH_USE', 0)
  context.set_ciphers(_RESTRICTED_SERVER_CIPHERS)
 if (cafile or capath or cadata):
  context.load_verify_locations(cafile, capath, cadata)
 elif (context.verify_mode != CERT_NONE):
  context.load_default_certs(purpose)
 return context

def create_default_context ( purpose = Purpose . SERVER_AUTH , cafile = None , capath = None , cadata = None ) : if ( not isinstance ( purpose , _ASN1Object ) ) : raise TypeError ( purpose ) context = SSLContext ( PROTOCOL_SSLv23 ) context . options |= OP_NO_SSLv2 context . options |= OP_NO_SSLv3 context . options |= getattr ( _ssl , 'OP_NO_COMPRESSION' , 0 ) if ( purpose == Purpose . SERVER_AUTH ) : context . verify_mode = CERT_REQUIRED context . check_hostname = True elif ( purpose == Purpose . CLIENT_AUTH ) : context . options |= getattr ( _ssl , 'OP_CIPHER_SERVER_PREFERENCE' , 0 ) context . options |= getattr ( _ssl , 'OP_SINGLE_DH_USE' , 0 ) context . options |= getattr ( _ssl , 'OP_SINGLE_ECDH_USE' , 0 ) context . set_ciphers ( _RESTRICTED_SERVER_CIPHERS ) if ( cafile or capath or cadata ) : context . load_verify_locations ( cafile , capath , cadata ) elif ( context . verify_mode != CERT_NONE ) : context . load_default_certs ( purpose ) return context
create a sslcontext object with default settings .