Source code for pcapkit.const.ftp.return_code

# -*- coding: utf-8 -*-
# mypy: disable-error-code=assignment
# pylint: disable=line-too-long,consider-using-f-string
"""FTP Server Return Code
============================

.. module:: pcapkit.const.ftp.return_code

This module contains the constant enumeration for **FTP Server Return Code**,
which is automatically generated from :class:`pcapkit.vendor.ftp.return_code.ReturnCode`.

"""

from typing import TYPE_CHECKING

from aenum import IntEnum

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

if TYPE_CHECKING:
    from typing import Any, Optional, Type

__all__ = ['ReturnCode']

#: Grouping information.
INFO = {
    '0': 'Syntax',
    '1': 'Information',
    '2': 'Connections',
    '3': 'Authentication and accounting',
    '4': 'Unspecified',                     # [RFC 959]
    '5': 'File system',
}  # type: dict[str, str]


class ResponseKind(EnumRegistry, IntEnum):
    """Response kind; whether the response is good, bad or incomplete."""

    PositivePreliminary = 1
    PositiveCompletion = 2
    PositiveIntermediate = 3
    TransientNegativeCompletion = 4
    PermanentNegativeCompletion = 5
    Protected = 6

    @classmethod
    def _validate_value(cls, value: 'Any') -> 'None':
        """Reject ``value`` unless it is a digit, which :meth:`_missing_` accepts.

        Overrides :meth:`~pcapkit.corekit.enum.EnumLookup._validate_value`
        with the range :meth:`_missing_` resolves, and the message the
        constructor raises outside it, so
        :meth:`~pcapkit.corekit.enum.EnumRegistry.register` refuses exactly the
        values :meth:`~pcapkit.corekit.enum.EnumLookup.get` refuses, in the
        same words (:issue:`1816`).

        Args:
            value: Value about to be looked up or minted.

        Raises:
            EnumValueError: If ``value`` is not an :class:`int` in ``0``-``9``.
                A :exc:`ValueError`, so an ``except ValueError`` caller is
                unaffected.

        """
        if not (isinstance(value, int) and 0 <= value <= 9):
            raise EnumValueError('%r is not a valid %s' % (value, cls.__name__))

    @classmethod
    def _missing_(cls, value: 'int') -> 'ResponseKind':
        """Lookup function used when value is not found.

        Args:
            value: Value to lookup.

        """
        if isinstance(value, int) and 0 <= value <= 9:
            #: Unknown
            return cls._unregistered_member(value, 'Unknown')
        return super()._missing_(value)


class GroupingInformation(EnumRegistry, IntEnum):
    """Grouping information."""

    Syntax = 0
    Information = 1
    Connections = 2
    AuthenticationAccounting = 3
    Unspecified = 4
    FileSystem = 5

    @classmethod
    def _validate_value(cls, value: 'Any') -> 'None':
        """Reject ``value`` unless it is a digit, which :meth:`_missing_` accepts.

        Overrides :meth:`~pcapkit.corekit.enum.EnumLookup._validate_value`
        with the range :meth:`_missing_` resolves, and the message the
        constructor raises outside it, so
        :meth:`~pcapkit.corekit.enum.EnumRegistry.register` refuses exactly the
        values :meth:`~pcapkit.corekit.enum.EnumLookup.get` refuses, in the
        same words (:issue:`1816`).

        Args:
            value: Value about to be looked up or minted.

        Raises:
            EnumValueError: If ``value`` is not an :class:`int` in ``0``-``9``.
                A :exc:`ValueError`, so an ``except ValueError`` caller is
                unaffected.

        """
        if not (isinstance(value, int) and 0 <= value <= 9):
            raise EnumValueError('%r is not a valid %s' % (value, cls.__name__))

    @classmethod
    def _missing_(cls, value: 'int') -> 'GroupingInformation':
        """Lookup function used when value is not found.

        Args:
            value: Value to lookup.

        """
        if isinstance(value, int) and 0 <= value <= 9:
            #: Unknown
            return cls._unregistered_member(value, 'Unknown')
        return super()._missing_(value)


[docs] class ReturnCode(EnumRegistry, IntEnum): """[ReturnCode] FTP Server Return Code""" if TYPE_CHECKING: #: Description of the return code. description: 'Optional[str]' #: Response kind. kind: 'ResponseKind' #: Grouping information. group: 'GroupingInformation' def __new__(cls, value: 'int', description: 'Optional[str]' = None) -> 'Type[ReturnCode]': obj = int.__new__(cls, value) obj._value_ = value code = '%03d' % value obj.description = description obj.kind = ResponseKind(int(code[0])) obj.group = GroupingInformation(int(code[1])) return obj def __repr__(self) -> 'str': return f'<{self.__class__.__name__} [{self._value_}]>' def __str__(self) -> 'str': return "[%s] %s" % (self._value_, self.description) #: Restart marker replay. In this case, the text is exact and not left to the #: particular implementation; it must read: MARK yyyy = mmmm where yyyy is #: User-process data stream marker, and mmmm server's equivalent marker (note #: the spaces between markers and "="). CODE_110: 'ReturnCode' = 110, 'Restart marker replay.' #: Service ready in nnn minutes. CODE_120: 'ReturnCode' = 120, 'Service ready in nnn minutes.' #: Data connection already open; transfer starting. CODE_125: 'ReturnCode' = 125, 'Data connection already open; transfer starting.' #: File status okay; about to open data connection. CODE_150: 'ReturnCode' = 150, 'File status okay; about to open data connection.' #: Command not implemented, superfluous at this site. CODE_202: 'ReturnCode' = 202, 'Command not implemented, superfluous at this site.' #: System status, or system help reply. CODE_211: 'ReturnCode' = 211, 'System status, or system help reply.' #: Directory status. CODE_212: 'ReturnCode' = 212, 'Directory status.' #: File status. CODE_213: 'ReturnCode' = 213, 'File status.' #: Help message. Explains how to use the server or the meaning of a particular #: non-standard command. This reply is useful only to the human user. CODE_214: 'ReturnCode' = 214, 'Help message.' #: NAME system type. Where NAME is an official system name from the registry #: kept by IANA. CODE_215: 'ReturnCode' = 215, 'NAME system type.' #: Service ready for new user. CODE_220: 'ReturnCode' = 220, 'Service ready for new user.' #: Service closing control connection. Logged out if appropriate. CODE_221: 'ReturnCode' = 221, 'Service closing control connection.' #: Data connection open; no transfer in progress. CODE_225: 'ReturnCode' = 225, 'Data connection open; no transfer in progress.' #: Closing data connection. Requested file action successful (for example, file #: transfer or file abort). CODE_226: 'ReturnCode' = 226, 'Closing data connection.' #: Entering Passive Mode (h1,h2,h3,h4,p1,p2). CODE_227: 'ReturnCode' = 227, 'Entering Passive Mode.' #: Entering Long Passive Mode (long address, port). CODE_228: 'ReturnCode' = 228, 'Entering Long Passive Mode.' #: Entering Extended Passive Mode ( |||port| ). CODE_229: 'ReturnCode' = 229, 'Entering Extended Passive Mode.' #: User logged in, proceed. CODE_230: 'ReturnCode' = 230, 'User logged in, proceed.' #: User logged in, authorized by security data exchange. CODE_232: 'ReturnCode' = 232, 'User logged in, authorized by security data exchange.' #: Server accepts the security mechanism specified by the client; no security #: data needs to be exchanged. CODE_234: 'ReturnCode' = 234, 'Server accepts the security mechanism specified by the client; no security data needs to be exchanged.' #: Server accepts the security data given by the client; no further security #: data needs to be exchanged. CODE_235: 'ReturnCode' = 235, 'Server accepts the security data given by the client; no further security data needs to be exchanged.' #: Requested file action was okay, completed. CODE_250: 'ReturnCode' = 250, 'Requested file action was okay, completed.' #: User name okay, password needed. CODE_331: 'ReturnCode' = 331, 'User name okay, password needed.' #: No need account for login. CODE_332: 'ReturnCode' = 332, 'No need account for login.' #: Server accepts the security mechanism specified by the client; some security #: data needs to be exchanged. CODE_334: 'ReturnCode' = 334, 'Server accepts the security mechanism specified by the client; some security data needs to be exchanged.' #: Server accepts the security data given by the client; more security data #: needs to be exchanged. CODE_335: 'ReturnCode' = 335, 'Server accepts the security data given by the client; more security data needs to be exchanged.' #: Username okay, password okay. Challenge is ". . . . ". CODE_336: 'ReturnCode' = 336, 'Username okay, password okay.' #: Service NOT available, closing control connection. This may be a reply to #: any command if the service knows it must shut down. CODE_421: 'ReturnCode' = 421, 'Service NOT available, closing control connection.' #: Can't open data connection. CODE_425: 'ReturnCode' = 425, "Can't open data connection." #: Connection closed; transfer aborted. CODE_426: 'ReturnCode' = 426, 'Connection closed; transfer aborted.' #: Invalid username or password CODE_430: 'ReturnCode' = 430, 'Invalid username or password.' #: Need some unavailable resource to process security. CODE_431: 'ReturnCode' = 431, 'Need some unavailable resource to process security.' #: Requested host unavailable. CODE_434: 'ReturnCode' = 434, 'Requested host unavailable.' #: Requested file action not taken. File unavailable (e.g., file busy). CODE_450: 'ReturnCode' = 450, 'Requested file action not taken.' #: Requested action aborted. Local error in processing. CODE_451: 'ReturnCode' = 451, 'Requested action aborted.' #: Requested action not taken. Insufficient storage space in system. CODE_452: 'ReturnCode' = 452, 'Requested action not taken.' #: Syntax error in parameters or arguments. CODE_501: 'ReturnCode' = 501, 'Syntax error in parameters or arguments.' #: Command not implemented. CODE_502: 'ReturnCode' = 502, 'Command not implemented.' #: Bad sequence of commands. CODE_503: 'ReturnCode' = 503, 'Bad sequence of commands.' #: Command not implemented for that parameter. CODE_504: 'ReturnCode' = 504, 'Command not implemented for that parameter.' #: Not logged in. CODE_530: 'ReturnCode' = 530, 'Not logged in.' #: Need account for storing files. CODE_532: 'ReturnCode' = 532, 'Need account for storing files.' #: Command protection level denied for policy reasons. CODE_533: 'ReturnCode' = 533, 'Command protection level denied for policy reasons.' #: Request denied for policy reasons. CODE_534: 'ReturnCode' = 534, 'Request denied for policy reasons.' #: Failed security check. CODE_535: 'ReturnCode' = 535, 'Failed security check.' #: Data protection level not supported by security mechanism. CODE_536: 'ReturnCode' = 536, 'Data protection level not supported by security mechanism.' #: Command protection level not supported by security mechanism. CODE_537: 'ReturnCode' = 537, 'Command protection level not supported by security mechanism.' #: Requested action not taken. File unavailable (e.g., file not found, no #: access). CODE_550: 'ReturnCode' = 550, 'Requested action not taken.' #: Requested action aborted. Page type unknown. CODE_551: 'ReturnCode' = 551, 'Requested action aborted.' #: Requested file action aborted. Exceeded storage allocation (for current #: directory or dataset). CODE_552: 'ReturnCode' = 552, 'Requested file action aborted.' #: Requested action not taken. File name not allowed. CODE_553: 'ReturnCode' = 553, 'Requested action not taken.' #: Integrity protected reply. CODE_631: 'ReturnCode' = 631, 'Integrity protected reply.' #: Confidentiality and integrity protected reply. CODE_632: 'ReturnCode' = 632, 'Confidentiality and integrity protected reply.' #: Confidentiality protected reply. CODE_633: 'ReturnCode' = 633, 'Confidentiality protected reply.'
[docs] @classmethod def _unregistered_member(cls, value: 'int', name: 'str') -> 'ReturnCode': """Build a member absent from this registry's own lookup tables. Reconstructs :attr:`description`, :attr:`kind` and :attr:`group` the same way :meth:`__new__` would, rather than leaving them unset -- :meth:`~pcapkit.corekit.enum.EnumRegistry._unregistered_member` bypasses :meth:`__new__` entirely (it calls :class:`int`'s directly), so those attributes would otherwise be missing from the result and :meth:`__str__`/:meth:`__repr__` would raise on it. Args: value: Value to get enum item. name: Bare label for the unregistered member, per the ranged mint/unmint criterion. """ obj = super()._unregistered_member(value, name) code = '%03d' % value obj.description = None obj.kind = ResponseKind(int(code[0])) obj.group = GroupingInformation(int(code[1])) return obj
[docs] @classmethod def _validate_value(cls, value: 'Any') -> 'None': """Reject ``value`` unless it is a three-digit reply code. Overrides :meth:`~pcapkit.corekit.enum.EnumLookup._validate_value` with the range check :meth:`_missing_` makes, and the message it raises, so :meth:`~pcapkit.corekit.enum.EnumRegistry.register` refuses exactly the values :meth:`~pcapkit.corekit.enum.EnumLookup.get` refuses, in the same words (:issue:`1816`). That range is ``0``-``999`` rather than the registry's own, since :meth:`_missing_` resolves a code outside the registry to ``Unknown`` rather than refusing it. Args: value: Value about to be looked up or minted. Raises: EnumValueError: If ``value`` is not an :class:`int` in ``0``-``999``. A :exc:`ValueError`, so an ``except ValueError`` caller is unaffected. """ if not (isinstance(value, int) and 0 <= value <= 999): raise EnumValueError('%r is not a valid %s' % (value, cls.__name__))
[docs] @classmethod def _missing_(cls, value: 'int') -> 'ReturnCode': """Lookup function used when value is not found. A reply code is three digits (:rfc:`959#section-4.2`), so every value from 0 to 999 can arrive on the wire: one within the registry's range resolves to ``Unassigned``, any other to ``Unknown``. Args: value: Value to get enum item. """ if not (isinstance(value, int) and 0 <= value <= 999): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) if isinstance(value, int) and 100 <= value <= 659: #: Unassigned return cls._unregistered_member(value, 'Unassigned') #: Unknown return cls._unregistered_member(value, 'Unknown')