blob: 2344c5aeb3d9609cdaf2799cba8e501756e3371f [file] [log] [blame]
Fred Drake2764dd31998-04-07 22:08:02 +00001\section{Standard Module \module{anydbm}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{anydbm}
3
4\modulesynopsis{Generic interface to DBM-style database modules.}
5
Guido van Rossum571391b1997-04-03 22:41:49 +00006
Fred Drakeddf03bf1998-02-18 15:05:47 +00007\module{anydbm} is a generic interface to variants of the DBM
Fred Drake2764dd31998-04-07 22:08:02 +00008database --- \module{dbhash}\refbimodindex{dbhash},
9\module{gdbm}\refbimodindex{gdbm}, or \module{dbm}\refbimodindex{dbm}.
10If none of these modules is installed, the slow-but-simple
11implementation in module \module{dumbdbm}\refstmodindex{dumbdbm} will
12be used.
Guido van Rossum571391b1997-04-03 22:41:49 +000013
Fred Drake2764dd31998-04-07 22:08:02 +000014\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
Fred Drakeddf03bf1998-02-18 15:05:47 +000015Open the database file \var{filename} and return a corresponding object.
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000016
17If the database file already exists, the \module{whichdb} module is
18used to determine its type and the appropriate module is used; if it
19doesn't exist, the first module listed above that can be imported is
20used.
21
Guido van Rossum571391b1997-04-03 22:41:49 +000022The optional \var{flag} argument can be
23\code{'r'} to open an existing database for reading only,
24\code{'w'} to open an existing database for reading and writing,
25\code{'c'} to create the database if it doesn't exist, or
26\code{'n'}, which will always create a new empty database. If not
27specified, the default value is \code{'r'}.
28
29The optional \var{mode} argument is the \UNIX{} mode of the file, used
30only when the database has to be created. It defaults to octal
Guido van Rossum51a6c901997-05-09 02:23:45 +000031\code{0666} (and will be modified by the prevailing umask).
Guido van Rossum571391b1997-04-03 22:41:49 +000032\end{funcdesc}
33
Fred Drake2764dd31998-04-07 22:08:02 +000034\begin{excdesc}{error}
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000035A tuple containing the exceptions that can be raised by each of the
36supported modules, with a unique exception \exception{anydbm.error} as
37the first item --- the latter is used when \exception{anydbm.error} is
38raised.
Fred Drake2764dd31998-04-07 22:08:02 +000039\end{excdesc}
40
Fred Drakeddf03bf1998-02-18 15:05:47 +000041The object returned by \function{open()} supports most of the same
Guido van Rossum571391b1997-04-03 22:41:49 +000042functionality as dictionaries; keys and their corresponding values can
Fred Drakeddf03bf1998-02-18 15:05:47 +000043be stored, retrieved, and deleted, and the \method{has_key()} and
44\method{keys()} methods are available. Keys and values must always be
Guido van Rossum51a6c901997-05-09 02:23:45 +000045strings.
Guido van Rossum571391b1997-04-03 22:41:49 +000046
Fred Drake2764dd31998-04-07 22:08:02 +000047
48
49\section{Standard Module \module{dumbdbm}}
Fred Drakeb91e9341998-07-23 17:59:49 +000050\declaremodule{standard}{dumbdbm}
51
Fred Drake9030b0f1998-07-27 22:12:26 +000052\modulesynopsis{Portable implementation of the simple DBM interface.}
Fred Drakeb91e9341998-07-23 17:59:49 +000053
Fred Drake2764dd31998-04-07 22:08:02 +000054
55A simple and slow database implemented entirely in Python. This
56should only be used when no other DBM-style database is available.
57
58
59\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
60Open the database file \var{filename} and return a corresponding object.
61The optional \var{flag} argument can be
62\code{'r'} to open an existing database for reading only,
63\code{'w'} to open an existing database for reading and writing,
64\code{'c'} to create the database if it doesn't exist, or
65\code{'n'}, which will always create a new empty database. If not
66specified, the default value is \code{'r'}.
67
68The optional \var{mode} argument is the \UNIX{} mode of the file, used
69only when the database has to be created. It defaults to octal
70\code{0666} (and will be modified by the prevailing umask).
71\end{funcdesc}
72
73\begin{excdesc}{error}
74Raised for errors not reported as \exception{KeyError} errors.
75\end{excdesc}