(self, items, obj)
| 1082 | dispatch[dict] = save_dict |
| 1083 | |
| 1084 | def _batch_setitems(self, items, obj): |
| 1085 | # Helper to batch up SETITEMS sequences; proto >= 1 only |
| 1086 | save = self.save |
| 1087 | write = self.write |
| 1088 | |
| 1089 | if not self.bin: |
| 1090 | for k, v in items: |
| 1091 | save(k) |
| 1092 | try: |
| 1093 | save(v) |
| 1094 | except BaseException as exc: |
| 1095 | exc.add_note(f'when serializing {_T(obj)} item {k!r}') |
| 1096 | raise |
| 1097 | write(SETITEM) |
| 1098 | return |
| 1099 | |
| 1100 | for batch in batched(items, self._BATCHSIZE): |
| 1101 | if len(batch) != 1: |
| 1102 | write(MARK) |
| 1103 | for k, v in batch: |
| 1104 | save(k) |
| 1105 | try: |
| 1106 | save(v) |
| 1107 | except BaseException as exc: |
| 1108 | exc.add_note(f'when serializing {_T(obj)} item {k!r}') |
| 1109 | raise |
| 1110 | write(SETITEMS) |
| 1111 | else: |
| 1112 | k, v = batch[0] |
| 1113 | save(k) |
| 1114 | try: |
| 1115 | save(v) |
| 1116 | except BaseException as exc: |
| 1117 | exc.add_note(f'when serializing {_T(obj)} item {k!r}') |
| 1118 | raise |
| 1119 | write(SETITEM) |
| 1120 | |
| 1121 | def save_set(self, obj): |
| 1122 | save = self.save |
no test coverage detected