diff options
author | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:12:11 +0000 |
---|---|---|
committer | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:12:11 +0000 |
commit | 6ba3329c274e2c7876c61f2e98d4592310d26bae (patch) | |
tree | 6bb346e892269279fa2011c3e4bd4648b273a7ae /Lib/bsddb/dbobj.py | |
parent | 73c96dbf34c70bbf1ef807b98d51cf9c0e9dc042 (diff) | |
download | cpython-git-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.gz |
bsddb code updated to version 4.7.3pre2. This code is the same than
Python 2.6 one, since the intention is to keep an unified 2.x/3.x
codebase.
The Python code is automatically translated using "2to3". Please, do not
update this code in Python 3.0 by hand. Update the 2.6 one and then do
"2to3".
Diffstat (limited to 'Lib/bsddb/dbobj.py')
-rw-r--r-- | Lib/bsddb/dbobj.py | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/Lib/bsddb/dbobj.py b/Lib/bsddb/dbobj.py index 4c0f12582d..299e9dbf20 100644 --- a/Lib/bsddb/dbobj.py +++ b/Lib/bsddb/dbobj.py @@ -21,12 +21,24 @@ # added to _bsddb.c. # -from . import db +import sys +absolute_import = (sys.version_info[0] >= 3) +if absolute_import : + # Because this syntaxis is not valid before Python 2.5 + exec("from . import db") +else : + from . import db -try: - from collections import MutableMapping -except ImportError: - class MutableMapping: pass +if sys.version_info[0:2] <= (2, 5) : + try: + from UserDict import DictMixin + except ImportError: + # DictMixin is new in Python 2.3 + class DictMixin: pass + MutableMapping = DictMixin +else : + import collections + MutableMapping = collections.MutableMapping class DBEnv: def __init__(self, *args, **kwargs): @@ -95,9 +107,8 @@ class DBEnv: def set_get_returns_none(self, *args, **kwargs): return self._cobj.set_get_returns_none(*args, **kwargs) - if db.version() >= (4,0): - def log_stat(self, *args, **kwargs): - return self._cobj.log_stat(*args, **kwargs) + def log_stat(self, *args, **kwargs): + return self._cobj.log_stat(*args, **kwargs) if db.version() >= (4,1): def dbremove(self, *args, **kwargs): @@ -115,7 +126,7 @@ class DBEnv: class DB(MutableMapping): def __init__(self, dbenv, *args, **kwargs): # 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) # TODO are there other dict methods that need to be overridden? def __len__(self): @@ -126,8 +137,10 @@ class DB(MutableMapping): self._cobj[key] = value def __delitem__(self, arg): del self._cobj[arg] - def __iter__(self): - return iter(self.keys()) + + if sys.version_info[0:2] >= (2, 6) : + def __iter__(self) : + return self._cobj.__iter__() def append(self, *args, **kwargs): return self._cobj.append(*args, **kwargs) @@ -163,8 +176,6 @@ class DB(MutableMapping): return self._cobj.key_range(*args, **kwargs) def has_key(self, *args, **kwargs): return self._cobj.has_key(*args, **kwargs) - def __contains__(self, key): - return self._cobj.has_key(key) def items(self, *args, **kwargs): return self._cobj.items(*args, **kwargs) def keys(self, *args, **kwargs): |