Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_frozendict():
assert len(FrozenDict({1: 2, 3: 4})) == 2
assert repr(FrozenDict({1: 2})) == "FrozenDict({1: 2})"
def test_frozendict():
assert len(FrozenDict({1: 2, 3: 4})) == 2
assert repr(FrozenDict({1: 2})) == "FrozenDict({1: 2})"
def test_dict_key(impl):
assert impl.dumps({FrozenDict({2: 1}): u''}) == unhexlify('a1a1020160')
(('ipaddress', 'IPv6Address'), CBOREncoder.encode_ipaddress),
(('ipaddress', 'IPv4Network'), CBOREncoder.encode_ipnetwork),
(('ipaddress', 'IPv6Network'), CBOREncoder.encode_ipnetwork),
(CBORSimpleValue, CBOREncoder.encode_simple_value),
(CBORTag, CBOREncoder.encode_semantic),
(set, CBOREncoder.encode_set),
(frozenset, CBOREncoder.encode_set),
])
canonical_encoders = OrderedDict([
(float, CBOREncoder.encode_minimal_float),
(dict, CBOREncoder.encode_canonical_map),
(defaultdict, CBOREncoder.encode_canonical_map),
(OrderedDict, CBOREncoder.encode_canonical_map),
(FrozenDict, CBOREncoder.encode_canonical_map),
(set, CBOREncoder.encode_canonical_set),
(frozenset, CBOREncoder.encode_canonical_set),
])
def dumps(obj, **kwargs):
"""
Serialize an object to a bytestring.
:param obj: the object to serialize
:param kwargs: keyword arguments passed to :class:`~.CBOREncoder`
:return: the serialized output
:rtype: bytes
"""
with BytesIO() as fp:
for index in range(length):
key = self._decode(immutable=True, unshared=True)
seq[index] = (key, self._decode(unshared=True))
dictionary = dict(seq)
else:
dictionary = {}
self.set_shareable(dictionary)
for _ in range(length):
key = self._decode(immutable=True, unshared=True)
dictionary[key] = self._decode(unshared=True)
if self._object_hook:
dictionary = self._object_hook(self, dictionary)
self.set_shareable(dictionary)
elif self._immutable:
dictionary = FrozenDict(dictionary)
self.set_shareable(dictionary)
return dictionary