-
Notifications
You must be signed in to change notification settings - Fork 92
Pickles
Jim Fulton edited this page Mar 18, 2013
·
12 revisions
It's useful to be able to support accessing databases from both Python 2 and Python 3 because:
- You may have multiple applications accessing a database, or multiple installations of the same applications that are moved to Python 3 at different times. Supporting both Python versions will make transition much easier.
- Eventually, ZODB may support other languages, especially Javascript. It would be a shame if we could support Javascript but not Python 2.
- Python 3 uses different pickling codes than Python 2. In particular, the Python 2 bytes (STRING, BINSTRING, and SHORTBINSTRING) are DWIMilly interpreted as text in some encoding. Python 3 saves bytes with a Python 3-specific bytecode (BYTES and BINBYTES).
- Names (attribute, and global) in Python 3 are unicode in Python 3 but bytes in Python 2.
- Python2 pickle with name conversion
-
Read and store byte data using Python 2 byte codes using a forked version of pickle, zodbpickle. Fix up names when necessary in Python 3.
-
When finding globals or setting instance state, convert byte names to unicode using an ascii encoding.
We can only fix up attribute names when no custom set state is used. So this is only a partial solution. Applications with custom
__setstate__
methods may not be interoperable accross Python versions or may need to be modified. -
Note that Python 2 attributes can be stored as unicode. (They can only be accessed with attribute notation if they're ASCII.)
-