(self, obj)
| 890 | |
| 891 | if _HAVE_PICKLE_BUFFER: |
| 892 | def save_picklebuffer(self, obj): |
| 893 | if self.proto < 5: |
| 894 | raise PicklingError("PickleBuffer can only be pickled with " |
| 895 | "protocol >= 5") |
| 896 | with obj.raw() as m: |
| 897 | if not m.contiguous: |
| 898 | raise PicklingError("PickleBuffer can not be pickled when " |
| 899 | "pointing to a non-contiguous buffer") |
| 900 | in_band = True |
| 901 | if self._buffer_callback is not None: |
| 902 | in_band = bool(self._buffer_callback(obj)) |
| 903 | if in_band: |
| 904 | # Write data in-band |
| 905 | # XXX The C implementation avoids a copy here |
| 906 | buf = m.tobytes() |
| 907 | in_memo = id(buf) in self.memo |
| 908 | if m.readonly: |
| 909 | if in_memo: |
| 910 | self._save_bytes_no_memo(buf) |
| 911 | else: |
| 912 | self.save_bytes(buf) |
| 913 | else: |
| 914 | if in_memo: |
| 915 | self._save_bytearray_no_memo(buf) |
| 916 | else: |
| 917 | self.save_bytearray(buf) |
| 918 | else: |
| 919 | # Write data out-of-band |
| 920 | self.write(NEXT_BUFFER) |
| 921 | if m.readonly: |
| 922 | self.write(READONLY_BUFFER) |
| 923 | |
| 924 | dispatch[PickleBuffer] = save_picklebuffer |
| 925 |
nothing calls this directly
no test coverage detected