Source code for pcapkit.vendor.mh.binding_update_flag
# -*- coding: utf-8 -*-"""Binding Update Flags==========================.. module:: pcapkit.vendor.mh.binding_update_flagThis module contains the vendor crawler for **Binding Update Flags**,which is automatically generating :class:`pcapkit.const.mh.binding_update_flag.BindingUpdateFlag`."""importcsvimportreimportsysfromtypingimportTYPE_CHECKINGfrompcapkit.vendor.defaultimportVendor__all__=['BindingUpdateFlag']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]classBindingUpdateFlag(Vendor):"""Binding Update Flags"""#: Value limit checker.FLAG='isinstance(value, int) and 0 <= value <= 0xFFFF'#: Link to registry.LINK='https://www.iana.org/assignments/mobility-parameters/mobility-parameters-11.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:long=item[0]rfcs=item[2]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''split=long.split(' (',1)iflen(split)==2:name=split[0]cmmt=f" ({split[1]}"else:name,cmmt=long,''desc=self.wrap_comment(f'{name}{cmmt}{tmp1}')code,code_val=item[1],int(item[1],base=16)renm=self.rename(name,code,original=long)pres=f"{renm} = 0x{code_val:04x}"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__)