MCPcopy Index your code
hub / github.com/python/cpython / save_picklebuffer

Method save_picklebuffer

Lib/pickle.py:908–938  ·  view source on GitHub ↗
(self, obj)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

_save_bytes_no_memoMethod · 0.95
save_bytesMethod · 0.95
save_bytearrayMethod · 0.95
PicklingErrorClass · 0.85
idFunction · 0.85
rawMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected