mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-06-19 06:02:09 +00:00
fix: enforce strict_map_key with object_pairs_hook
This commit is contained in:
parent
0d600a3328
commit
e24d5de5ef
1 changed files with 9 additions and 3 deletions
|
|
@ -518,9 +518,15 @@ class Unpacker:
|
|||
self._unpack(EX_SKIP)
|
||||
return
|
||||
if self._object_pairs_hook is not None:
|
||||
ret = self._object_pairs_hook(
|
||||
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n)
|
||||
)
|
||||
|
||||
def _gen():
|
||||
for _ in range(n):
|
||||
key = self._unpack(EX_CONSTRUCT)
|
||||
if self._strict_map_key and type(key) not in (str, bytes):
|
||||
raise ValueError("%s is not allowed for map key" % str(type(key)))
|
||||
yield key, self._unpack(EX_CONSTRUCT)
|
||||
|
||||
ret = self._object_pairs_hook(_gen())
|
||||
else:
|
||||
ret = {}
|
||||
for _ in range(n):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue