(self, items, obj)
| 1035 | _BATCHSIZE = 1000 |
| 1036 | |
| 1037 | def _batch_appends(self, items, obj): |
| 1038 | # Helper to batch up APPENDS sequences |
| 1039 | save = self.save |
| 1040 | write = self.write |
| 1041 | |
| 1042 | if not self.bin: |
| 1043 | for i, x in enumerate(items): |
| 1044 | try: |
| 1045 | save(x) |
| 1046 | except BaseException as exc: |
| 1047 | exc.add_note(f'when serializing {_T(obj)} item {i}') |
| 1048 | raise |
| 1049 | write(APPEND) |
| 1050 | return |
| 1051 | |
| 1052 | start = 0 |
| 1053 | for batch in batched(items, self._BATCHSIZE): |
| 1054 | batch_len = len(batch) |
| 1055 | if batch_len != 1: |
| 1056 | write(MARK) |
| 1057 | for i, x in enumerate(batch, start): |
| 1058 | try: |
| 1059 | save(x) |
| 1060 | except BaseException as exc: |
| 1061 | exc.add_note(f'when serializing {_T(obj)} item {i}') |
| 1062 | raise |
| 1063 | write(APPENDS) |
| 1064 | else: |
| 1065 | try: |
| 1066 | save(batch[0]) |
| 1067 | except BaseException as exc: |
| 1068 | exc.add_note(f'when serializing {_T(obj)} item {start}') |
| 1069 | raise |
| 1070 | write(APPEND) |
| 1071 | start += batch_len |
| 1072 | |
| 1073 | def save_dict(self, obj): |
| 1074 | if self.bin: |
no test coverage detected