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/dbtables.py

    r2 r391  
    1616# the Python Berkeley DB 3 interface.
    1717#
    18 _cvsid = '$Id: dbtables.py 66088 2008-08-31 14:00:51Z jesus.cea $'
     18_cvsid = '$Id$'
    1919
    2020import re
     
    2323import random
    2424import struct
    25 import cPickle as pickle
     25
     26
     27if sys.version_info[0] >= 3 :
     28    import pickle
     29else :
     30    if sys.version_info < (2, 6) :
     31        import cPickle as pickle
     32    else :
     33        # When we drop support for python 2.4
     34        # we could use: (in 2.5 we need a __future__ statement)
     35        #
     36        #    with warnings.catch_warnings():
     37        #        warnings.filterwarnings(...)
     38        #        ...
     39        #
     40        # We can not use "with" as is, because it would be invalid syntax
     41        # in python 2.4 and (with no __future__) 2.5.
     42        # Here we simulate "with" following PEP 343 :
     43        import warnings
     44        w = warnings.catch_warnings()
     45        w.__enter__()
     46        try :
     47            warnings.filterwarnings('ignore',
     48                message='the cPickle module has been removed in Python 3.0',
     49                category=DeprecationWarning)
     50            import cPickle as pickle
     51        finally :
     52            w.__exit__()
     53        del w
    2654
    2755try:
     
    3159    # For Python 2.3
    3260    from bsddb import db
    33 
    34 # XXX(nnorwitz): is this correct? DBIncompleteError is conditional in _bsddb.c
    35 if not hasattr(db,"DBIncompleteError") :
    36     class DBIncompleteError(Exception):
    37         pass
    38     db.DBIncompleteError = DBIncompleteError
    3961
    4062class TableDBError(StandardError):
     
    180202                def set_range(self, search) :
    181203                    v = self._dbcursor.set_range(bytes(search, "iso8859-1"))
    182                     if v != None :
     204                    if v is not None :
    183205                        v = (v[0].decode("iso8859-1"),
    184206                                v[1].decode("iso8859-1"))
     
    187209                def __next__(self) :
    188210                    v = getattr(self._dbcursor, "next")()
    189                     if v != None :
     211                    if v is not None :
    190212                        v = (v[0].decode("iso8859-1"),
    191213                                v[1].decode("iso8859-1"))
     
    205227                def put(self, key, value, flags=0, txn=None) :
    206228                    key = bytes(key, "iso8859-1")
    207                     if value != None :
     229                    if value is not None :
    208230                        value = bytes(value, "iso8859-1")
    209231                    return self._db.put(key, value, flags=flags, txn=txn)
     
    216238                    key = bytes(key, "iso8859-1")
    217239                    v = self._db.get(key, txn=txn, flags=flags)
    218                     if v != None :
     240                    if v is not None :
    219241                        v = v.decode("iso8859-1")
    220242                    return v
     
    262284
    263285    def checkpoint(self, mins=0):
    264         try:
    265             self.env.txn_checkpoint(mins)
    266         except db.DBIncompleteError:
    267             pass
     286        self.env.txn_checkpoint(mins)
    268287
    269288    def sync(self):
    270         try:
    271             self.db.sync()
    272         except db.DBIncompleteError:
    273             pass
     289        self.db.sync()
    274290
    275291    def _db_print(self) :
     
    333349            if txn:
    334350                txn.abort()
    335             if sys.version_info[0] < 3 :
     351            if sys.version_info < (2, 6) :
    336352                raise TableDBError, dberror[1]
    337353            else :
     
    399415                newcolumnlist = copy.copy(oldcolumnlist)
    400416                for c in columns:
    401                     if not oldcolumnhash.has_key(c):
     417                    if not c in oldcolumnhash:
    402418                        newcolumnlist.append(c)
    403419
     
    417433                if txn:
    418434                    txn.abort()
    419                 if sys.version_info[0] < 3 :
     435                if sys.version_info < (2, 6) :
    420436                    raise TableDBError, dberror[1]
    421437                else :
     
    473489
    474490            # check the validity of each column name
    475             if not self.__tablecolumns.has_key(table):
     491            if not table in self.__tablecolumns:
    476492                self.__load_column_info(table)
    477493            for column in rowdict.keys() :
     
    500516                txn.abort()
    501517                self.db.delete(_rowid_key(table, rowid))
    502             if sys.version_info[0] < 3 :
     518            if sys.version_info < (2, 6) :
    503519                raise TableDBError, dberror[1], info[2]
    504520            else :
     
    541557                            dataitem = None
    542558                        dataitem = mappings[column](dataitem)
    543                         if dataitem <> None:
     559                        if dataitem is not None:
    544560                            self.db.put(
    545561                                _data_key(table, column, rowid),
     
    555571
    556572        except db.DBError, dberror:
    557             if sys.version_info[0] < 3 :
     573            if sys.version_info < (2, 6) :
    558574                raise TableDBError, dberror[1]
    559575            else :
     
    599615                    raise
    600616        except db.DBError, dberror:
    601             if sys.version_info[0] < 3 :
     617            if sys.version_info < (2, 6) :
    602618                raise TableDBError, dberror[1]
    603619            else :
     
    616632        """
    617633        try:
    618             if not self.__tablecolumns.has_key(table):
     634            if not table in self.__tablecolumns:
    619635                self.__load_column_info(table)
    620636            if columns is None:
     
    622638            matching_rowids = self.__Select(table, columns, conditions)
    623639        except db.DBError, dberror:
    624             if sys.version_info[0] < 3 :
     640            if sys.version_info < (2, 6) :
    625641                raise TableDBError, dberror[1]
    626642            else :
     
    640656        """
    641657        # check the validity of each column name
    642         if not self.__tablecolumns.has_key(table):
     658        if not table in self.__tablecolumns:
    643659            self.__load_column_info(table)
    644660        if columns is None:
     
    660676            b = btuple[1]
    661677            if type(a) is type(b):
     678
     679                # Needed for python 3. "cmp" vanished in 3.0.1
     680                def cmp(a, b) :
     681                    if a==b : return 0
     682                    if a<b : return -1
     683                    return 1
     684
    662685                if isinstance(a, PrefixCond) and isinstance(b, PrefixCond):
    663686                    # longest prefix first
     
    678701            return 0
    679702
    680         if sys.version_info[0] < 3 :
     703        if sys.version_info < (2, 6) :
    681704            conditionlist = conditions.items()
    682705            conditionlist.sort(cmp_conditions)
     
    710733                    rowid = key[-_rowid_str_len:]
    711734
    712                     if not rejected_rowids.has_key(rowid):
     735                    if not rowid in rejected_rowids:
    713736                        # if no condition was specified or the condition
    714737                        # succeeds, add row to our match list.
    715738                        if not condition or condition(data):
    716                             if not matching_rowids.has_key(rowid):
     739                            if not rowid in matching_rowids:
    717740                                matching_rowids[rowid] = {}
    718741                            if savethiscolumndata:
    719742                                matching_rowids[rowid][column] = data
    720743                        else:
    721                             if matching_rowids.has_key(rowid):
     744                            if rowid in matching_rowids:
    722745                                del matching_rowids[rowid]
    723746                            rejected_rowids[rowid] = rowid
     
    726749
    727750            except db.DBError, dberror:
    728                 if sys.version_info[0] < 3 :
    729                     if dberror[0] != db.DB_NOTFOUND:
    730                         raise
    731                 else :
    732                     if dberror.args[0] != db.DB_NOTFOUND:
    733                         raise
     751                if dberror.args[0] != db.DB_NOTFOUND:
     752                    raise
    734753                continue
    735754
     
    744763            for rowid, rowdata in matching_rowids.items():
    745764                for column in columns:
    746                     if rowdata.has_key(column):
     765                    if column in rowdata:
    747766                        continue
    748767                    try:
     
    750769                            _data_key(table, column, rowid))
    751770                    except db.DBError, dberror:
    752                         if sys.version_info[0] < 3 :
     771                        if sys.version_info < (2, 6) :
    753772                            if dberror[0] != db.DB_NOTFOUND:
    754773                                raise
     
    816835            txn = None
    817836
    818             if self.__tablecolumns.has_key(table):
     837            if table in self.__tablecolumns:
    819838                del self.__tablecolumns[table]
    820839
     
    822841            if txn:
    823842                txn.abort()
    824             if sys.version_info[0] < 3 :
    825                 raise TableDBError, dberror[1]
    826             else :
    827                 raise TableDBError, dberror.args[1]
     843            raise TableDBError(dberror.args[1])
Note: See TracChangeset for help on using the changeset viewer.