Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python2..../bsddb
File: __init__.py
#----------------------------------------------------------------------
[0] Fix | Delete
# Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA
[1] Fix | Delete
# and Andrew Kuchling. All rights reserved.
[2] Fix | Delete
#
[3] Fix | Delete
# Redistribution and use in source and binary forms, with or without
[4] Fix | Delete
# modification, are permitted provided that the following conditions are
[5] Fix | Delete
# met:
[6] Fix | Delete
#
[7] Fix | Delete
# o Redistributions of source code must retain the above copyright
[8] Fix | Delete
# notice, this list of conditions, and the disclaimer that follows.
[9] Fix | Delete
#
[10] Fix | Delete
# o Redistributions in binary form must reproduce the above copyright
[11] Fix | Delete
# notice, this list of conditions, and the following disclaimer in
[12] Fix | Delete
# the documentation and/or other materials provided with the
[13] Fix | Delete
# distribution.
[14] Fix | Delete
#
[15] Fix | Delete
# o Neither the name of Digital Creations nor the names of its
[16] Fix | Delete
# contributors may be used to endorse or promote products derived
[17] Fix | Delete
# from this software without specific prior written permission.
[18] Fix | Delete
#
[19] Fix | Delete
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
[20] Fix | Delete
# IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
[21] Fix | Delete
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
[22] Fix | Delete
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
[23] Fix | Delete
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
[24] Fix | Delete
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
[25] Fix | Delete
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
[26] Fix | Delete
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
[27] Fix | Delete
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
[28] Fix | Delete
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
[29] Fix | Delete
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
[30] Fix | Delete
# DAMAGE.
[31] Fix | Delete
#----------------------------------------------------------------------
[32] Fix | Delete
[33] Fix | Delete
[34] Fix | Delete
"""Support for Berkeley DB 4.3 through 5.3 with a simple interface.
[35] Fix | Delete
[36] Fix | Delete
For the full featured object oriented interface use the bsddb.db module
[37] Fix | Delete
instead. It mirrors the Oracle Berkeley DB C API.
[38] Fix | Delete
"""
[39] Fix | Delete
[40] Fix | Delete
import sys
[41] Fix | Delete
absolute_import = (sys.version_info[0] >= 3)
[42] Fix | Delete
[43] Fix | Delete
if (sys.version_info >= (2, 6)) and (sys.version_info < (3, 0)) :
[44] Fix | Delete
import warnings
[45] Fix | Delete
if sys.py3kwarning and (__name__ != 'bsddb3') :
[46] Fix | Delete
warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
[47] Fix | Delete
"please use the pybsddb project instead",
[48] Fix | Delete
DeprecationWarning, 2)
[49] Fix | Delete
warnings.filterwarnings("ignore", ".*CObject.*", DeprecationWarning,
[50] Fix | Delete
"bsddb.__init__")
[51] Fix | Delete
[52] Fix | Delete
try:
[53] Fix | Delete
if __name__ == 'bsddb3':
[54] Fix | Delete
# import _pybsddb binary as it should be the more recent version from
[55] Fix | Delete
# a standalone pybsddb addon package than the version included with
[56] Fix | Delete
# python as bsddb._bsddb.
[57] Fix | Delete
if absolute_import :
[58] Fix | Delete
# Because this syntaxis is not valid before Python 2.5
[59] Fix | Delete
exec("from . import _pybsddb")
[60] Fix | Delete
else :
[61] Fix | Delete
import _pybsddb
[62] Fix | Delete
_bsddb = _pybsddb
[63] Fix | Delete
from bsddb3.dbutils import DeadlockWrap as _DeadlockWrap
[64] Fix | Delete
else:
[65] Fix | Delete
import _bsddb
[66] Fix | Delete
from bsddb.dbutils import DeadlockWrap as _DeadlockWrap
[67] Fix | Delete
except ImportError:
[68] Fix | Delete
# Remove ourselves from sys.modules
[69] Fix | Delete
import sys
[70] Fix | Delete
del sys.modules[__name__]
[71] Fix | Delete
raise
[72] Fix | Delete
[73] Fix | Delete
# bsddb3 calls it db, but provide _db for backwards compatibility
[74] Fix | Delete
db = _db = _bsddb
[75] Fix | Delete
__version__ = db.__version__
[76] Fix | Delete
[77] Fix | Delete
error = db.DBError # So bsddb.error will mean something...
[78] Fix | Delete
[79] Fix | Delete
#----------------------------------------------------------------------
[80] Fix | Delete
[81] Fix | Delete
import sys, os
[82] Fix | Delete
[83] Fix | Delete
from weakref import ref
[84] Fix | Delete
[85] Fix | Delete
if sys.version_info < (2, 6) :
[86] Fix | Delete
import UserDict
[87] Fix | Delete
MutableMapping = UserDict.DictMixin
[88] Fix | Delete
else :
[89] Fix | Delete
import collections
[90] Fix | Delete
MutableMapping = collections.MutableMapping
[91] Fix | Delete
[92] Fix | Delete
class _iter_mixin(MutableMapping):
[93] Fix | Delete
def _make_iter_cursor(self):
[94] Fix | Delete
cur = _DeadlockWrap(self.db.cursor)
[95] Fix | Delete
key = id(cur)
[96] Fix | Delete
self._cursor_refs[key] = ref(cur, self._gen_cref_cleaner(key))
[97] Fix | Delete
return cur
[98] Fix | Delete
[99] Fix | Delete
def _gen_cref_cleaner(self, key):
[100] Fix | Delete
# use generate the function for the weakref callback here
[101] Fix | Delete
# to ensure that we do not hold a strict reference to cur
[102] Fix | Delete
# in the callback.
[103] Fix | Delete
return lambda ref: self._cursor_refs.pop(key, None)
[104] Fix | Delete
[105] Fix | Delete
def __iter__(self):
[106] Fix | Delete
self._kill_iteration = False
[107] Fix | Delete
self._in_iter += 1
[108] Fix | Delete
try:
[109] Fix | Delete
try:
[110] Fix | Delete
cur = self._make_iter_cursor()
[111] Fix | Delete
[112] Fix | Delete
# FIXME-20031102-greg: race condition. cursor could
[113] Fix | Delete
# be closed by another thread before this call.
[114] Fix | Delete
[115] Fix | Delete
# since we're only returning keys, we call the cursor
[116] Fix | Delete
# methods with flags=0, dlen=0, dofs=0
[117] Fix | Delete
key = _DeadlockWrap(cur.first, 0,0,0)[0]
[118] Fix | Delete
yield key
[119] Fix | Delete
[120] Fix | Delete
next = getattr(cur, "next")
[121] Fix | Delete
while 1:
[122] Fix | Delete
try:
[123] Fix | Delete
key = _DeadlockWrap(next, 0,0,0)[0]
[124] Fix | Delete
yield key
[125] Fix | Delete
except _bsddb.DBCursorClosedError:
[126] Fix | Delete
if self._kill_iteration:
[127] Fix | Delete
raise RuntimeError('Database changed size '
[128] Fix | Delete
'during iteration.')
[129] Fix | Delete
cur = self._make_iter_cursor()
[130] Fix | Delete
# FIXME-20031101-greg: race condition. cursor could
[131] Fix | Delete
# be closed by another thread before this call.
[132] Fix | Delete
_DeadlockWrap(cur.set, key,0,0,0)
[133] Fix | Delete
next = getattr(cur, "next")
[134] Fix | Delete
except _bsddb.DBNotFoundError:
[135] Fix | Delete
pass
[136] Fix | Delete
except _bsddb.DBCursorClosedError:
[137] Fix | Delete
# the database was modified during iteration. abort.
[138] Fix | Delete
pass
[139] Fix | Delete
# When Python 2.4 not supported in bsddb3, we can change this to "finally"
[140] Fix | Delete
except :
[141] Fix | Delete
self._in_iter -= 1
[142] Fix | Delete
raise
[143] Fix | Delete
[144] Fix | Delete
self._in_iter -= 1
[145] Fix | Delete
[146] Fix | Delete
def iteritems(self):
[147] Fix | Delete
if not self.db:
[148] Fix | Delete
return
[149] Fix | Delete
self._kill_iteration = False
[150] Fix | Delete
self._in_iter += 1
[151] Fix | Delete
try:
[152] Fix | Delete
try:
[153] Fix | Delete
cur = self._make_iter_cursor()
[154] Fix | Delete
[155] Fix | Delete
# FIXME-20031102-greg: race condition. cursor could
[156] Fix | Delete
# be closed by another thread before this call.
[157] Fix | Delete
[158] Fix | Delete
kv = _DeadlockWrap(cur.first)
[159] Fix | Delete
key = kv[0]
[160] Fix | Delete
yield kv
[161] Fix | Delete
[162] Fix | Delete
next = getattr(cur, "next")
[163] Fix | Delete
while 1:
[164] Fix | Delete
try:
[165] Fix | Delete
kv = _DeadlockWrap(next)
[166] Fix | Delete
key = kv[0]
[167] Fix | Delete
yield kv
[168] Fix | Delete
except _bsddb.DBCursorClosedError:
[169] Fix | Delete
if self._kill_iteration:
[170] Fix | Delete
raise RuntimeError('Database changed size '
[171] Fix | Delete
'during iteration.')
[172] Fix | Delete
cur = self._make_iter_cursor()
[173] Fix | Delete
# FIXME-20031101-greg: race condition. cursor could
[174] Fix | Delete
# be closed by another thread before this call.
[175] Fix | Delete
_DeadlockWrap(cur.set, key,0,0,0)
[176] Fix | Delete
next = getattr(cur, "next")
[177] Fix | Delete
except _bsddb.DBNotFoundError:
[178] Fix | Delete
pass
[179] Fix | Delete
except _bsddb.DBCursorClosedError:
[180] Fix | Delete
# the database was modified during iteration. abort.
[181] Fix | Delete
pass
[182] Fix | Delete
# When Python 2.4 not supported in bsddb3, we can change this to "finally"
[183] Fix | Delete
except :
[184] Fix | Delete
self._in_iter -= 1
[185] Fix | Delete
raise
[186] Fix | Delete
[187] Fix | Delete
self._in_iter -= 1
[188] Fix | Delete
[189] Fix | Delete
[190] Fix | Delete
class _DBWithCursor(_iter_mixin):
[191] Fix | Delete
"""
[192] Fix | Delete
A simple wrapper around DB that makes it look like the bsddbobject in
[193] Fix | Delete
the old module. It uses a cursor as needed to provide DB traversal.
[194] Fix | Delete
"""
[195] Fix | Delete
def __init__(self, db):
[196] Fix | Delete
self.db = db
[197] Fix | Delete
self.db.set_get_returns_none(0)
[198] Fix | Delete
[199] Fix | Delete
# FIXME-20031101-greg: I believe there is still the potential
[200] Fix | Delete
# for deadlocks in a multithreaded environment if someone
[201] Fix | Delete
# attempts to use the any of the cursor interfaces in one
[202] Fix | Delete
# thread while doing a put or delete in another thread. The
[203] Fix | Delete
# reason is that _checkCursor and _closeCursors are not atomic
[204] Fix | Delete
# operations. Doing our own locking around self.dbc,
[205] Fix | Delete
# self.saved_dbc_key and self._cursor_refs could prevent this.
[206] Fix | Delete
# TODO: A test case demonstrating the problem needs to be written.
[207] Fix | Delete
[208] Fix | Delete
# self.dbc is a DBCursor object used to implement the
[209] Fix | Delete
# first/next/previous/last/set_location methods.
[210] Fix | Delete
self.dbc = None
[211] Fix | Delete
self.saved_dbc_key = None
[212] Fix | Delete
[213] Fix | Delete
# a collection of all DBCursor objects currently allocated
[214] Fix | Delete
# by the _iter_mixin interface.
[215] Fix | Delete
self._cursor_refs = {}
[216] Fix | Delete
self._in_iter = 0
[217] Fix | Delete
self._kill_iteration = False
[218] Fix | Delete
[219] Fix | Delete
def __del__(self):
[220] Fix | Delete
self.close()
[221] Fix | Delete
[222] Fix | Delete
def _checkCursor(self):
[223] Fix | Delete
if self.dbc is None:
[224] Fix | Delete
self.dbc = _DeadlockWrap(self.db.cursor)
[225] Fix | Delete
if self.saved_dbc_key is not None:
[226] Fix | Delete
_DeadlockWrap(self.dbc.set, self.saved_dbc_key)
[227] Fix | Delete
self.saved_dbc_key = None
[228] Fix | Delete
[229] Fix | Delete
# This method is needed for all non-cursor DB calls to avoid
[230] Fix | Delete
# Berkeley DB deadlocks (due to being opened with DB_INIT_LOCK
[231] Fix | Delete
# and DB_THREAD to be thread safe) when intermixing database
[232] Fix | Delete
# operations that use the cursor internally with those that don't.
[233] Fix | Delete
def _closeCursors(self, save=1):
[234] Fix | Delete
if self.dbc:
[235] Fix | Delete
c = self.dbc
[236] Fix | Delete
self.dbc = None
[237] Fix | Delete
if save:
[238] Fix | Delete
try:
[239] Fix | Delete
self.saved_dbc_key = _DeadlockWrap(c.current, 0,0,0)[0]
[240] Fix | Delete
except db.DBError:
[241] Fix | Delete
pass
[242] Fix | Delete
_DeadlockWrap(c.close)
[243] Fix | Delete
del c
[244] Fix | Delete
for cref in self._cursor_refs.values():
[245] Fix | Delete
c = cref()
[246] Fix | Delete
if c is not None:
[247] Fix | Delete
_DeadlockWrap(c.close)
[248] Fix | Delete
[249] Fix | Delete
def _checkOpen(self):
[250] Fix | Delete
if self.db is None:
[251] Fix | Delete
raise error, "BSDDB object has already been closed"
[252] Fix | Delete
[253] Fix | Delete
def isOpen(self):
[254] Fix | Delete
return self.db is not None
[255] Fix | Delete
[256] Fix | Delete
def __len__(self):
[257] Fix | Delete
self._checkOpen()
[258] Fix | Delete
return _DeadlockWrap(lambda: len(self.db)) # len(self.db)
[259] Fix | Delete
[260] Fix | Delete
if sys.version_info >= (2, 6) :
[261] Fix | Delete
def __repr__(self) :
[262] Fix | Delete
if self.isOpen() :
[263] Fix | Delete
return repr(dict(_DeadlockWrap(self.db.items)))
[264] Fix | Delete
return repr(dict())
[265] Fix | Delete
[266] Fix | Delete
def __getitem__(self, key):
[267] Fix | Delete
self._checkOpen()
[268] Fix | Delete
return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
[269] Fix | Delete
[270] Fix | Delete
def __setitem__(self, key, value):
[271] Fix | Delete
self._checkOpen()
[272] Fix | Delete
self._closeCursors()
[273] Fix | Delete
if self._in_iter and key not in self:
[274] Fix | Delete
self._kill_iteration = True
[275] Fix | Delete
def wrapF():
[276] Fix | Delete
self.db[key] = value
[277] Fix | Delete
_DeadlockWrap(wrapF) # self.db[key] = value
[278] Fix | Delete
[279] Fix | Delete
def __delitem__(self, key):
[280] Fix | Delete
self._checkOpen()
[281] Fix | Delete
self._closeCursors()
[282] Fix | Delete
if self._in_iter and key in self:
[283] Fix | Delete
self._kill_iteration = True
[284] Fix | Delete
def wrapF():
[285] Fix | Delete
del self.db[key]
[286] Fix | Delete
_DeadlockWrap(wrapF) # del self.db[key]
[287] Fix | Delete
[288] Fix | Delete
def close(self):
[289] Fix | Delete
self._closeCursors(save=0)
[290] Fix | Delete
if self.dbc is not None:
[291] Fix | Delete
_DeadlockWrap(self.dbc.close)
[292] Fix | Delete
v = 0
[293] Fix | Delete
if self.db is not None:
[294] Fix | Delete
v = _DeadlockWrap(self.db.close)
[295] Fix | Delete
self.dbc = None
[296] Fix | Delete
self.db = None
[297] Fix | Delete
return v
[298] Fix | Delete
[299] Fix | Delete
def keys(self):
[300] Fix | Delete
self._checkOpen()
[301] Fix | Delete
return _DeadlockWrap(self.db.keys)
[302] Fix | Delete
[303] Fix | Delete
def has_key(self, key):
[304] Fix | Delete
self._checkOpen()
[305] Fix | Delete
return _DeadlockWrap(self.db.has_key, key)
[306] Fix | Delete
[307] Fix | Delete
def set_location(self, key):
[308] Fix | Delete
self._checkOpen()
[309] Fix | Delete
self._checkCursor()
[310] Fix | Delete
return _DeadlockWrap(self.dbc.set_range, key)
[311] Fix | Delete
[312] Fix | Delete
def next(self): # Renamed by "2to3"
[313] Fix | Delete
self._checkOpen()
[314] Fix | Delete
self._checkCursor()
[315] Fix | Delete
rv = _DeadlockWrap(getattr(self.dbc, "next"))
[316] Fix | Delete
return rv
[317] Fix | Delete
[318] Fix | Delete
if sys.version_info[0] >= 3 : # For "2to3" conversion
[319] Fix | Delete
next = __next__
[320] Fix | Delete
[321] Fix | Delete
def previous(self):
[322] Fix | Delete
self._checkOpen()
[323] Fix | Delete
self._checkCursor()
[324] Fix | Delete
rv = _DeadlockWrap(self.dbc.prev)
[325] Fix | Delete
return rv
[326] Fix | Delete
[327] Fix | Delete
def first(self):
[328] Fix | Delete
self._checkOpen()
[329] Fix | Delete
# fix 1725856: don't needlessly try to restore our cursor position
[330] Fix | Delete
self.saved_dbc_key = None
[331] Fix | Delete
self._checkCursor()
[332] Fix | Delete
rv = _DeadlockWrap(self.dbc.first)
[333] Fix | Delete
return rv
[334] Fix | Delete
[335] Fix | Delete
def last(self):
[336] Fix | Delete
self._checkOpen()
[337] Fix | Delete
# fix 1725856: don't needlessly try to restore our cursor position
[338] Fix | Delete
self.saved_dbc_key = None
[339] Fix | Delete
self._checkCursor()
[340] Fix | Delete
rv = _DeadlockWrap(self.dbc.last)
[341] Fix | Delete
return rv
[342] Fix | Delete
[343] Fix | Delete
def sync(self):
[344] Fix | Delete
self._checkOpen()
[345] Fix | Delete
return _DeadlockWrap(self.db.sync)
[346] Fix | Delete
[347] Fix | Delete
[348] Fix | Delete
#----------------------------------------------------------------------
[349] Fix | Delete
# Compatibility object factory functions
[350] Fix | Delete
[351] Fix | Delete
def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
[352] Fix | Delete
cachesize=None, lorder=None, hflags=0):
[353] Fix | Delete
[354] Fix | Delete
flags = _checkflag(flag, file)
[355] Fix | Delete
e = _openDBEnv(cachesize)
[356] Fix | Delete
d = db.DB(e)
[357] Fix | Delete
d.set_flags(hflags)
[358] Fix | Delete
if pgsize is not None: d.set_pagesize(pgsize)
[359] Fix | Delete
if lorder is not None: d.set_lorder(lorder)
[360] Fix | Delete
if ffactor is not None: d.set_h_ffactor(ffactor)
[361] Fix | Delete
if nelem is not None: d.set_h_nelem(nelem)
[362] Fix | Delete
d.open(file, db.DB_HASH, flags, mode)
[363] Fix | Delete
return _DBWithCursor(d)
[364] Fix | Delete
[365] Fix | Delete
#----------------------------------------------------------------------
[366] Fix | Delete
[367] Fix | Delete
def btopen(file, flag='c', mode=0666,
[368] Fix | Delete
btflags=0, cachesize=None, maxkeypage=None, minkeypage=None,
[369] Fix | Delete
pgsize=None, lorder=None):
[370] Fix | Delete
[371] Fix | Delete
flags = _checkflag(flag, file)
[372] Fix | Delete
e = _openDBEnv(cachesize)
[373] Fix | Delete
d = db.DB(e)
[374] Fix | Delete
if pgsize is not None: d.set_pagesize(pgsize)
[375] Fix | Delete
if lorder is not None: d.set_lorder(lorder)
[376] Fix | Delete
d.set_flags(btflags)
[377] Fix | Delete
if minkeypage is not None: d.set_bt_minkey(minkeypage)
[378] Fix | Delete
if maxkeypage is not None: d.set_bt_maxkey(maxkeypage)
[379] Fix | Delete
d.open(file, db.DB_BTREE, flags, mode)
[380] Fix | Delete
return _DBWithCursor(d)
[381] Fix | Delete
[382] Fix | Delete
#----------------------------------------------------------------------
[383] Fix | Delete
[384] Fix | Delete
[385] Fix | Delete
def rnopen(file, flag='c', mode=0666,
[386] Fix | Delete
rnflags=0, cachesize=None, pgsize=None, lorder=None,
[387] Fix | Delete
rlen=None, delim=None, source=None, pad=None):
[388] Fix | Delete
[389] Fix | Delete
flags = _checkflag(flag, file)
[390] Fix | Delete
e = _openDBEnv(cachesize)
[391] Fix | Delete
d = db.DB(e)
[392] Fix | Delete
if pgsize is not None: d.set_pagesize(pgsize)
[393] Fix | Delete
if lorder is not None: d.set_lorder(lorder)
[394] Fix | Delete
d.set_flags(rnflags)
[395] Fix | Delete
if delim is not None: d.set_re_delim(delim)
[396] Fix | Delete
if rlen is not None: d.set_re_len(rlen)
[397] Fix | Delete
if source is not None: d.set_re_source(source)
[398] Fix | Delete
if pad is not None: d.set_re_pad(pad)
[399] Fix | Delete
d.open(file, db.DB_RECNO, flags, mode)
[400] Fix | Delete
return _DBWithCursor(d)
[401] Fix | Delete
[402] Fix | Delete
#----------------------------------------------------------------------
[403] Fix | Delete
[404] Fix | Delete
def _openDBEnv(cachesize):
[405] Fix | Delete
e = db.DBEnv()
[406] Fix | Delete
if cachesize is not None:
[407] Fix | Delete
if cachesize >= 20480:
[408] Fix | Delete
e.set_cachesize(0, cachesize)
[409] Fix | Delete
else:
[410] Fix | Delete
raise error, "cachesize must be >= 20480"
[411] Fix | Delete
e.set_lk_detect(db.DB_LOCK_DEFAULT)
[412] Fix | Delete
e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
[413] Fix | Delete
return e
[414] Fix | Delete
[415] Fix | Delete
def _checkflag(flag, file):
[416] Fix | Delete
if flag == 'r':
[417] Fix | Delete
flags = db.DB_RDONLY
[418] Fix | Delete
elif flag == 'rw':
[419] Fix | Delete
flags = 0
[420] Fix | Delete
elif flag == 'w':
[421] Fix | Delete
flags = db.DB_CREATE
[422] Fix | Delete
elif flag == 'c':
[423] Fix | Delete
flags = db.DB_CREATE
[424] Fix | Delete
elif flag == 'n':
[425] Fix | Delete
flags = db.DB_CREATE
[426] Fix | Delete
#flags = db.DB_CREATE | db.DB_TRUNCATE
[427] Fix | Delete
# we used db.DB_TRUNCATE flag for this before but Berkeley DB
[428] Fix | Delete
# 4.2.52 changed to disallowed truncate with txn environments.
[429] Fix | Delete
if file is not None and os.path.isfile(file):
[430] Fix | Delete
os.unlink(file)
[431] Fix | Delete
else:
[432] Fix | Delete
raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
[433] Fix | Delete
return flags | db.DB_THREAD
[434] Fix | Delete
[435] Fix | Delete
#----------------------------------------------------------------------
[436] Fix | Delete
[437] Fix | Delete
[438] Fix | Delete
# This is a silly little hack that allows apps to continue to use the
[439] Fix | Delete
# DB_THREAD flag even on systems without threads without freaking out
[440] Fix | Delete
# Berkeley DB.
[441] Fix | Delete
#
[442] Fix | Delete
# This assumes that if Python was built with thread support then
[443] Fix | Delete
# Berkeley DB was too.
[444] Fix | Delete
[445] Fix | Delete
try:
[446] Fix | Delete
# 2to3 automatically changes "import thread" to "import _thread"
[447] Fix | Delete
import thread as T
[448] Fix | Delete
del T
[449] Fix | Delete
[450] Fix | Delete
except ImportError:
[451] Fix | Delete
db.DB_THREAD = 0
[452] Fix | Delete
[453] Fix | Delete
#----------------------------------------------------------------------
[454] Fix | Delete
[455] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function