(self, obj)
| 906 | |
| 907 | if _HAVE_PICKLE_BUFFER: |
| 908 | def save_picklebuffer(self, obj): |
| 909 | if self.proto < 5: |
| 910 | raise PicklingError("PickleBuffer can only be pickled with " |
| 911 | "protocol >= 5") |
| 912 | with obj.raw() as m: |
| 913 | if not m.contiguous: |
| 914 | raise PicklingError("PickleBuffer can not be pickled when " |
| 915 | "pointing to a non-contiguous buffer") |
| 916 | in_band = True |
| 917 | if self._buffer_callback is not None: |
| 918 | in_band = bool(self._buffer_callback(obj)) |
| 919 | if in_band: |
| 920 | # Write data in-band |
| 921 | # XXX The C implementation avoids a copy here |
| 922 | buf = m.tobytes() |
| 923 | in_memo = id(buf) in self.memo |
| 924 | if m.readonly: |
| 925 | if in_memo: |
| 926 | self._save_bytes_no_memo(buf) |
| 927 | else: |
| 928 | self.save_bytes(buf) |
| 929 | else: |
| 930 | if in_memo: |
| 931 | self._save_bytearray_no_memo(buf) |
| 932 | else: |
| 933 | self.save_bytearray(buf) |
| 934 | else: |
| 935 | # Write data out-of-band |
| 936 | self.write(NEXT_BUFFER) |
| 937 | if m.readonly: |
| 938 | self.write(READONLY_BUFFER) |
| 939 | |
| 940 | dispatch[PickleBuffer] = save_picklebuffer |
| 941 |
nothing calls this directly
no test coverage detected