Changeset 391 for python/trunk/Lib/bsddb/dbshelve.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/bsddb/dbshelve.py
r10 r391 29 29 30 30 #------------------------------------------------------------------------ 31 32 import cPickle33 import sys34 31 35 32 import sys … … 41 38 import db 42 39 43 #At version 2.3 cPickle switched to using protocol instead of bin 44 if sys.version_info[:3] >= (2, 3, 0): 45 HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL 46 # In python 2.3.*, "cPickle.dumps" accepts no 47 # named parameters. "pickle.dumps" accepts them, 48 # so this seems a bug. 49 if sys.version_info[:3] < (2, 4, 0): 50 def _dumps(object, protocol): 51 return cPickle.dumps(object, protocol) 40 if sys.version_info[0] >= 3 : 41 import cPickle # Will be converted to "pickle" by "2to3" 42 else : 43 if sys.version_info < (2, 6) : 44 import cPickle 52 45 else : 53 def _dumps(object, protocol): 54 return cPickle.dumps(object, protocol=protocol) 55 56 else: 57 HIGHEST_PROTOCOL = None 58 def _dumps(object, protocol): 59 return cPickle.dumps(object, bin=protocol) 60 61 62 try: 63 from UserDict import DictMixin 64 except ImportError: 65 # DictMixin is new in Python 2.3 66 class DictMixin: pass 46 # When we drop support for python 2.4 47 # we could use: (in 2.5 we need a __future__ statement) 48 # 49 # with warnings.catch_warnings(): 50 # warnings.filterwarnings(...) 51 # ... 52 # 53 # We can not use "with" as is, because it would be invalid syntax 54 # in python 2.4 and (with no __future__) 2.5. 55 # Here we simulate "with" following PEP 343 : 56 import warnings 57 w = warnings.catch_warnings() 58 w.__enter__() 59 try : 60 warnings.filterwarnings('ignore', 61 message='the cPickle module has been removed in Python 3.0', 62 category=DeprecationWarning) 63 import cPickle 64 finally : 65 w.__exit__() 66 del w 67 68 HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL 69 def _dumps(object, protocol): 70 return cPickle.dumps(object, protocol=protocol) 71 72 if sys.version_info < (2, 6) : 73 from UserDict import DictMixin as MutableMapping 74 else : 75 import collections 76 MutableMapping = collections.MutableMapping 67 77 68 78 #------------------------------------------------------------------------ … … 107 117 108 118 109 class DBShelf( DictMixin):119 class DBShelf(MutableMapping): 110 120 """A shelf to hold pickled objects, built upon a bsddb DB object. It 111 121 automatically pickles/unpickles data objects going to/from the DB. … … 153 163 154 164 def keys(self, txn=None): 155 if txn !=None:165 if txn is not None: 156 166 return self.db.keys(txn) 157 167 else: 158 168 return self.db.keys() 169 170 if sys.version_info >= (2, 6) : 171 def __iter__(self) : # XXX: Load all keys in memory :-( 172 for k in self.db.keys() : 173 yield k 174 175 # Do this when "DB" support iteration 176 # Or is it enough to pass thru "getattr"? 177 # 178 # def __iter__(self) : 179 # return self.db.__iter__() 159 180 160 181 … … 177 198 178 199 def items(self, txn=None): 179 if txn !=None:200 if txn is not None: 180 201 items = self.db.items(txn) 181 202 else: … … 188 209 189 210 def values(self, txn=None): 190 if txn !=None:211 if txn is not None: 191 212 values = self.db.values(txn) 192 213 else: … … 226 247 # an exception can be raised if set_get_returns_none is turned 227 248 # off. 228 data = apply(self.db.get, args,kw)249 data = self.db.get(*args, **kw) 229 250 try: 230 251 return cPickle.loads(data) … … 295 316 count = len(args) # a method overloading hack 296 317 method = getattr(self, 'get_%d' % count) 297 apply(method,args)318 method(*args) 298 319 299 320 def get_1(self, flags):
Note:
See TracChangeset
for help on using the changeset viewer.