Changeset 391 for python/trunk/Lib/bsddb/dbtables.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/dbtables.py
r2 r391 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$' 19 19 20 20 import re … … 23 23 import random 24 24 import struct 25 import cPickle as pickle 25 26 27 if sys.version_info[0] >= 3 : 28 import pickle 29 else : 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 26 54 27 55 try: … … 31 59 # For Python 2.3 32 60 from bsddb import db 33 34 # XXX(nnorwitz): is this correct? DBIncompleteError is conditional in _bsddb.c35 if not hasattr(db,"DBIncompleteError") :36 class DBIncompleteError(Exception):37 pass38 db.DBIncompleteError = DBIncompleteError39 61 40 62 class TableDBError(StandardError): … … 180 202 def set_range(self, search) : 181 203 v = self._dbcursor.set_range(bytes(search, "iso8859-1")) 182 if v !=None :204 if v is not None : 183 205 v = (v[0].decode("iso8859-1"), 184 206 v[1].decode("iso8859-1")) … … 187 209 def __next__(self) : 188 210 v = getattr(self._dbcursor, "next")() 189 if v !=None :211 if v is not None : 190 212 v = (v[0].decode("iso8859-1"), 191 213 v[1].decode("iso8859-1")) … … 205 227 def put(self, key, value, flags=0, txn=None) : 206 228 key = bytes(key, "iso8859-1") 207 if value !=None :229 if value is not None : 208 230 value = bytes(value, "iso8859-1") 209 231 return self._db.put(key, value, flags=flags, txn=txn) … … 216 238 key = bytes(key, "iso8859-1") 217 239 v = self._db.get(key, txn=txn, flags=flags) 218 if v !=None :240 if v is not None : 219 241 v = v.decode("iso8859-1") 220 242 return v … … 262 284 263 285 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) 268 287 269 288 def sync(self): 270 try: 271 self.db.sync() 272 except db.DBIncompleteError: 273 pass 289 self.db.sync() 274 290 275 291 def _db_print(self) : … … 333 349 if txn: 334 350 txn.abort() 335 if sys.version_info [0] < 3:351 if sys.version_info < (2, 6) : 336 352 raise TableDBError, dberror[1] 337 353 else : … … 399 415 newcolumnlist = copy.copy(oldcolumnlist) 400 416 for c in columns: 401 if not oldcolumnhash.has_key(c):417 if not c in oldcolumnhash: 402 418 newcolumnlist.append(c) 403 419 … … 417 433 if txn: 418 434 txn.abort() 419 if sys.version_info [0] < 3:435 if sys.version_info < (2, 6) : 420 436 raise TableDBError, dberror[1] 421 437 else : … … 473 489 474 490 # check the validity of each column name 475 if not self.__tablecolumns.has_key(table):491 if not table in self.__tablecolumns: 476 492 self.__load_column_info(table) 477 493 for column in rowdict.keys() : … … 500 516 txn.abort() 501 517 self.db.delete(_rowid_key(table, rowid)) 502 if sys.version_info [0] < 3:518 if sys.version_info < (2, 6) : 503 519 raise TableDBError, dberror[1], info[2] 504 520 else : … … 541 557 dataitem = None 542 558 dataitem = mappings[column](dataitem) 543 if dataitem <>None:559 if dataitem is not None: 544 560 self.db.put( 545 561 _data_key(table, column, rowid), … … 555 571 556 572 except db.DBError, dberror: 557 if sys.version_info [0] < 3:573 if sys.version_info < (2, 6) : 558 574 raise TableDBError, dberror[1] 559 575 else : … … 599 615 raise 600 616 except db.DBError, dberror: 601 if sys.version_info [0] < 3:617 if sys.version_info < (2, 6) : 602 618 raise TableDBError, dberror[1] 603 619 else : … … 616 632 """ 617 633 try: 618 if not self.__tablecolumns.has_key(table):634 if not table in self.__tablecolumns: 619 635 self.__load_column_info(table) 620 636 if columns is None: … … 622 638 matching_rowids = self.__Select(table, columns, conditions) 623 639 except db.DBError, dberror: 624 if sys.version_info [0] < 3:640 if sys.version_info < (2, 6) : 625 641 raise TableDBError, dberror[1] 626 642 else : … … 640 656 """ 641 657 # check the validity of each column name 642 if not self.__tablecolumns.has_key(table):658 if not table in self.__tablecolumns: 643 659 self.__load_column_info(table) 644 660 if columns is None: … … 660 676 b = btuple[1] 661 677 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 662 685 if isinstance(a, PrefixCond) and isinstance(b, PrefixCond): 663 686 # longest prefix first … … 678 701 return 0 679 702 680 if sys.version_info [0] < 3:703 if sys.version_info < (2, 6) : 681 704 conditionlist = conditions.items() 682 705 conditionlist.sort(cmp_conditions) … … 710 733 rowid = key[-_rowid_str_len:] 711 734 712 if not r ejected_rowids.has_key(rowid):735 if not rowid in rejected_rowids: 713 736 # if no condition was specified or the condition 714 737 # succeeds, add row to our match list. 715 738 if not condition or condition(data): 716 if not matching_rowids.has_key(rowid):739 if not rowid in matching_rowids: 717 740 matching_rowids[rowid] = {} 718 741 if savethiscolumndata: 719 742 matching_rowids[rowid][column] = data 720 743 else: 721 if matching_rowids.has_key(rowid):744 if rowid in matching_rowids: 722 745 del matching_rowids[rowid] 723 746 rejected_rowids[rowid] = rowid … … 726 749 727 750 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 734 753 continue 735 754 … … 744 763 for rowid, rowdata in matching_rowids.items(): 745 764 for column in columns: 746 if rowdata.has_key(column):765 if column in rowdata: 747 766 continue 748 767 try: … … 750 769 _data_key(table, column, rowid)) 751 770 except db.DBError, dberror: 752 if sys.version_info [0] < 3:771 if sys.version_info < (2, 6) : 753 772 if dberror[0] != db.DB_NOTFOUND: 754 773 raise … … 816 835 txn = None 817 836 818 if self.__tablecolumns.has_key(table):837 if table in self.__tablecolumns: 819 838 del self.__tablecolumns[table] 820 839 … … 822 841 if txn: 823 842 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.