Source code for pcapkit.vendor.mh.handover_initiate_flag
# -*- coding: utf-8 -*-"""Handover Initiate Flags=============================.. module:: pcapkit.vendor.mh.handover_initiate_flagThis module contains the vendor crawler for **Handover Initiate Flags**,which is automatically generating :class:`pcapkit.const.mh.handover_initiate_flag.HandoverInitiateFlag`."""importcsvimportreimportsysfromtypingimportTYPE_CHECKINGfrompcapkit.vendor.defaultimportVendor__all__=['HandoverInitiateFlag']ifTYPE_CHECKING:fromtypingimportCallableLINE=lambdaNAME,DOCS,FLAG,ENUM,MODL:f'''\# -*- coding: utf-8 -*-# 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 aenum import IntFlag__all__ = ['{NAME}']class {NAME}(IntFlag): """[{NAME}] {DOCS}"""{ENUM} @staticmethod def get(key: 'int | str', default: 'int' = -1) -> '{NAME}': """Backport support for original codes. Args: key: Key to get enum item. default: Default value if not found. :meta private: """ if isinstance(key, int): return {NAME}(key) return {NAME}[key] # type: ignore[misc] @classmethod def _missing_(cls, value: 'int') -> '{NAME}': """Lookup function used when value is not found. Args: value: Value to get enum item. """ if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) return cls(value)'''# type: Callable[[str, str, str, str, str], str]
[docs]classHandoverInitiateFlag(Vendor):"""Handover Initiate Flags"""#: Value limit checker.FLAG='isinstance(value, int) and 0 <= value <= 0xFF'#: Link to registry.LINK='https://www.iana.org/assignments/mobility-parameters/handover-initiate-flags.csv'defprocess(self,data:'list[str]')->'list[str]':# type: ignore[override] # pylint: disable=arguments-differ,arguments-renamed"""Process CSV data. Args: data: CSV data. Returns: Enumeration fields and missing fields. """reader=csv.reader(data)next(reader)# headerenum=[]# type: list[str]foriteminreader:name=item[0]dscp=item[2]rfcs=item[3]temp=[]# type: list[str]forrfcinfilter(None,re.split(r'\[|\]',rfcs)):if'RFC'inrfcandre.match(r'\d+',rfc[3:]):# temp.append(f'[{rfc[:3]} {rfc[3:]}]')temp.append(f'[:rfc:`{rfc[3:]}`]')else:temp.append(f'[{rfc}]'.replace('_',' '))tmp1=f" {''.join(temp)}"ifrfcselse''desc=self.wrap_comment(f'{dscp}{tmp1}')code,code_val=item[1],int(item[1],base=16)renm=self.rename(name,code)pres=f"{renm} = 0x{code_val:02x}"sufs=f'#: {desc}'# if len(pres) > 74:# sufs = f"\n{' '*80}{sufs}"# enum.append(f'{pres.ljust(76)}{sufs}')enum.append(f'{sufs}\n{pres}')returnenumdefcontext(self,data:'list[str]')->'str':# pylint: disable=arguments-differ,arguments-renamed"""Generate constant context. Args: soup: Parsed HTML source. Returns: Constant context. """enum=self.process(data)ENUM='\n\n '.join(map(lambdas:s.rstrip(),enum))returnLINE(self.NAME,self.DOCS,self.FLAG,ENUM,self.__module__)