Skip to main content

Fork of Python 3 pickle module.

Project description

zodbpickle README

This package presents a uniform pickling interface for ZODB:

  • Under Python2, this package forks both Python 2.7’s pickle and cPickle modules, adding support for the protocol 3 opcodes. It also provides a new subclass of bytes, zodbpickle.binary, which Python2 applications can use to pickle binary values such that they will be unpickled as bytes under Py3k.

  • Under Py3k, this package forks the pickle module (and the supporting C extension) from both Python 3.2 and Python 3.3. The fork add support for the noload operations used by ZODB.

General Usage

To get compatibility between Python 2 and 3 pickling, replace:

import pickle

by:

from zodbpickle import pickle

This provides compatibility, but has the effect that you get the fast implementation in Python 3, while Python 2 uses the slow version.

To get a more deterministic choice of the implementation, use one of:

from zodbpickle import fastpickle # always C
from zodbpickle import slowpickle # always Python

Both modules can co-exist which is helpful for comparison.

But there is a bit more to consider, so please read on!

Loading/Storing Python 2 Strings

In all their wisdom, the Python developers have decided that Python 2 str instances should be loaded as Python 3 str objects (i.e. unicode strings). Patches were proposed in Python issue 6784 but were never applied. This code base contains those patches.

Example 1: Loading Python 2 pickles on Python 3

$ python2
>>> import pickle
>>> pickle.dumps('\xff', protocol=0)
"S'\\xff'\np0\n."
>>> pickle.dumps('\xff', protocol=1)
'U\x01\xffq\x00.'
>>> pickle.dumps('\xff', protocol=2)
'\x80\x02U\x01\xffq\x00.'

$ python3
>>> from zodbpickle import pickle
>>> pickle.loads(b"S'\\xff'\np0\n.", encoding='bytes')
b'\xff'
>>> pickle.loads(b'U\x01\xffq\x00.', encoding='bytes')
b'\xff'
>>> pickle.loads(b'\x80\x02U\x01\xffq\x00.', encoding='bytes')
b'\xff'

Example 2: Loading Python 3 pickles on Python 2

$ python3
>>> from zodbpickle import pickle
>>> pickle.dumps(b"\xff", protocol=0)
b'c_codecs\nencode\np0\n(V\xff\np1\nVlatin1\np2\ntp3\nRp4\n.'
>>> pickle.dumps(b"\xff", protocol=1)
b'c_codecs\nencode\nq\x00(X\x02\x00\x00\x00\xc3\xbfq\x01X\x06\x00\x00\x00latin1q\x02tq\x03Rq\x04.'
>>> pickle.dumps(b"\xff", protocol=2)
b'\x80\x02c_codecs\nencode\nq\x00X\x02\x00\x00\x00\xc3\xbfq\x01X\x06\x00\x00\x00latin1q\x02\x86q\x03Rq\x04.'

$ python2
>>> import pickle
>>> pickle.loads('c_codecs\nencode\np0\n(V\xff\np1\nVlatin1\np2\ntp3\nRp4\n.')
'\xff'
>>> pickle.loads('c_codecs\nencode\nq\x00(X\x02\x00\x00\x00\xc3\xbfq\x01X\x06\x00\x00\x00latin1q\x02tq\x03Rq\x04.')
'\xff'
>>> pickle.loads('\x80\x02c_codecs\nencode\nq\x00X\x02\x00\x00\x00\xc3\xbfq\x01X\x06\x00\x00\x00latin1q\x02\x86q\x03Rq\x04.')
'\xff'

Example 3: everything breaks down

$ python2
>>> class Foo(object):
...     def __init__(self):
...         self.x = 'hello'
...
>>> import pickle
>>> pickle.dumps(Foo(), protocol=0)
"ccopy_reg\n_reconstructor\np0\n(c__main__\nFoo\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'x'\np6\nS'hello'\np7\nsb."
>>> pickle.dumps(Foo(), protocol=1)
'ccopy_reg\n_reconstructor\nq\x00(c__main__\nFoo\nq\x01c__builtin__\nobject\nq\x02Ntq\x03Rq\x04}q\x05U\x01xq\x06U\x05helloq\x07sb.'
>>> pickle.dumps(Foo(), protocol=2)
'\x80\x02c__main__\nFoo\nq\x00)\x81q\x01}q\x02U\x01xq\x03U\x05helloq\x04sb.'

$ python3
>>> from zodbpickle import pickle
>>> class Foo(object): pass
...
>>> foo = pickle.loads("ccopy_reg\n_reconstructor\np0\n(c__main__\nFoo\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'x'\np6\nS'hello'\np7\nsb.", encoding='bytes')
>>> foo.x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'x'

wait what?

>>> foo.__dict__
{b'x': b'hello'}

oooh. So we use encoding='ASCII' (the default) and errors='bytes' and hope it works:

>>> foo = pickle.loads("ccopy_reg\n_reconstructor\np0\n(c__main__\nFoo\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'x'\np6\nS'hello'\np7\nsb.", errors='bytes')
>>> foo.x
'hello'

falling back to bytes if necessary

>>> pickle.loads(b'\x80\x02U\x01\xffq\x00.', errors='bytes')
b'\xff'

Support for noload()

The ZODB uses cPickle’s noload() method to retrieve all persistent references from a pickle without loading any objects. This feature was removed from Python 3’s pickle. Unfortuantely, this unnecessarily fills the pickle cache.

This module provides a noload() method again.

zodbpickle Changelog

0.6.0 (2015-04-02)

  • Restore the noload behaviour from Python 2.6 and provide the noload method on the non-C-accelerated unpicklers under PyPy and Python 2.

  • Add support for PyPy, PyPy3, and Python 3.4.

0.5.2 (2013-08-17)

0.5.1 (2013-07-06)

  • Update all code and tests to Python 2.6.8, 2.7.5, 3.2.5, 3.3.2 .

  • Add the modules zodbpickle.fastpickle and zodbpickle.slowpickle. This provides a version-independent choice of the C or Python implementation.

  • Fix a minor bug on OS X

0.5.0 (2013-06-14)

  • Removed support for the bytes_as_strings arguments to pickling APIs: the pickles created when that argument was true might not be unpickled without passing encoding='bytes', which ZODB couldn’t reliably enforce. On Py3k, ZODB will be using protocol=3 pickles anyway.

0.4.4 (2013-06-07)

  • Add protocol 3 opcodes to the C version of the noload() dispatcher.

0.4.3 (2013-06-07)

  • Packaging error: remove spurious -ASIDE file from sdist.

0.4.2 (2013-06-07)

  • Fix NameError in pure-Python version of Unpickler.noload_appends.

  • Fix NameError in pure-Python version of Unpickler.noload_setitems.

0.4.1 (2013-04-29)

  • Fix typo in Python2 version of zodbpickle.pickle module.

0.4 (2013-04-28)

  • Support the common pickle module interface for Python 2.6, 2.7, 3.2, and 3.3.

  • Split the Python implementations / tests into Python2- and Py3k-specific variants.

  • Added a fork of the Python 2.7 _pickle.c, for use under Python2. The fork adds support for the Py3k protocol 3 opcodes.

  • Added a custom binary type for use in Python2 apps. Derived from bytes, the binary type allows Python2 apps to pickle binary data using opcodes which will cause it to be unpickled as bytes on Py3k. Under Py3k, the binary type is just an alias for bytes.

0.3 (2013-03-18)

  • Added noload code to Python 3.2 version of Unpickler. As with the Python 3.3 version, this code remains untested.

  • Added bytes_as_strings option to the Python 3.2 version of Pickler, dump, and dumps.

0.2 (2013-03-05)

  • Added bytes_as_strings option to Pickler, dump, and dumps.

  • Incomplete support for Python 3.2:

    • Move _pickle.c -> _pickle_33.c.

    • Clone Python 3.2.3’s _pickle.c -> _pickle_32.c and apply the same patch.

    • Choose between them at build time based on sys.version_info.

    • Disable some tests of 3.3-only features.

    • Missing: implementation of noload() in _pickle_32.c.

    • Missing: implementation of bytes_as_strings=True in _pickle_32.c.

0.1.0 (2013-02-27)

  • Initial release of Python 3.3’s pickle with the patches of Python issue 6784 applied.

  • Added support for errors="bytes".

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zodbpickle-0.6.0.tar.gz (223.0 kB view details)

Uploaded Source

Built Distributions

zodbpickle-0.6.0.win-amd64-py3.4.exe (487.0 kB view details)

Uploaded Source

zodbpickle-0.6.0.win-amd64-py3.3.exe (487.2 kB view details)

Uploaded Source

zodbpickle-0.6.0.win-amd64-py2.7.exe (484.5 kB view details)

Uploaded Source

zodbpickle-0.6.0.win-amd64-py2.6.exe (484.5 kB view details)

Uploaded Source

zodbpickle-0.6.0.win32-py3.4.exe (449.9 kB view details)

Uploaded Source

zodbpickle-0.6.0.win32-py3.3.exe (450.2 kB view details)

Uploaded Source

zodbpickle-0.6.0.win32-py2.7.exe (453.0 kB view details)

Uploaded Source

zodbpickle-0.6.0.win32-py2.6.exe (453.1 kB view details)

Uploaded Source

zodbpickle-0.6.0-py3.4-win-amd64.egg (325.3 kB view details)

Uploaded Source

zodbpickle-0.6.0-py3.4-win32.egg (319.4 kB view details)

Uploaded Source

zodbpickle-0.6.0-py3.3-win-amd64.egg (328.0 kB view details)

Uploaded Source

zodbpickle-0.6.0-py3.3-win32.egg (322.2 kB view details)

Uploaded Source

zodbpickle-0.6.0-py2.7-win-amd64.egg (309.7 kB view details)

Uploaded Source

zodbpickle-0.6.0-py2.7-win32.egg (305.8 kB view details)

Uploaded Source

zodbpickle-0.6.0-py2.6-win-amd64.egg (309.9 kB view details)

Uploaded Source

zodbpickle-0.6.0-py2.6-win32.egg (306.0 kB view details)

Uploaded Source

File details

Details for the file zodbpickle-0.6.0.tar.gz.

File metadata

  • Download URL: zodbpickle-0.6.0.tar.gz
  • Upload date:
  • Size: 223.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zodbpickle-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ea3248be966159e7791e3db0e35ea992b9235d52e7d39835438686741d196665
MD5 bd050064511eaf2ac276a21bedf9d072
BLAKE2b-256 7afcf6f437a5222b330735eaf8f1e67a6845bd1b600e9a9455e552d3c13c4902

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 716eb0be86d1b7eaa72b83f55a09586919e88535cd5e0117c65782dc5dba518f
MD5 612ec987d9057a4a67f8e647bdb79fe3
BLAKE2b-256 a781aa4983ea958ef9aa199dcf0c3158e575613d08935408bdca386a19ce23dc

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 9728f787876bd1a001f89d70d74b3be8b9e7ccdfb61400bcaecb8d6a27fe83e4
MD5 f76e7fcc33fd9665f71cc67134cd3f95
BLAKE2b-256 470770f3745cc77f15d722ab75f53fc432cf01e2b354ed129c03f15bce8fe20e

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 5937628f2aa56bc097e097a1a269ba9dbd04c02193d0177f889c1d14f4a303cd
MD5 356aaf4a1a2fb0087bdcc8196ea01dc8
BLAKE2b-256 268a70d7fd59abf0f035869065cba2b51e3201805c970efdeccd98dd7fb2005b

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 64c82aef492278455d8e0506f66e6764f23c7c7048db9e0659db5fa45377ff7b
MD5 cab34ca25aa8a4758cd798a2fd9721a4
BLAKE2b-256 a3c4edd21b58f064cea088992395d556992f0a3e383a989e0c2b3410e5777274

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win32-py3.4.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win32-py3.4.exe
Algorithm Hash digest
SHA256 71c4ccb51aad026e16d4b7ce81c8b9ee66c06bfd41d111136c75ad8ef298e9c4
MD5 e6b59a10379c6fb3a10c7237ac1a870e
BLAKE2b-256 1a6d67480f09ff85f6284add74617b10276e83b23d1cf00e9bf4b3366bc85267

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win32-py3.3.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win32-py3.3.exe
Algorithm Hash digest
SHA256 ec00e0b21119bec9c4135c824abaaeeac02b3034476af1894508d475b2ee9fa7
MD5 785ec5c7d00a8b160050daf73a519fdc
BLAKE2b-256 ac6c2f2daa31709b7edb31aa55be9a004d704df7744c13395d02250ea67580ee

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win32-py2.7.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win32-py2.7.exe
Algorithm Hash digest
SHA256 41b0ca802972195f51e76a855bb59daae9a992cb61eb155dee1b0807a75e9b9e
MD5 ec29662c113e7c1ab4ad0cc47f87846d
BLAKE2b-256 eacada07bc1fc664f18569c754a69bdb957fb2a8f7edee75aad405d0df5b3c1e

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0.win32-py2.6.exe.

File metadata

File hashes

Hashes for zodbpickle-0.6.0.win32-py2.6.exe
Algorithm Hash digest
SHA256 a282b471531b6f82aa2858982b42f261d69c638df23f1d86859111903bc38c68
MD5 a27b1acfd108e6f30d383d09a66e80f3
BLAKE2b-256 af7640e0211d8a5b3fb7e4e9757ab7d49f37ba648119464129ca60f4701f6a44

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py3.4-win-amd64.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py3.4-win-amd64.egg
Algorithm Hash digest
SHA256 51b49f8e93d62293c57b774ce5d84178e10eba06510c6b3cea3b75acf48d8803
MD5 bc91eb56fc37e493c4c26a5391d52f79
BLAKE2b-256 b874abf0bd059b692bb29f7e1b38035bb365e5a2c4251165ccd7a3c6e0ab91e6

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py3.4-win32.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py3.4-win32.egg
Algorithm Hash digest
SHA256 018c56cbcc7173d23b606162286c54dffb617365ec683e0497210d2540c31b3d
MD5 5db1b44572be5c64d96361703fefb5bd
BLAKE2b-256 cd2fd103886763e9211c8bca3228446fd246ab7b4724f9639d82146798f20e50

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py3.3-win-amd64.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py3.3-win-amd64.egg
Algorithm Hash digest
SHA256 92ba1411653d30a41793d1e52f9a193979600f7afd2a6ab5a7171a496f8a8cb6
MD5 ba58586bc4cc0dad90350c8c9b17ed52
BLAKE2b-256 63bdacd90f0a00b58977e4be878d5e7d6b879d4c88513bbac7eafdaef407ba26

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py3.3-win32.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py3.3-win32.egg
Algorithm Hash digest
SHA256 d340606be588752f8ca498898cf06a3ddc0949f2cb6e3fff6d663fc289240264
MD5 37aca0131d89057a53f83615dde89658
BLAKE2b-256 6616c9ba21ce75479008f18a77962f49f92a8860cb2776a85985f1e5419fe197

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py2.7-win-amd64.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 40bfa2ce16f17c4020f4ce2a99855b5fe4778ee85df748925d07f577cc382c22
MD5 510debaccbf42b916c563c35e366c2c6
BLAKE2b-256 f517ac9f9220ccb517e8b5b906ff6c428747064a16fbee22e2eb6ff0b0196d8e

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py2.7-win32.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py2.7-win32.egg
Algorithm Hash digest
SHA256 8624381abb49bdf66ca32b2f62b4ba0c2314bcf8e7e9feb0fef39d9ae5f6a9a0
MD5 b5a62fa8104af42c9ccc53c176c78ad3
BLAKE2b-256 5e9c471b4b631bf079477bcf13411024b1ca56ff2c218bfd64dd86bf5d48a27c

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py2.6-win-amd64.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 43d82d7d7b64715225491a91b767f06938462cc859638d778f9a376a23099c28
MD5 362192c2c9730569c5e51e9a2dc159ee
BLAKE2b-256 8bb7cc15fd5b3839d31f0f99fda3b3444aba0427ae7a3ae69dcf4325d7f6637d

See more details on using hashes here.

File details

Details for the file zodbpickle-0.6.0-py2.6-win32.egg.

File metadata

File hashes

Hashes for zodbpickle-0.6.0-py2.6-win32.egg
Algorithm Hash digest
SHA256 e7229162d9a316b82fcb3db748c97d4589c917b06cacd703d0bf42b166b3b31e
MD5 38438a9f5eeb86c6166386d8636a42a9
BLAKE2b-256 af78d9eec7c96de4152a6992aa41f0a7aa9b50d386da332be52119b38ea7a943

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page