Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{anydbm}} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 2 | \declaremodule{standard}{anydbm} |
| 3 | |
| 4 | \modulesynopsis{Generic interface to DBM-style database modules.} |
| 5 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 6 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 7 | \module{anydbm} is a generic interface to variants of the DBM |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 8 | database --- \module{dbhash}\refbimodindex{dbhash}, |
| 9 | \module{gdbm}\refbimodindex{gdbm}, or \module{dbm}\refbimodindex{dbm}. |
| 10 | If none of these modules is installed, the slow-but-simple |
| 11 | implementation in module \module{dumbdbm}\refstmodindex{dumbdbm} will |
| 12 | be used. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 13 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 14 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 15 | Open the database file \var{filename} and return a corresponding object. |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 16 | |
| 17 | If the database file already exists, the \module{whichdb} module is |
| 18 | used to determine its type and the appropriate module is used; if it |
| 19 | doesn't exist, the first module listed above that can be imported is |
| 20 | used. |
| 21 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 22 | The 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 |
| 27 | specified, the default value is \code{'r'}. |
| 28 | |
| 29 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 30 | only when the database has to be created. It defaults to octal |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 31 | \code{0666} (and will be modified by the prevailing umask). |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 32 | \end{funcdesc} |
| 33 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 34 | \begin{excdesc}{error} |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 35 | A tuple containing the exceptions that can be raised by each of the |
| 36 | supported modules, with a unique exception \exception{anydbm.error} as |
| 37 | the first item --- the latter is used when \exception{anydbm.error} is |
| 38 | raised. |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 39 | \end{excdesc} |
| 40 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 41 | The object returned by \function{open()} supports most of the same |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 42 | functionality as dictionaries; keys and their corresponding values can |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 43 | be stored, retrieved, and deleted, and the \method{has_key()} and |
| 44 | \method{keys()} methods are available. Keys and values must always be |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 45 | strings. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 46 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | \section{Standard Module \module{dumbdbm}} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 50 | \declaremodule{standard}{dumbdbm} |
| 51 | |
Fred Drake | 9030b0f | 1998-07-27 22:12:26 +0000 | [diff] [blame^] | 52 | \modulesynopsis{Portable implementation of the simple DBM interface.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 53 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 54 | |
| 55 | A simple and slow database implemented entirely in Python. This |
| 56 | should only be used when no other DBM-style database is available. |
| 57 | |
| 58 | |
| 59 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
| 60 | Open the database file \var{filename} and return a corresponding object. |
| 61 | The 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 |
| 66 | specified, the default value is \code{'r'}. |
| 67 | |
| 68 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 69 | only 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} |
| 74 | Raised for errors not reported as \exception{KeyError} errors. |
| 75 | \end{excdesc} |