diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-18 18:33:08 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-18 18:33:08 (GMT) |
commit | 172f025bed3cca992c1d4d9fe93d4cd8bee92392 (patch) | |
tree | cfed69633555d4a905faa1f4da90fbfcdc63b5a2 /Lib/ssl.py | |
parent | 1226db46517f21cba52bd3efe8b206ddaefd7504 (diff) | |
download | cpython-172f025bed3cca992c1d4d9fe93d4cd8bee92392.zip cpython-172f025bed3cca992c1d4d9fe93d4cd8bee92392.tar.gz cpython-172f025bed3cca992c1d4d9fe93d4cd8bee92392.tar.bz2 |
Issue #21068: The ssl.PROTOCOL* constants are now enum members.
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r-- | Lib/ssl.py | 27 |
1 files changed, 8 insertions, 19 deletions
@@ -92,7 +92,7 @@ import re import sys import os from collections import namedtuple -from enum import Enum as _Enum +from enum import Enum as _Enum, IntEnum as _IntEnum import _ssl # if we can't import it, let the error propagate @@ -119,30 +119,19 @@ _import_symbols('SSL_ERROR_') from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN -from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1 from _ssl import _OPENSSL_API_VERSION +_SSLMethod = _IntEnum('_SSLMethod', + {name: value for name, value in vars(_ssl).items() + if name.startswith('PROTOCOL_')}) +globals().update(_SSLMethod.__members__) + +_PROTOCOL_NAMES = {value: name for name, value in _SSLMethod.__members__.items()} -_PROTOCOL_NAMES = { - PROTOCOL_TLSv1: "TLSv1", - PROTOCOL_SSLv23: "SSLv23", - PROTOCOL_SSLv3: "SSLv3", -} try: - from _ssl import PROTOCOL_SSLv2 _SSLv2_IF_EXISTS = PROTOCOL_SSLv2 -except ImportError: +except NameError: _SSLv2_IF_EXISTS = None -else: - _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2" - -try: - from _ssl import PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2 -except ImportError: - pass -else: - _PROTOCOL_NAMES[PROTOCOL_TLSv1_1] = "TLSv1.1" - _PROTOCOL_NAMES[PROTOCOL_TLSv1_2] = "TLSv1.2" if sys.platform == "win32": from _ssl import enum_certificates, enum_crls |