Source code for pcapkit.const.pop3.command

# -*- coding: utf-8 -*-
# pylint: disable=line-too-long
"""POP3 Command
==================

.. module:: pcapkit.const.pop3.command

This module contains the constant enumeration for **POP3 Command**,
which is automatically generated from :class:`pcapkit.vendor.pop3.command.Command`.

"""

from typing import TYPE_CHECKING

from aenum import StrEnum

from pcapkit.corekit.enum import EnumRegistry
from pcapkit.corekit.sentinels import NO_DEFAULT
from pcapkit.utilities.exceptions import EnumValueError

if TYPE_CHECKING:
    from typing import Any

__all__ = ['Command']


[docs] class Command(EnumRegistry, StrEnum): """[Command] POP3 Command""" #: USER name [:rfc:`1939#section-7`] USER = 'USER' #: PASS string [:rfc:`1939#section-7`] PASS = 'PASS' #: QUIT [:rfc:`1939#section-4`][:rfc:`1939#section-6`] QUIT = 'QUIT' #: STAT [:rfc:`1939#section-5`] STAT = 'STAT' #: LIST [msg] [:rfc:`1939#section-5`] LIST = 'LIST' #: RETR msg [:rfc:`1939#section-5`] RETR = 'RETR' #: DELE msg [:rfc:`1939#section-5`] DELE = 'DELE' #: NOOP [:rfc:`1939#section-5`] NOOP = 'NOOP' #: RSET [:rfc:`1939#section-5`] RSET = 'RSET' #: APOP name digest [:rfc:`1939#section-7`] APOP = 'APOP' #: TOP msg n [:rfc:`1939#section-7`] TOP = 'TOP' #: UIDL [msg] [:rfc:`1939#section-7`] UIDL = 'UIDL' #: CAPA [:rfc:`2449#section-5`] CAPA = 'CAPA' #: STLS [:rfc:`2595#section-4`] STLS = 'STLS' #: AUTH mechanism [initial-response] [:rfc:`5034#section-4`] AUTH = 'AUTH' #: UTF8 [:rfc:`6856#section-2.1`] UTF8 = 'UTF8' #: LANG [:rfc:`6856#section-3`] LANG = 'LANG'
[docs] @classmethod def get(cls, key: 'Any', default: 'Any' = NO_DEFAULT) -> 'Command': """Resolve ``key`` to a member, folding a :class:`str` to upper case. Command keywords are not case-sensitive (:rfc:`1939#section-3`), and each member is named, and valued, its keyword in upper case. Args: key: Key to get enum item. default: An already-registered value to fall back to, as :meth:`~pcapkit.corekit.enum.EnumLookup.get` takes it. Returns: The member ``key`` names or carries. Raises: EnumKeyError: If ``key`` names no member and there is no usable ``default``. EnumValueError: If ``key`` is not a :class:`str` and there is no usable ``default``. """ if isinstance(key, str): return super().get(key.upper(), default) return super().get(key, default)
[docs] @classmethod def _validate_value(cls, value: 'Any') -> 'None': """Reject ``value`` unless it is a :class:`str`, as :meth:`_missing_` does. Args: value: Value about to be looked up or minted. Raises: EnumValueError: If ``value`` is not a :class:`str`. """ if not isinstance(value, str): raise EnumValueError(f'{value!r} is not a valid {cls.__name__}')
[docs] @classmethod def _missing_(cls, value: 'str') -> 'Command': """Lookup function used when value is not found. Args: value: Value to get enum item, matched case-insensitively against the member names (:rfc:`1939#section-3`). A keyword no member names resolves to an unregistered member named after it in upper case and valued as given (:issue:`860`). """ if not isinstance(value, str): raise ValueError(f'{value!r} is not a valid {cls.__name__}') name = value.upper() if name in cls._member_map_: # pylint: disable=no-member return cls._member_map_[name] # pylint: disable=no-member return cls._unregistered_member(value, name)