MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _Pickler

Class _Pickler

tools/python-3.11.9-amd64/Lib/pickle.py:407–1132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405# Pickling machinery
406
407class _Pickler:
408
409 def __init__(self, file, protocol=None, *, fix_imports=True,
410 buffer_callback=None):
411 """This takes a binary file for writing a pickle data stream.
412
413 The optional *protocol* argument tells the pickler to use the
414 given protocol; supported protocols are 0, 1, 2, 3, 4 and 5.
415 The default protocol is 4. It was introduced in Python 3.4, and
416 is incompatible with previous versions.
417
418 Specifying a negative protocol version selects the highest
419 protocol version supported. The higher the protocol used, the
420 more recent the version of Python needed to read the pickle
421 produced.
422
423 The *file* argument must have a write() method that accepts a
424 single bytes argument. It can thus be a file object opened for
425 binary writing, an io.BytesIO instance, or any other custom
426 object that meets this interface.
427
428 If *fix_imports* is True and *protocol* is less than 3, pickle
429 will try to map the new Python 3 names to the old module names
430 used in Python 2, so that the pickle data stream is readable
431 with Python 2.
432
433 If *buffer_callback* is None (the default), buffer views are
434 serialized into *file* as part of the pickle stream.
435
436 If *buffer_callback* is not None, then it can be called any number
437 of times with a buffer view. If the callback returns a false value
438 (such as None), the given buffer is out-of-band; otherwise the
439 buffer is serialized in-band, i.e. inside the pickle stream.
440
441 It is an error if *buffer_callback* is not None and *protocol*
442 is None or smaller than 5.
443 """
444 if protocol is None:
445 protocol = DEFAULT_PROTOCOL
446 if protocol < 0:
447 protocol = HIGHEST_PROTOCOL
448 elif not 0 <= protocol <= HIGHEST_PROTOCOL:
449 raise ValueError("pickle protocol must be <= %d" % HIGHEST_PROTOCOL)
450 if buffer_callback is not None and protocol < 5:
451 raise ValueError("buffer_callback needs protocol >= 5")
452 self._buffer_callback = buffer_callback
453 try:
454 self._file_write = file.write
455 except AttributeError:
456 raise TypeError("file must have a 'write' attribute")
457 self.framer = _Framer(self._file_write)
458 self.write = self.framer.write
459 self._write_large_bytes = self.framer.write_large_bytes
460 self.memo = {}
461 self.proto = int(protocol)
462 self.bin = protocol >= 1
463 self.fast = 0
464 self.fix_imports = fix_imports and protocol < 3

Callers 2

_dumpFunction · 0.85
_dumpsFunction · 0.85

Calls 1

typeClass · 0.50

Tested by

no test coverage detected