database file is opened for reading and writing. The optional *flag* parameter
has the same interpretation as the *flag* parameter of :func:`dbm.open`.
- By default, version 3 pickles are used to serialize values. The version of the
- pickle protocol can be specified with the *protocol* parameter.
+ By default, pickles created with :data:`pickle.DEFAULT_PROTOCOL` are used
+ to serialize values. The version of the pickle protocol can be specified
+ with the *protocol* parameter.
Because of Python semantics, a shelf cannot know when a mutable
persistent-dictionary entry is modified. By default modified objects are
determine which accessed entries are mutable, nor which ones were actually
mutated).
+ .. versionchanged:: 3.10
+ :data:`pickle.DEFAULT_PROTOCOL` is now used as the default pickle
+ protocol.
+
.. note::
Do not rely on the shelf being closed automatically; always call
A subclass of :class:`collections.abc.MutableMapping` which stores pickled
values in the *dict* object.
- By default, version 3 pickles are used to serialize values. The version of the
- pickle protocol can be specified with the *protocol* parameter. See the
- :mod:`pickle` documentation for a discussion of the pickle protocols.
+ By default, pickles created with :data:`pickle.DEFAULT_PROTOCOL` are used
+ to serialize values. The version of the pickle protocol can be specified
+ with the *protocol* parameter. See the :mod:`pickle` documentation for a
+ discussion of the pickle protocols.
If the *writeback* parameter is ``True``, the object will hold a cache of all
entries accessed and write them back to the *dict* at sync and close times.
.. versionchanged:: 3.4
Added context manager support.
+ .. versionchanged:: 3.10
+ :data:`pickle.DEFAULT_PROTOCOL` is now used as the default pickle
+ protocol.
+
.. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8')
the persistent dictionary on disk, if feasible).
"""
-from pickle import Pickler, Unpickler
+from pickle import DEFAULT_PROTOCOL, Pickler, Unpickler
from io import BytesIO
import collections.abc
keyencoding="utf-8"):
self.dict = dict
if protocol is None:
- protocol = 3
+ protocol = DEFAULT_PROTOCOL
self._protocol = protocol
self.writeback = writeback
self.cache = {}
import unittest
import shelve
import glob
+import pickle
+
from test import support
from test.support import os_helper
from collections.abc import MutableMapping
def test_default_protocol(self):
with shelve.Shelf({}) as s:
- self.assertEqual(s._protocol, 3)
+ self.assertEqual(s._protocol, pickle.DEFAULT_PROTOCOL)
from test import mapping_tests