from _ssl import RAND_status, RAND_add, RAND_bytes, RAND_pseudo_bytes try: from _ssl import RAND_egd except ImportError: # LibreSSL does not provide RAND_egd pass from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3 from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION _IntEnum._convert_("_SSLMethod", __name__, lambda name: name.startswith("PROTOCOL_") and name != "PROTOCOL_SSLv23", source=_ssl) _IntFlag._convert_("Options", __name__, lambda name: name.startswith("OP_"), source=_ssl) _IntEnum._convert_("AlertDescription", __name__, lambda name: name.startswith("ALERT_DESCRIPTION_"), source=_ssl) _IntEnum._convert_("SSLErrorNumber", __name__, lambda name: name.startswith("SSL_ERROR_"), source=_ssl) _IntFlag._convert_("VerifyFlags", __name__, lambda name: name.startswith("VERIFY_"), source=_ssl) _IntEnum._convert_("VerifyMode", __name__, lambda name: name.startswith("CERT_"), source=_ssl) PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_TLS _PROTOCOL_NAMES = {value: name for name, value in _SSLMethod.__members__.items()} _SSLv2_IF_EXISTS = getattr(_SSLMethod, "PROTOCOL_SSLv2", None)
# Note that _socket only knows about the integer values. The public interface # in this module understands the enums and translates them back from integers # where needed (e.g. .family property of a socket object). IntEnum._convert_( 'AddressFamily', __name__, lambda C: C.isupper() and C.startswith('AF_')) IntEnum._convert_( 'SocketKind', __name__, lambda C: C.isupper() and C.startswith('SOCK_')) IntFlag._convert_( 'MsgFlag', __name__, lambda C: C.isupper() and C.startswith('MSG_')) IntFlag._convert_( 'AddressInfo', __name__, lambda C: C.isupper() and C.startswith('AI_')) _LOCALHOST = '127.0.0.1' _LOCALHOST_V6 = '::1' def _intenum_converter(value, enum_klass): """Convert a numeric family value to an IntEnum member. If it's not a known member, return the numeric value itself.
from _ssl import ( HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1, HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3 ) from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION _IntEnum._convert_( '_SSLMethod', __name__, lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23', source=_ssl) _IntFlag._convert_( 'Options', __name__, lambda name: name.startswith('OP_'), source=_ssl) _IntEnum._convert_( 'AlertDescription', __name__, lambda name: name.startswith('ALERT_DESCRIPTION_'), source=_ssl) _IntEnum._convert_( 'SSLErrorNumber', __name__, lambda name: name.startswith('SSL_ERROR_'), source=_ssl) _IntFlag._convert_( 'VerifyFlags', __name__, lambda name: name.startswith('VERIFY_'),
] __all__.extend(os._get_exports_list(_socket)) # Set up the socket.AF_* socket.SOCK_* constants as members of IntEnums for # nicer string representations. # Note that _socket only knows about the integer values. The public interface # in this module understands the enums and translates them back from integers # where needed (e.g. .family property of a socket object). IntEnum._convert_("AddressFamily", __name__, lambda C: C.isupper() and C.startswith("AF_")) IntEnum._convert_("SocketKind", __name__, lambda C: C.isupper() and C.startswith("SOCK_")) IntFlag._convert_("MsgFlag", __name__, lambda C: C.isupper() and C.startswith("MSG_")) IntFlag._convert_("AddressInfo", __name__, lambda C: C.isupper() and C.startswith("AI_")) _LOCALHOST = "127.0.0.1" _LOCALHOST_V6 = "::1" def _intenum_converter(value, enum_klass): """Convert a numeric family value to an IntEnum member. If it's not a known member, return the numeric value itself. """ try: return enum_klass(value)