(code, fp, options)
| 733 | |
| 734 | |
| 735 | def _unpack_map(code, fp, options): |
| 736 | if (ord(code) & 0xf0) == 0x80: |
| 737 | length = (ord(code) & ~0xf0) |
| 738 | elif code == b'\xde': |
| 739 | length = struct.unpack(">H", _read_except(fp, 2))[0] |
| 740 | elif code == b'\xdf': |
| 741 | length = struct.unpack(">I", _read_except(fp, 4))[0] |
| 742 | else: |
| 743 | raise Exception("logic error, not map: 0x%02x" % ord(code)) |
| 744 | |
| 745 | d = {} if not options.get('use_ordered_dict') \ |
| 746 | else collections.OrderedDict() |
| 747 | for _ in xrange(length): |
| 748 | # Unpack key |
| 749 | k = _unpack(fp, options) |
| 750 | |
| 751 | if isinstance(k, list): |
| 752 | # Attempt to convert list into a hashable tuple |
| 753 | k = _deep_list_to_tuple(k) |
| 754 | elif not isinstance(k, collections.Hashable): |
| 755 | raise UnhashableKeyException( |
| 756 | "encountered unhashable key: %s, %s" % (str(k), str(type(k)))) |
| 757 | elif k in d: |
| 758 | raise DuplicateKeyException( |
| 759 | "encountered duplicate key: %s, %s" % (str(k), str(type(k)))) |
| 760 | |
| 761 | # Unpack value |
| 762 | v = _unpack(fp, options) |
| 763 | |
| 764 | try: |
| 765 | d[k] = v |
| 766 | except TypeError: |
| 767 | raise UnhashableKeyException( |
| 768 | "encountered unhashable key: %s" % str(k)) |
| 769 | return d |
| 770 | |
| 771 | |
| 772 | def _unpack(fp, options): |
nothing calls this directly
no test coverage detected