<s> from __future__ import absolute_import , division , print_function <EOL> import atexit <EOL> from collections import namedtuple <EOL> from cffi import FFI <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class API ( object ) : <EOL> """<STR_LIT>""" <EOL> SSLVersion = namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _modules = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def __init__ ( self ) : <EOL> self . ffi = FFI ( ) <EOL> self . INCLUDES = [ ] <EOL> self . TYPES = [ ] <EOL> self . FUNCTIONS = [ ] <EOL> self . C_CUSTOMIZATION = [ ] <EOL> self . OVERRIDES = [ ] <EOL> self . SETUP = [ ] <EOL> self . TEARDOWN = [ ] <EOL> self . _import ( ) <EOL> self . _define ( ) <EOL> self . _verify ( ) <EOL> self . _override ( ) <EOL> self . _populate ( ) <EOL> self . _initialise ( ) <EOL> def _import ( self ) : <EOL> "<STR_LIT>" <EOL> for name in self . _modules : <EOL> module = __import__ ( __name__ + '<STR_LIT:.>' + name , fromlist = [ '<STR_LIT:*>' ] ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> self . _import_definitions ( module , '<STR_LIT>' ) <EOL> def _import_definitions ( self , module , name ) : <EOL> "<STR_LIT>" <EOL> container = getattr ( self , name ) <EOL> for definition in getattr ( module , name , ( ) ) : <EOL> if definition not in container : <EOL> container . append ( definition ) <EOL> def _define ( self ) : <EOL> "<STR_LIT>" <EOL> for typedef in self . TYPES : <EOL> self . ffi . cdef ( typedef ) <EOL> for function in self . FUNCTIONS : <EOL> self . ffi . cdef ( function ) <EOL> def _verify ( self ) : <EOL> "<STR_LIT>" <EOL> self . openssl = self . ffi . verify ( <EOL> source = "<STR_LIT:\n>" . join ( self . INCLUDES + self . C_CUSTOMIZATION ) , <EOL> ext_package = "<STR_LIT>" , <EOL> extra_compile_args = [ <EOL> '<STR_LIT>' , <EOL> ] , <EOL> libraries = [ '<STR_LIT>' ] <EOL> ) <EOL> def _override ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _overrides = { } <EOL> for func in self . OVERRIDES : <EOL> name = func . __name__ <EOL> from_openssl = getattr ( self . openssl , name ) <EOL> override = func ( self . openssl , from_openssl ) <EOL> self . _overrides [ name ] = override <EOL> def _populate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . NULL = self . ffi . NULL <EOL> self . buffer = self . ffi . buffer <EOL> self . callback = self . ffi . callback <EOL> self . cast = self . ffi . cast <EOL> self . new = self . ffi . new <EOL> self . gc = self . ffi . gc <EOL> self . string = self . ffi . string <EOL> def __getattr__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . _overrides . get ( name , getattr ( self . openssl , name ) ) <EOL> def _initialise ( self ) : <EOL> "<STR_LIT>" <EOL> for function in self . SETUP : <EOL> getattr ( self , function ) ( ) <EOL> for function in self . TEARDOWN : <EOL> atexit . register ( getattr ( self , function ) ) <EOL> def version_info ( self ) : <EOL> "<STR_LIT>" <EOL> version = self . SSLeay ( ) <EOL> major = version >> ( <NUM_LIT:7> * <NUM_LIT:4> ) & <NUM_LIT> <EOL> minor = version >> ( <NUM_LIT:5> * <NUM_LIT:4> ) & <NUM_LIT> <EOL> fix = version >> ( <NUM_LIT:3> * <NUM_LIT:4> ) & <NUM_LIT> <EOL> patch = version >> ( <NUM_LIT:1> * <NUM_LIT:4> ) & <NUM_LIT> <EOL> patch = '<STR_LIT>' if not patch else chr ( <NUM_LIT> + patch ) <EOL> status = version & <NUM_LIT> <EOL> if status == <NUM_LIT> : <EOL> status = '<STR_LIT>' <EOL> elif status == <NUM_LIT> : <EOL> status = '<STR_LIT>' <EOL> else : <EOL> status = '<STR_LIT>' . format ( status ) <EOL> return self . SSLVersion ( major , minor , fix , patch , status ) <EOL> def version ( self , detail = None ) : <EOL> "<STR_LIT>" <EOL> detail = self . SSLEAY_VERSION if detail is None else detail <EOL> buff = self . SSLeay_version ( detail ) <EOL> return api . string ( buff ) <EOL> api = API ( ) </s>
