~ubuntu-branches/ubuntu/oneiric/python2.6/oneiric

« back to all changes in this revision

Viewing changes to Lib/bsddb/dbtables.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-08-07 20:03:08 UTC
  • mfrom: (10.1.27 sid)
  • Revision ID: james.westby@ubuntu.com-20100807200308-bwsyymoc4donr9a9
Tags: 2.6.6~rc1-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# This provides a simple database table interface built on top of
16
16
# the Python Berkeley DB 3 interface.
17
17
#
18
 
_cvsid = '$Id: dbtables.py 66088 2008-08-31 14:00:51Z jesus.cea $'
 
18
_cvsid = '$Id: dbtables.py 83624 2010-08-03 03:19:00Z ezio.melotti $'
19
19
 
20
20
import re
21
21
import sys
179
179
 
180
180
                def set_range(self, search) :
181
181
                    v = self._dbcursor.set_range(bytes(search, "iso8859-1"))
182
 
                    if v != None :
 
182
                    if v is not None :
183
183
                        v = (v[0].decode("iso8859-1"),
184
184
                                v[1].decode("iso8859-1"))
185
185
                    return v
186
186
 
187
187
                def __next__(self) :
188
188
                    v = getattr(self._dbcursor, "next")()
189
 
                    if v != None :
 
189
                    if v is not None :
190
190
                        v = (v[0].decode("iso8859-1"),
191
191
                                v[1].decode("iso8859-1"))
192
192
                    return v
204
204
 
205
205
                def put(self, key, value, flags=0, txn=None) :
206
206
                    key = bytes(key, "iso8859-1")
207
 
                    if value != None :
 
207
                    if value is not None :
208
208
                        value = bytes(value, "iso8859-1")
209
209
                    return self._db.put(key, value, flags=flags, txn=txn)
210
210
 
215
215
                def get(self, key, txn=None, flags=0) :
216
216
                    key = bytes(key, "iso8859-1")
217
217
                    v = self._db.get(key, txn=txn, flags=flags)
218
 
                    if v != None :
 
218
                    if v is not None :
219
219
                        v = v.decode("iso8859-1")
220
220
                    return v
221
221
 
332
332
        except db.DBError, dberror:
333
333
            if txn:
334
334
                txn.abort()
335
 
            if sys.version_info[0] < 3 :
 
335
            if sys.version_info < (2, 6) :
336
336
                raise TableDBError, dberror[1]
337
337
            else :
338
338
                raise TableDBError, dberror.args[1]
398
398
                # column names
399
399
                newcolumnlist = copy.copy(oldcolumnlist)
400
400
                for c in columns:
401
 
                    if not oldcolumnhash.has_key(c):
 
401
                    if c not in oldcolumnhash:
402
402
                        newcolumnlist.append(c)
403
403
 
404
404
                # store the table's new extended column list
416
416
            except db.DBError, dberror:
417
417
                if txn:
418
418
                    txn.abort()
419
 
                if sys.version_info[0] < 3 :
 
419
                if sys.version_info < (2, 6) :
420
420
                    raise TableDBError, dberror[1]
421
421
                else :
422
422
                    raise TableDBError, dberror.args[1]
472
472
                raise TableDBError, "unknown table"
473
473
 
474
474
            # check the validity of each column name
475
 
            if not self.__tablecolumns.has_key(table):
 
475
            if not table in self.__tablecolumns:
476
476
                self.__load_column_info(table)
477
477
            for column in rowdict.keys() :
478
478
                if not self.__tablecolumns[table].count(column):
499
499
            if txn:
500
500
                txn.abort()
501
501
                self.db.delete(_rowid_key(table, rowid))
502
 
            if sys.version_info[0] < 3 :
 
502
            if sys.version_info < (2, 6) :
503
503
                raise TableDBError, dberror[1], info[2]
504
504
            else :
505
505
                raise TableDBError, dberror.args[1], info[2]
540
540
                             # error
541
541
                            dataitem = None
542
542
                        dataitem = mappings[column](dataitem)
543
 
                        if dataitem <> None:
 
543
                        if dataitem is not None:
544
544
                            self.db.put(
545
545
                                _data_key(table, column, rowid),
546
546
                                dataitem, txn=txn)
554
554
                    raise
555
555
 
556
556
        except db.DBError, dberror:
557
 
            if sys.version_info[0] < 3 :
 
557
            if sys.version_info < (2, 6) :
558
558
                raise TableDBError, dberror[1]
559
559
            else :
560
560
                raise TableDBError, dberror.args[1]
598
598
                        txn.abort()
599
599
                    raise
600
600
        except db.DBError, dberror:
601
 
            if sys.version_info[0] < 3 :
 
601
            if sys.version_info < (2, 6) :
602
602
                raise TableDBError, dberror[1]
603
603
            else :
604
604
                raise TableDBError, dberror.args[1]
615
615
          argument and returning a boolean.
616
616
        """
617
617
        try:
618
 
            if not self.__tablecolumns.has_key(table):
 
618
            if table not in self.__tablecolumns:
619
619
                self.__load_column_info(table)
620
620
            if columns is None:
621
621
                columns = self.__tablecolumns[table]
622
622
            matching_rowids = self.__Select(table, columns, conditions)
623
623
        except db.DBError, dberror:
624
 
            if sys.version_info[0] < 3 :
 
624
            if sys.version_info < (2, 6) :
625
625
                raise TableDBError, dberror[1]
626
626
            else :
627
627
                raise TableDBError, dberror.args[1]
639
639
        argument and returning a boolean.
640
640
        """
641
641
        # check the validity of each column name
642
 
        if not self.__tablecolumns.has_key(table):
 
642
        if not table in self.__tablecolumns:
643
643
            self.__load_column_info(table)
644
644
        if columns is None:
645
645
            columns = self.tablecolumns[table]
677
677
            # leave all unknown condition callables alone as equals
678
678
            return 0
679
679
 
680
 
        if sys.version_info[0] < 3 :
 
680
        if sys.version_info < (2, 6) :
681
681
            conditionlist = conditions.items()
682
682
            conditionlist.sort(cmp_conditions)
683
683
        else :  # Insertion Sort. Please, improve
709
709
                    # extract the rowid from the key
710
710
                    rowid = key[-_rowid_str_len:]
711
711
 
712
 
                    if not rejected_rowids.has_key(rowid):
 
712
                    if not rowid in rejected_rowids:
713
713
                        # if no condition was specified or the condition
714
714
                        # succeeds, add row to our match list.
715
715
                        if not condition or condition(data):
716
 
                            if not matching_rowids.has_key(rowid):
 
716
                            if not rowid in matching_rowids:
717
717
                                matching_rowids[rowid] = {}
718
718
                            if savethiscolumndata:
719
719
                                matching_rowids[rowid][column] = data
720
720
                        else:
721
 
                            if matching_rowids.has_key(rowid):
 
721
                            if rowid in matching_rowids:
722
722
                                del matching_rowids[rowid]
723
723
                            rejected_rowids[rowid] = rowid
724
724
 
725
725
                    key, data = cur.next()
726
726
 
727
727
            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
 
728
                if dberror.args[0] != db.DB_NOTFOUND:
 
729
                    raise
734
730
                continue
735
731
 
736
732
        cur.close()
743
739
        if len(columns) > 0:
744
740
            for rowid, rowdata in matching_rowids.items():
745
741
                for column in columns:
746
 
                    if rowdata.has_key(column):
 
742
                    if column in rowdata:
747
743
                        continue
748
744
                    try:
749
745
                        rowdata[column] = self.db.get(
750
746
                            _data_key(table, column, rowid))
751
747
                    except db.DBError, dberror:
752
 
                        if sys.version_info[0] < 3 :
 
748
                        if sys.version_info < (2, 6) :
753
749
                            if dberror[0] != db.DB_NOTFOUND:
754
750
                                raise
755
751
                        else :
815
811
            txn.commit()
816
812
            txn = None
817
813
 
818
 
            if self.__tablecolumns.has_key(table):
 
814
            if table in self.__tablecolumns:
819
815
                del self.__tablecolumns[table]
820
816
 
821
817
        except db.DBError, dberror:
822
818
            if txn:
823
819
                txn.abort()
824
 
            if sys.version_info[0] < 3 :
825
 
                raise TableDBError, dberror[1]
826
 
            else :
827
 
                raise TableDBError, dberror.args[1]
 
820
            raise TableDBError(dberror.args[1])