Info Class¶
pcapkit.corekit.infoclass contains dict like class
Info only, which is originally
designed to work alike dataclasses.dataclass() as introduced
in PEP 557.
- class pcapkit.corekit.infoclass.Info(dict_=None, **kwargs)[source]¶
Bases:
Mapping[str,VT],Generic[VT]Turn dictionaries into
objectlike instances.Infoobjects are iterable, and support all functions asdicttypeInfoobjects are immutable, thus cannot set or delete attributes after initialisation
Important
Infowill attempt to rename keys with the same names as the class’s builtin methods, and store the mapping information in the__map__and__map_reverse__attributes. However, when accessing such renamed keys, the original key name should always be used, i.e., such renaming is totally transparent to the user.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- __map__: dict[str, str]¶
Mapping of name conflicts with builtin methods (original names to transformed names).
- __map_reverse__: dict[str, str]¶
Mapping of name conflicts with builtin methods (transformed names to original names).
- static __new__(cls, *args, **kwargs)[source]¶
Create a new instance.
The class will try to automatically generate
__init__method with the same signature as specified in class variables’ type annotations, which is inspired by PEP 557 (dataclasses).
- classmethod from_dict(dict_=None, **kwargs)[source]¶
Create a new instance.
If
dict_is present and has a.keys()method, then does:for k in dict_: self[k] = dict_[k].If
dict_is present and has no.keys()method, then does:for k, v in dict_: self[k] = v.If
dict_is not present, then does:for k, v in kwargs.items(): self[k] = v.