|
10 | 10 | classes.
|
11 | 11 |
|
12 | 12 | """
|
| 13 | +import collections |
13 | 14 | import datetime
|
14 | 15 | import decimal
|
15 | 16 | import enum
|
|
19 | 20 | import aenum
|
20 | 21 |
|
21 | 22 | from pcapkit.corekit.infoclass import Info
|
| 23 | +from pcapkit.corekit.multidict import MultiDict, OrderedMultiDict |
22 | 24 | from pcapkit.utilities.logging import logger
|
23 | 25 |
|
24 | 26 | __all__ = ['make_dumper']
|
25 | 27 |
|
26 | 28 | if TYPE_CHECKING:
|
27 |
| - from typing import Any, TextIO, Type |
| 29 | + from typing import Any, TextIO, Type, DefaultDict |
28 | 30 |
|
29 | 31 | from dictdumper.dumper import Dumper
|
30 | 32 | from typing_extensions import Literal
|
@@ -62,14 +64,21 @@ def object_hook(self, o: 'Any') -> 'Any':
|
62 | 64 | return o.to_dict()
|
63 | 65 | if isinstance(o, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
|
64 | 66 | return str(o)
|
| 67 | + if isinstance(o, (MultiDict, OrderedMultiDict)): |
| 68 | + temp = collections.defaultdict(list) # type: DefaultDict[str, list[Any]] |
| 69 | + for key, val in o.items(multi=True): |
| 70 | + if isinstance(key, (enum.Enum, aenum.Enum)): |
| 71 | + key = f'{type(key).__name__}::{key.name} [{key.value}]' |
| 72 | + temp[key].append(val) |
| 73 | + return temp |
65 | 74 | if isinstance(o, (enum.Enum, aenum.Enum)):
|
66 | 75 | addon = {key: val for key, val in o.__dict__.items() if not key.startswith('_')}
|
67 | 76 | if addon:
|
68 | 77 | return {
|
69 |
| - 'enum': f'<{type(o).__name__}::{o.name} ({o.value})', |
| 78 | + 'enum': f'{type(o).__name__}::{o.name} [{o.value}]', |
70 | 79 | **addon,
|
71 | 80 | }
|
72 |
| - return f'{type(o).__name__}::{o.name} ({o.value})' |
| 81 | + return f'{type(o).__name__}::{o.name} [{o.value}]' |
73 | 82 | return super(type(self), self).object_hook(o) # type: ignore[unreachable]
|
74 | 83 |
|
75 | 84 | def default(self, o: 'Any') -> 'Literal["fallback"]': # pylint: disable=unused-argument
|
|
0 commit comments