Skip to main content

Fork of Python 3 pickle module.

Project description

zodbpickle README

https://travis-ci.org/zopefoundation/zodbpickle.png?branch=master PyPI Python versions

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.7.0 (2017-09-22)

  • Drop support for Python 2.6 and 3.2.

  • Add support for Jython 2.7.

  • Add support for Python 3.5 and 3.6.

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.7.0.tar.gz (181.3 kB view details)

Uploaded Source

Built Distributions

zodbpickle-0.7.0-cp36-cp36m-win_amd64.whl (219.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

zodbpickle-0.7.0-cp36-cp36m-win32.whl (211.9 kB view details)

Uploaded CPython 3.6m Windows x86

zodbpickle-0.7.0-cp35-cp35m-win_amd64.whl (219.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

zodbpickle-0.7.0-cp35-cp35m-win32.whl (211.9 kB view details)

Uploaded CPython 3.5m Windows x86

zodbpickle-0.7.0-cp34-cp34m-win_amd64.whl (216.2 kB view details)

Uploaded CPython 3.4m Windows x86-64

zodbpickle-0.7.0-cp34-cp34m-win32.whl (210.3 kB view details)

Uploaded CPython 3.4m Windows x86

zodbpickle-0.7.0-cp33-cp33m-win_amd64.whl (216.3 kB view details)

Uploaded CPython 3.3m Windows x86-64

zodbpickle-0.7.0-cp33-cp33m-win32.whl (210.6 kB view details)

Uploaded CPython 3.3m Windows x86

zodbpickle-0.7.0-cp27-cp27m-win_amd64.whl (212.0 kB view details)

Uploaded CPython 2.7m Windows x86-64

zodbpickle-0.7.0-cp27-cp27m-win32.whl (208.1 kB view details)

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

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

File hashes

Hashes for zodbpickle-0.7.0.tar.gz
Algorithm Hash digest
SHA256 95a247fb17bce980af8d548af70ac5bd1bad22773f242eb8efa24428efa909a8
MD5 5ad123465fb7283983b15e11d1df7ebd
BLAKE2b-256 95240b61c9c1d4c9442c95b7245883257b83f5ad9e929d77be5e5493315b30e7

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 92359f9b5cbf0ea0a200bc332931aa9de3a59a351f7c7e5e9eb6a89ee76fb2db
MD5 cd5f75664159bfd6db4a3bcd55a33d09
BLAKE2b-256 68d31c016b1b5b98a102691f65afdda52aac9d7eff5e6dc838c491f5145d57b1

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 d320f6ba7ce9cae813a47d48d4c406adb766e27eb2a0b356027f4358a35c4f9c
MD5 be981c8f842aecdc9a7d7e7be6428dcf
BLAKE2b-256 57b9c2e7f3bbfb4c86a0e5286f5489ff44ac48b278b17b70a51e9ca73157c5bc

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 460523b3ccd108eb80037cfb980cf8932e636c9090902dc4691554b45dd5f86c
MD5 7d27d9a31b4e9be77d076372d11607f7
BLAKE2b-256 077e5218f7cab13060b9640effbb50d611521adfa4ef9f76d6800875c0593959

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 3aa2c39d8e5c43c703beddeb5765df3e25b7f38b647b439d685cad721e3bf902
MD5 03ab20cd72df7b8ca145862f39b7a56f
BLAKE2b-256 eecda179fe88377690712ec5658f570f8eacb838651d0223be4a2992d73ffd5d

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 522f7d5361d546942c74f346301855edf47a373618e99d0a0e1d4038d7dd26eb
MD5 585666ec0cbc99f0ef8c175a63c47e40
BLAKE2b-256 378bf9f9fda5ebc276b47865ea64c4979cd8cd4b184614a6663704ca47fcf32b

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 8371f5988f3e1189139e05c7aaf1024c4a6160737f6bad4d64b59f6ad341443e
MD5 5ba4ae6b1e951516a5ac4cc7d29c2223
BLAKE2b-256 c259075c1d879110ecbaa3f16ef423ede94a94664fb71d2f792e101fb99fba30

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp33-cp33m-win_amd64.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 1199f5e2685cb8194fa1b477281401768c63cf9775e810bed8ac2828499ec510
MD5 ca71507fcd7fef8541c7b9abd4b01fe4
BLAKE2b-256 4fbf5b6be7fd1369b9825671aee9de1f422e774e9b42abfcecb6a4c4410cd86c

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 5e4e396ad6c31ada0ebdecadf668a7de399d3daf95ace9f24271f3d0bd7c36c1
MD5 5587ed1e1a7f45aee8dc700fe59997b8
BLAKE2b-256 5255831b56724ca986fbd88ec9a62c412ab5b9231ac32d863bcff7312d5cce39

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 0d6c8b39a5b1454b5bf7ad8c728e4a5f3f3ae98d44125d7e9bbef4082e58c5fd
MD5 689eb5602e292ad2964ca5471e269dd8
BLAKE2b-256 286aef6b38e13f36330bb0d498e36b4b2c13f42a4455b04684cbcc8b00e55e2c

See more details on using hashes here.

File details

Details for the file zodbpickle-0.7.0-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for zodbpickle-0.7.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 4d48a53fda2bebf3349ca213023d17b37a18cd0b3b113f365d15380102edeac2
MD5 7cc0c05ca4c165900e6e41e8a3ac8af3
BLAKE2b-256 5fd5ce076b84597c373eea2ca08edb61c0f1b9891904b72c877d9fdc289fe4fd

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