Back to index

python3.2  3.2.2
Classes | Functions | Variables
dbm.dumb Namespace Reference

Classes

class  _Database

Functions

def open

Variables

list __all__ = ["error", "open"]
int _BLOCKSIZE = 512
 error = IOError

Detailed Description

A dumb and slow but simple dbm clone.

For database spam, spam.dir contains the index (a text file),
spam.bak *may* contain a backup of the index (also a text file),
while spam.dat contains the data (a binary file).

XXX TO DO:

- seems to contain a bug when updating...

- reclaim free space (currently, space once occupied by deleted or expanded
items is never reused)

- support concurrent access (currently, if two processes take turns making
updates, they can mess up the index)

- support efficient access to large databases (currently, the whole index
is read when the database is opened, and some updates rewrite the whole index)

- support opening for read-only (flag = 'm')

Function Documentation

def dbm.dumb.open (   file,
  flag = None,
  mode = 0o666 
)
Open the database file, filename, and return corresponding object.

The flag argument, used to control how the database is opened in the
other DBM implementations, is ignored in the dbm.dumb module; the
database is always opened for update, and will be created if it does
not exist.

The optional mode argument is the UNIX mode of the file, used only when
the database has to be created.  It defaults to octal code 0o666 (and
will be modified by the prevailing umask).

Definition at line 240 of file dumb.py.

00240 
00241 def open(file, flag=None, mode=0o666):
00242     """Open the database file, filename, and return corresponding object.
00243 
00244     The flag argument, used to control how the database is opened in the
00245     other DBM implementations, is ignored in the dbm.dumb module; the
00246     database is always opened for update, and will be created if it does
00247     not exist.
00248 
00249     The optional mode argument is the UNIX mode of the file, used only when
00250     the database has to be created.  It defaults to octal code 0o666 (and
00251     will be modified by the prevailing umask).
00252 
00253     """
00254     # flag argument is currently ignored
00255 
00256     # Modify mode depending on the umask
00257     try:
00258         um = _os.umask(0)
00259         _os.umask(um)
00260     except AttributeError:
00261         pass
00262     else:
00263         # Turn off any bits that are set in the umask
00264         mode = mode & (~um)
00265 
00266     return _Database(file, mode)

Variable Documentation

list dbm.dumb.__all__ = ["error", "open"]

Definition at line 28 of file dumb.py.

Definition at line 30 of file dumb.py.

dbm.dumb.error = IOError

Definition at line 32 of file dumb.py.