# -*- coding: utf-8 -*-"""FTP Command=================.. module:: pcapkit.vendor.ftp.commandThis module contains the vendor crawler for **FTP Command**,which is automatically generating :class:`pcapkit.const.ftp.command.Command`."""importcollectionsimportcsvimportreimportsysfromtypingimportTYPE_CHECKING,castfrompcapkit.vendor.defaultimportVendorifTYPE_CHECKING:fromcollectionsimportOrderedDictfromtypingimportCallable__all__=['Command']#: Command type.KIND={'a':'CommandType.A','p':'CommandType.P','s':'CommandType.S',}# type: dict[str, str]#: Conformance requirements.CONF={'m':'ConformanceRequirement.M','o':'ConformanceRequirement.O','h':'ConformanceRequirement.H',}# type: dict[str, str]#: Default constant template of enumerate registry from IANA CSV.LINE=lambdaNAME,DOCS,ENUM,MODL:f'''\# -*- coding: utf-8 -*-# mypy: disable-error-code=assignment# pylint: disable=line-too-long,consider-using-f-string"""{(name:=DOCS.split(' [',maxsplit=1)[0])}{'='*(len(name)+6)}.. module:: {MODL.replace('vendor','const')}This module contains the constant enumeration for **{name}**,which is automatically generated from :class:`{MODL}.{NAME}`."""from typing import TYPE_CHECKINGfrom aenum import IntEnum, IntFlag, StrEnum, auto, extend_enumif TYPE_CHECKING: from typing import Optional, Type__all__ = ['{NAME}']class FEATCode(StrEnum): """Keyword returned in FEAT response line for this command/extension, c.f., :rfc:`5797#secion-3`.""" #: FTP standard commands [:rfc:`0959`]. base = '<base>' #: Historic experimental commands [:rfc:`0775`][:rfc:`1639`]. hist = '<hist>' #: FTP Security Extensions [:rfc:`2228`]. secu = '<secu>' #: FTP Feature Negotiation [:rfc:`2389`]. feat = '<feat>' #: FTP Extensions for NAT/IPv6 [:rfc:`2428`]. nat6 = '<nat6>' def __repr__(self) -> 'str': return "<%s [%s]>" % (self.__class__.__name__, self._name_) @classmethod def _missing_(cls, value: 'str') -> 'FEATCode': """Lookup function used when value is not found. Args: value: Value to get enum item. """ return extend_enum(cls, value.upper(), value)class CommandType(IntFlag): """Type of "kind" of command, based on :rfc:`959#section-4.1`.""" undefined = 0 #: Access control. A = auto() #: Parameter setting. P = auto() #: Service execution. S = auto()class ConformanceRequirement(IntEnum): """Expectation for support in modern FTP implementations.""" #: Mandatory to implement. M = auto() #: Optional. O = auto() #: Historic. H = auto()class {NAME}(StrEnum): """[{NAME}] {DOCS}""" if TYPE_CHECKING: #: Feature code. Keyword returned in FEAT response line for this command/extension, #: c.f., :rfc:`5797#secion-2.2`. feat: 'Optional[FEATCode]' #: Brief description of command / extension. desc: 'Optional[str]' #: Type of "kind" of command, based on :rfc:`959#section-4.1`. type: 'CommandType' #: Expectation for support in modern FTP implementations. conf: 'ConformanceRequirement' def __new__(cls, name: 'str', feat: 'Optional[FEATCode]' = None, desc: 'Optional[str]' = None, type: 'CommandType' = CommandType.undefined, conf: 'ConformanceRequirement' = ConformanceRequirement.O) -> 'Type[{NAME}]': obj = str.__new__(cls, name) obj._value_ = name obj.feat = feat obj.desc = desc obj.type = type obj.conf = conf return obj def __repr__(self) -> 'str': return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, self.desc){ENUM} @staticmethod def get(key: 'str', default: 'Optional[str]' = None) -> '{NAME}': """Backport support for original codes. Args: key: Key to get enum item. default: Default value if not found. :meta private: """ if key not in {NAME}._member_map_: # pylint: disable=no-member return extend_enum({NAME}, key.upper(), default if default is not None else key) return {NAME}[key] # type: ignore[misc] @classmethod def _missing_(cls, value: 'str') -> '{NAME}': """Lookup function used when value is not found. Args: value: Value to get enum item. """ return extend_enum(cls, value.upper(), value)'''.strip()# type: Callable[[str, str, str, str], str]