Esempio n. 1
0
# 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.
Esempio n. 2
0
    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_"),
Esempio n. 3
0
]
__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)
Esempio n. 4
0
    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_TLSv1_3
from _ssl import _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_'),
Esempio n. 5
0
EWOULDBLOCK = getattr(errno, "EWOULDBLOCK", 11)

__all__ = ["fromfd", "getfqdn", "create_connection", "AddressFamily", "SocketKind"]
__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)
    except ValueError:
Esempio n. 6
0
File: ssl.py Progetto: 3lnc/cpython
except ImportError:
    # LibreSSL does not provide RAND_egd
    pass


from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN
from _ssl import _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_'),
Esempio n. 7
0
EWOULDBLOCK = getattr(errno, "EWOULDBLOCK", 11)

__all__ = ["fromfd", "getfqdn", "create_connection", "AddressFamily", "SocketKind"]
__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)
    except ValueError: