Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python2....
File: anydbm.py
"""Generic interface to all dbm clones.
[0] Fix | Delete
[1] Fix | Delete
Instead of
[2] Fix | Delete
[3] Fix | Delete
import dbm
[4] Fix | Delete
d = dbm.open(file, 'w', 0666)
[5] Fix | Delete
[6] Fix | Delete
use
[7] Fix | Delete
[8] Fix | Delete
import anydbm
[9] Fix | Delete
d = anydbm.open(file, 'w')
[10] Fix | Delete
[11] Fix | Delete
The returned object is a dbhash, gdbm, dbm or dumbdbm object,
[12] Fix | Delete
dependent on the type of database being opened (determined by whichdb
[13] Fix | Delete
module) in the case of an existing dbm. If the dbm does not exist and
[14] Fix | Delete
the create or new flag ('c' or 'n') was specified, the dbm type will
[15] Fix | Delete
be determined by the availability of the modules (tested in the above
[16] Fix | Delete
order).
[17] Fix | Delete
[18] Fix | Delete
It has the following interface (key and data are strings):
[19] Fix | Delete
[20] Fix | Delete
d[key] = data # store data at key (may override data at
[21] Fix | Delete
# existing key)
[22] Fix | Delete
data = d[key] # retrieve data at key (raise KeyError if no
[23] Fix | Delete
# such key)
[24] Fix | Delete
del d[key] # delete data stored at key (raises KeyError
[25] Fix | Delete
# if no such key)
[26] Fix | Delete
flag = key in d # true if the key exists
[27] Fix | Delete
list = d.keys() # return a list of all existing keys (slow!)
[28] Fix | Delete
[29] Fix | Delete
Future versions may change the order in which implementations are
[30] Fix | Delete
tested for existence, and add interfaces to other dbm-like
[31] Fix | Delete
implementations.
[32] Fix | Delete
"""
[33] Fix | Delete
[34] Fix | Delete
class error(Exception):
[35] Fix | Delete
pass
[36] Fix | Delete
[37] Fix | Delete
_names = ['dbhash', 'gdbm', 'dbm', 'dumbdbm']
[38] Fix | Delete
_errors = [error]
[39] Fix | Delete
_defaultmod = None
[40] Fix | Delete
[41] Fix | Delete
for _name in _names:
[42] Fix | Delete
try:
[43] Fix | Delete
_mod = __import__(_name)
[44] Fix | Delete
except ImportError:
[45] Fix | Delete
continue
[46] Fix | Delete
if not _defaultmod:
[47] Fix | Delete
_defaultmod = _mod
[48] Fix | Delete
_errors.append(_mod.error)
[49] Fix | Delete
[50] Fix | Delete
if not _defaultmod:
[51] Fix | Delete
raise ImportError, "no dbm clone found; tried %s" % _names
[52] Fix | Delete
[53] Fix | Delete
error = tuple(_errors)
[54] Fix | Delete
[55] Fix | Delete
def open(file, flag='r', mode=0666):
[56] Fix | Delete
"""Open or create database at path given by *file*.
[57] Fix | Delete
[58] Fix | Delete
Optional argument *flag* can be 'r' (default) for read-only access, 'w'
[59] Fix | Delete
for read-write access of an existing database, 'c' for read-write access
[60] Fix | Delete
to a new or existing database, and 'n' for read-write access to a new
[61] Fix | Delete
database.
[62] Fix | Delete
[63] Fix | Delete
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
[64] Fix | Delete
only if it doesn't exist; and 'n' always creates a new database.
[65] Fix | Delete
"""
[66] Fix | Delete
[67] Fix | Delete
# guess the type of an existing database
[68] Fix | Delete
from whichdb import whichdb
[69] Fix | Delete
result=whichdb(file)
[70] Fix | Delete
if result is None:
[71] Fix | Delete
# db doesn't exist
[72] Fix | Delete
if 'c' in flag or 'n' in flag:
[73] Fix | Delete
# file doesn't exist and the new
[74] Fix | Delete
# flag was used so use default type
[75] Fix | Delete
mod = _defaultmod
[76] Fix | Delete
else:
[77] Fix | Delete
raise error, "need 'c' or 'n' flag to open new db"
[78] Fix | Delete
elif result == "":
[79] Fix | Delete
# db type cannot be determined
[80] Fix | Delete
raise error, "db type could not be determined"
[81] Fix | Delete
else:
[82] Fix | Delete
mod = __import__(result)
[83] Fix | Delete
return mod.open(file, flag, mode)
[84] Fix | Delete
[85] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function