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
object
like instances.Info
objects are iterable, and support all functions asdict
typeInfo
objects are immutable, thus cannot set or delete attributes after initialisation
Important
Info
will 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
.