(self, execute=EX_CONSTRUCT)
| 489 | return typ, n, obj |
| 490 | |
| 491 | def _unpack(self, execute=EX_CONSTRUCT): |
| 492 | typ, n, obj = self._read_header() |
| 493 | |
| 494 | if execute == EX_READ_ARRAY_HEADER: |
| 495 | if typ != TYPE_ARRAY: |
| 496 | raise ValueError("Expected array") |
| 497 | return n |
| 498 | if execute == EX_READ_MAP_HEADER: |
| 499 | if typ != TYPE_MAP: |
| 500 | raise ValueError("Expected map") |
| 501 | return n |
| 502 | # TODO should we eliminate the recursion? |
| 503 | if typ == TYPE_ARRAY: |
| 504 | if execute == EX_SKIP: |
| 505 | for i in range(n): |
| 506 | # TODO check whether we need to call `list_hook` |
| 507 | self._unpack(EX_SKIP) |
| 508 | return |
| 509 | ret = newlist_hint(n) |
| 510 | for i in range(n): |
| 511 | ret.append(self._unpack(EX_CONSTRUCT)) |
| 512 | if self._list_hook is not None: |
| 513 | ret = self._list_hook(ret) |
| 514 | # TODO is the interaction between `list_hook` and `use_list` ok? |
| 515 | return ret if self._use_list else tuple(ret) |
| 516 | if typ == TYPE_MAP: |
| 517 | if execute == EX_SKIP: |
| 518 | for i in range(n): |
| 519 | # TODO check whether we need to call hooks |
| 520 | self._unpack(EX_SKIP) |
| 521 | self._unpack(EX_SKIP) |
| 522 | return |
| 523 | if self._object_pairs_hook is not None: |
| 524 | ret = self._object_pairs_hook( |
| 525 | (self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n) |
| 526 | ) |
| 527 | else: |
| 528 | ret = {} |
| 529 | for _ in range(n): |
| 530 | key = self._unpack(EX_CONSTRUCT) |
| 531 | if self._strict_map_key and type(key) not in (str, bytes): |
| 532 | raise ValueError("%s is not allowed for map key" % str(type(key))) |
| 533 | if isinstance(key, str): |
| 534 | key = sys.intern(key) |
| 535 | ret[key] = self._unpack(EX_CONSTRUCT) |
| 536 | if self._object_hook is not None: |
| 537 | ret = self._object_hook(ret) |
| 538 | return ret |
| 539 | if execute == EX_SKIP: |
| 540 | return |
| 541 | if typ == TYPE_RAW: |
| 542 | if self._raw: |
| 543 | obj = bytes(obj) |
| 544 | else: |
| 545 | obj = obj.decode("utf_8", self._unicode_errors) |
| 546 | return obj |
| 547 | if typ == TYPE_BIN: |
| 548 | return bytes(obj) |
no test coverage detected