Commit cf01843c authored by Tres Seaver's avatar Tres Seaver

Use protocol defined in _compat.

parent 4d046937
......@@ -31,7 +31,7 @@ import ZODB.interfaces
from ZODB import POSException
from ZODB.utils import z64, oid_repr, byte_ord, byte_chr
from ZODB.UndoLogCompatible import UndoLogCompatible
from ZODB._compat import dumps, py2_hasattr
from ZODB._compat import dumps, _protocol, py2_hasattr
log = logging.getLogger("ZODB.BaseStorage")
......@@ -235,7 +235,7 @@ class BaseStorage(UndoLogCompatible):
desc = transaction.description
ext = transaction._extension
if ext:
ext = dumps(ext, 1)
ext = dumps(ext, _protocol)
else:
ext = ""
......
......@@ -19,8 +19,7 @@ import six
import zope.interface
from ZODB.POSException import ConflictError
from ZODB.loglevels import BLATHER
from ZODB.serialize import _protocol
from ZODB._compat import BytesIO, Unpickler, Pickler
from ZODB._compat import BytesIO, Unpickler, Pickler, _protocol
# Subtle: Python 2.x has pickle.PicklingError and cPickle.PicklingError,
# and these are unrelated classes! So we shouldn't use pickle.PicklingError,
......
......@@ -23,7 +23,7 @@ import warnings
from ZODB.broken import find_global
from ZODB.utils import z64
from ZODB.Connection import Connection
from ZODB._compat import Pickler, BytesIO
from ZODB._compat import Pickler, _protocol, BytesIO
import ZODB.serialize
import transaction.weakset
......@@ -448,7 +448,7 @@ class DB(object):
# Manually create a pickle for the root to put in the storage.
# The pickle must be in the special ZODB format.
file = BytesIO()
p = Pickler(file, ZODB.serialize._protocol)
p = Pickler(file, _protocol)
p.dump((root.__class__, None))
p.dump(root.__getstate__())
t = transaction.Transaction()
......
......@@ -23,9 +23,9 @@ import six
from ZODB.blob import Blob
from ZODB.interfaces import IBlobStorage
from ZODB.POSException import ExportError
from ZODB.serialize import referencesf, _protocol
from ZODB.serialize import referencesf
from ZODB.utils import p64, u64, cp, mktemp
from ZODB._compat import Pickler, Unpickler, BytesIO
from ZODB._compat import Pickler, Unpickler, BytesIO, _protocol
logger = logging.getLogger('ZODB.ExportImport')
......
......@@ -41,7 +41,7 @@ from ZODB.fsIndex import fsIndex
from ZODB import BaseStorage, ConflictResolution, POSException
from ZODB.POSException import UndoError, POSKeyError, MultipleUndoErrors
from ZODB.utils import p64, u64, z64, as_bytes, as_text
from ZODB._compat import Pickler, loads, decodebytes, encodebytes
from ZODB._compat import Pickler, loads, decodebytes, encodebytes, _protocol
# Not all platforms have fsync
......@@ -369,7 +369,7 @@ class FileStorage(
if not self._is_read_only:
# Save the converted index.
f = open(index_name, 'wb')
p = Pickler(f, 1)
p = Pickler(f, _protocol)
info['index'] = index
p.dump(info)
f.close()
......
......@@ -17,6 +17,7 @@ try:
from cPickle import Pickler, Unpickler, dump, dumps, loads
IMPORT_MAPPING = {}
NAME_MAPPING = {}
_protocol = 1
except ImportError:
# Python 3.x: can't use stdlib's pickle because
# http://bugs.python.org/issue6784
......@@ -49,6 +50,7 @@ except ImportError:
def loads(s):
return zodbpickle.pickle.loads(s, encoding='ASCII', errors='bytes')
_protocol = 3
# XXX: consistent spelling of inst_persistent_id/persistent_id?
......
......@@ -20,7 +20,8 @@ import persistent
import zope.interface
import ZODB.interfaces
from ZODB._compat import loads, dumps, IMPORT_MAPPING, NAME_MAPPING
from ZODB._compat import IMPORT_MAPPING
from ZODB._compat import NAME_MAPPING
broken_cache = {}
......@@ -82,7 +83,10 @@ class Broken(object):
>>> r[2]
{'x': 1}
>>> a2 = loads(dumps(a, 1))
>>> from ZODB._compat import dumps
>>> from ZODB._compat import loads
>>> from ZODB._compat import _protocol
>>> a2 = loads(dumps(a, _protocol))
>>> a2
<broken not.there.Atall instance>
>>> a2.__Broken_newargs__
......
......@@ -47,6 +47,7 @@ import six
from ZODB._compat import INT_TYPES
from ZODB._compat import Pickler
from ZODB._compat import Unpickler
from ZODB._compat import _protocol
# convert between numbers and six-byte strings
......@@ -109,7 +110,7 @@ class fsIndex(object):
def save(self, pos, fname):
with open(fname, 'wb') as f:
pickler = Pickler(f, 1)
pickler = Pickler(f, _protocol)
pickler.fast = True
pickler.dump(pos)
for k, v in six.iteritems(self._data):
......
......@@ -140,14 +140,11 @@ from persistent import Persistent
from persistent.wref import WeakRefMarker, WeakRef
from ZODB import broken
from ZODB.POSException import InvalidObjectReference
from ZODB._compat import Pickler, Unpickler, BytesIO
from ZODB._compat import Pickler, Unpickler, BytesIO, _protocol
_oidtypes = bytes, type(None)
# Py3: Python 3 uses protocol 3 by default, which is not loadable by Python
# 2. If we want this, we can add a condition here for Python 3.
_protocol = 1
# Might to update or redo coptimizations to reflect weakrefs:
# from ZODB.coptimizations import new_persistent_id
......
......@@ -22,11 +22,11 @@ from persistent import Persistent
from persistent.mapping import PersistentMapping
from ZODB import DB
from ZODB.POSException import ConflictError, StorageError
from ZODB.serialize import referencesf, _protocol
from ZODB.serialize import referencesf
from ZODB.tests.MinPO import MinPO
from ZODB.tests.MTStorage import TestThread
from ZODB.tests.StorageTestBase import snooze
from ZODB._compat import loads, Pickler, Unpickler, BytesIO
from ZODB._compat import loads, Pickler, Unpickler, BytesIO, _protocol
import transaction
import ZODB.interfaces
import ZODB.tests.util
......
......@@ -25,7 +25,7 @@ import transaction
from ZODB.utils import u64
from ZODB.tests.MinPO import MinPO
from ZODB._compat import Pickler, Unpickler, BytesIO
from ZODB._compat import Pickler, Unpickler, BytesIO, _protocol
import ZODB.tests.util
......@@ -50,7 +50,7 @@ def _persistent_id(obj):
def zodb_pickle(obj):
"""Create a pickle in the format expected by ZODB."""
f = BytesIO()
p = Pickler(f, 1)
p = Pickler(f, _protocol)
if sys.version_info[0] < 3:
p.inst_persistent_id = _persistent_id
else:
......
......@@ -32,7 +32,7 @@ from ZODB.tests import HistoryStorage, IteratorStorage, Corruption
from ZODB.tests import RevisionStorage, PersistentStorage, MTStorage
from ZODB.tests import ReadOnlyStorage, RecoveryStorage
from ZODB.tests.StorageTestBase import MinPO, zodb_pickle
from ZODB._compat import dump, dumps
from ZODB._compat import dump, dumps, _protocol
class FileStorageTests(
......@@ -92,7 +92,7 @@ class FileStorageTests(
data['index'] = newindex
with open('FileStorageTests.fs.index', 'wb') as fp:
dump(data, fp, 1)
dump(data, fp, _protocol)
return index
def check_conversion_to_fsIndex(self, read_only=False):
......@@ -390,14 +390,14 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase):
j = 0
oid, revid = oids[j]
serial = self._storage.store(
oid, revid, dumps(OOBTree, 1), "", t)
oid, revid, dumps(OOBTree, _protocol), "", t)
oids[j][1] = serial
# and it could be from a broken module
j = 1
oid, revid = oids[j]
serial = self._storage.store(
oid, revid, dumps(Broken, 1), "", t)
oid, revid, dumps(Broken, _protocol), "", t)
oids[j][1] = serial
# but mostly it looks like this
......
......@@ -17,7 +17,7 @@ import unittest
import ZODB.tests.util
from ZODB import serialize
from ZODB._compat import Pickler, BytesIO
from ZODB._compat import Pickler, BytesIO, _protocol
class ClassWithNewargs(int):
......@@ -33,7 +33,7 @@ class ClassWithoutNewargs(object):
def make_pickle(ob):
sio = BytesIO()
p = Pickler(sio, 1)
p = Pickler(sio, _protocol)
p.dump(ob)
return sio.getvalue()
......
......@@ -16,7 +16,7 @@ from ZODB.blob import BushyLayout
from ZODB.DB import DB
from ZODB.FileStorage import FileStorage
from ZODB.tests.testConfig import ConfigTestBase
from ZODB._compat import Pickler, Unpickler
from ZODB._compat import Pickler, Unpickler, _protocol
import os
if os.environ.get('USE_ZOPE_TESTING_DOCTEST'):
......@@ -125,7 +125,7 @@ class BlobCloneTests(ZODB.tests.util.TestCase):
transaction.commit()
stream = BytesIO()
p = Pickler(stream, 1)
p = Pickler(stream, _protocol)
p.dump(root['blob'])
u = Unpickler(stream)
stream.seek(0)
......@@ -742,7 +742,8 @@ def storage_reusable_suite(prefix, factory,
suite = unittest.TestSuite()
suite.addTest(doctest.DocFileSuite(
"blob_connection.txt", "blob_importexport.txt",
"blob_connection.txt",
"blob_importexport.txt",
"blob_transaction.txt",
setUp=setup, tearDown=zope.testing.setupstack.tearDown,
checker=zope.testing.renormalizing.RENormalizing([
......@@ -805,7 +806,9 @@ def test_suite():
suite.addTest(unittest.makeSuite(BlobCloneTests))
suite.addTest(unittest.makeSuite(BushyLayoutTests))
suite.addTest(doctest.DocFileSuite(
"blob_basic.txt", "blob_consume.txt", "blob_tempdir.txt",
"blob_basic.txt",
"blob_consume.txt",
"blob_tempdir.txt",
"blobstorage_packing.txt",
setUp=setUp,
tearDown=zope.testing.setupstack.tearDown,
......
......@@ -221,8 +221,9 @@ Note that we pass a file position, which gets saved with the index data.
If we save the data in the old format, we can still read it:
>>> from ZODB._compat import dump
>>> from ZODB._compat import _protocol
>>> with open('old', 'wb') as fp:
... dump(dict(pos=42, index=index), fp, 1)
... dump(dict(pos=42, index=index), fp, _protocol)
>>> info = fsIndex.load('old')
>>> info['pos']
42
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment