Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/bsddb/dbshelve.py

    r10 r391  
    2929
    3030#------------------------------------------------------------------------
    31 
    32 import cPickle
    33 import sys
    3431
    3532import sys
     
    4138    import db
    4239
    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)
     40if sys.version_info[0] >= 3 :
     41    import cPickle  # Will be converted to "pickle" by "2to3"
     42else :
     43    if sys.version_info < (2, 6) :
     44        import cPickle
    5245    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
     68HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL
     69def _dumps(object, protocol):
     70    return cPickle.dumps(object, protocol=protocol)
     71
     72if sys.version_info < (2, 6) :
     73    from UserDict import DictMixin as MutableMapping
     74else :
     75    import collections
     76    MutableMapping = collections.MutableMapping
    6777
    6878#------------------------------------------------------------------------
     
    107117
    108118
    109 class DBShelf(DictMixin):
     119class DBShelf(MutableMapping):
    110120    """A shelf to hold pickled objects, built upon a bsddb DB object.  It
    111121    automatically pickles/unpickles data objects going to/from the DB.
     
    153163
    154164    def keys(self, txn=None):
    155         if txn != None:
     165        if txn is not None:
    156166            return self.db.keys(txn)
    157167        else:
    158168            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__()
    159180
    160181
     
    177198
    178199    def items(self, txn=None):
    179         if txn != None:
     200        if txn is not None:
    180201            items = self.db.items(txn)
    181202        else:
     
    188209
    189210    def values(self, txn=None):
    190         if txn != None:
     211        if txn is not None:
    191212            values = self.db.values(txn)
    192213        else:
     
    226247        # an exception can be raised if set_get_returns_none is turned
    227248        # off.
    228         data = apply(self.db.get, args, kw)
     249        data = self.db.get(*args, **kw)
    229250        try:
    230251            return cPickle.loads(data)
     
    295316        count = len(args)  # a method overloading hack
    296317        method = getattr(self, 'get_%d' % count)
    297         apply(method, args)
     318        method(*args)
    298319
    299320    def get_1(self, flags):
Note: See TracChangeset for help on using the changeset viewer.