Kaydet (Commit) d190f9c4 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

In bsddb, replace UserDict.DictMixin with collections.MutableMapping.

I can't test this directly on my build, so letting the buildbots do it for me.
If it fails, expect a reversion.
üst 3be449ae
...@@ -64,10 +64,10 @@ error = db.DBError # So bsddb.error will mean something... ...@@ -64,10 +64,10 @@ error = db.DBError # So bsddb.error will mean something...
#---------------------------------------------------------------------- #----------------------------------------------------------------------
import sys, os, UserDict import sys, os, collections
from weakref import ref from weakref import ref
class _iter_mixin(UserDict.DictMixin): class _iter_mixin(collections.MutableMapping):
def _make_iter_cursor(self): def _make_iter_cursor(self):
cur = _DeadlockWrap(self.db.cursor) cur = _DeadlockWrap(self.db.cursor)
key = id(cur) key = id(cur)
...@@ -289,7 +289,7 @@ class _ExposedProperties: ...@@ -289,7 +289,7 @@ class _ExposedProperties:
def _cursor_refs(self): def _cursor_refs(self):
return self.db._cursor_refs return self.db._cursor_refs
class StringKeys(UserDict.DictMixin, _ExposedProperties): class StringKeys(collections.MutableMapping, _ExposedProperties):
"""Wrapper around DB object that automatically encodes """Wrapper around DB object that automatically encodes
all keys as UTF-8; the keys must be strings.""" all keys as UTF-8; the keys must be strings."""
...@@ -357,7 +357,7 @@ class StringKeys(UserDict.DictMixin, _ExposedProperties): ...@@ -357,7 +357,7 @@ class StringKeys(UserDict.DictMixin, _ExposedProperties):
def sync(self): def sync(self):
return self.db.sync() return self.db.sync()
class StringValues(UserDict.DictMixin, _ExposedProperties): class StringValues(collections.MutableMapping, _ExposedProperties):
"""Wrapper around DB object that automatically encodes """Wrapper around DB object that automatically encodes
and decodes all values as UTF-8; input values must be strings.""" and decodes all values as UTF-8; input values must be strings."""
......
...@@ -24,10 +24,9 @@ ...@@ -24,10 +24,9 @@
from . import db from . import db
try: try:
from UserDict import DictMixin from collections import MutableMapping
except ImportError: except ImportError:
# DictMixin is new in Python 2.3 class MutableMapping: pass
class DictMixin: pass
class DBEnv: class DBEnv:
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -113,7 +112,7 @@ class DBEnv: ...@@ -113,7 +112,7 @@ class DBEnv:
return self._cobj.lsn_reset(*args, **kwargs) return self._cobj.lsn_reset(*args, **kwargs)
class DB(DictMixin): class DB(MutableMapping):
def __init__(self, dbenv, *args, **kwargs): def __init__(self, dbenv, *args, **kwargs):
# give it the proper DBEnv C object that its expecting # give it the proper DBEnv C object that its expecting
self._cobj = db.DB(dbenv._cobj, *args, **kwargs) self._cobj = db.DB(dbenv._cobj, *args, **kwargs)
...@@ -127,6 +126,8 @@ class DB(DictMixin): ...@@ -127,6 +126,8 @@ class DB(DictMixin):
self._cobj[key] = value self._cobj[key] = value
def __delitem__(self, arg): def __delitem__(self, arg):
del self._cobj[arg] del self._cobj[arg]
def __iter__(self):
return iter(self.keys())
def append(self, *args, **kwargs): def append(self, *args, **kwargs):
return self._cobj.append(*args, **kwargs) return self._cobj.append(*args, **kwargs)
......
...@@ -38,12 +38,12 @@ if sys.version_info[:3] >= (2, 3, 0): ...@@ -38,12 +38,12 @@ if sys.version_info[:3] >= (2, 3, 0):
HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
def _dumps(object, protocol): def _dumps(object, protocol):
return pickle.dumps(object, protocol=protocol) return pickle.dumps(object, protocol=protocol)
from UserDict import DictMixin from collections import MutableMapping
else: else:
HIGHEST_PROTOCOL = None HIGHEST_PROTOCOL = None
def _dumps(object, protocol): def _dumps(object, protocol):
return pickle.dumps(object, bin=protocol) return pickle.dumps(object, bin=protocol)
class DictMixin: pass class MutableMapping: pass
from . import db from . import db
...@@ -90,7 +90,7 @@ def open(filename, flags=db.DB_CREATE, mode=0o660, filetype=db.DB_HASH, ...@@ -90,7 +90,7 @@ def open(filename, flags=db.DB_CREATE, mode=0o660, filetype=db.DB_HASH,
class DBShelveError(db.DBError): pass class DBShelveError(db.DBError): pass
class DBShelf(DictMixin): class DBShelf(MutableMapping):
"""A shelf to hold pickled objects, built upon a bsddb DB object. It """A shelf to hold pickled objects, built upon a bsddb DB object. It
automatically pickles/unpickles data objects going to/from the DB. automatically pickles/unpickles data objects going to/from the DB.
""" """
...@@ -141,6 +141,8 @@ class DBShelf(DictMixin): ...@@ -141,6 +141,8 @@ class DBShelf(DictMixin):
else: else:
return self.db.keys() return self.db.keys()
def __iter__(self):
return iter(self.keys())
def open(self, *args, **kwargs): def open(self, *args, **kwargs):
self.db.open(*args, **kwargs) self.db.open(*args, **kwargs)
......
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