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
  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
   warnings.warn('ssl check hostname support disabled, upgrade your python', InsecurePlatformWarning)
  if getattr(context, 'supports_set_ciphers', True):
   if ciphers:
    context.set_ciphers(ciphers)
  else:
   warnings.warn('ssl ciphers support disabled, upgrade your python', InsecurePlatformWarning)
 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 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 warnings . warn ( 'ssl check hostname support disabled, upgrade your python' , InsecurePlatformWarning ) if getattr ( context , 'supports_set_ciphers' , True ) : if ciphers : context . set_ciphers ( ciphers ) else : warnings . warn ( 'ssl ciphers support disabled, upgrade your python' , InsecurePlatformWarning ) return context
backport create_default_context for older python versions .