|
2 | 2 |
|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
| 5 | +from frozenlist import FrozenList |
5 | 6 | import re
|
6 | 7 | import typing
|
7 | 8 | from collections import OrderedDict, UserList, defaultdict
|
@@ -149,10 +150,10 @@ def default_encoder(
|
149 | 150 | encoder: CBOREncoder, value: Union[CBORSerializable, IndefiniteList]
|
150 | 151 | ):
|
151 | 152 | """A fallback function that encodes CBORSerializable to CBOR"""
|
152 |
| - assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR)), ( |
| 153 | + assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR, FrozenList)), ( |
153 | 154 | f"Type of input value is not CBORSerializable, " f"got {type(value)} instead."
|
154 | 155 | )
|
155 |
| - if isinstance(value, IndefiniteList): |
| 156 | + if isinstance(value, IndefiniteList) or isinstance(value, FrozenList): |
156 | 157 | # Currently, cbor2 doesn't support indefinite list, therefore we need special
|
157 | 158 | # handling here to explicitly write header (b'\x9f'), each body item, and footer (b'\xff') to
|
158 | 159 | # the output bytestring.
|
@@ -253,7 +254,9 @@ def _dfs(value):
|
253 | 254 | elif isinstance(value, IndefiniteList):
|
254 | 255 | return IndefiniteList([_helper(k) for k in value])
|
255 | 256 | elif isinstance(value, CBORTag):
|
256 |
| - return CBORTag(value.tag, _helper(value.value)) |
| 257 | + value_list = FrozenList(_helper(value.value)) |
| 258 | + value_list.freeze() |
| 259 | + return CBORTag(value.tag, value_list) |
257 | 260 | else:
|
258 | 261 | return value
|
259 | 262 |
|
|
0 commit comments