Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 1 | \section{\module{dumbdbm} --- |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 2 | Portable DBM implementation} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 3 | |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{dumbdbm} |
| 5 | \modulesynopsis{Portable implementation of the simple DBM interface.} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 6 | |
| 7 | \index{databases} |
| 8 | |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 9 | \begin{notice} |
| 10 | The \module{dumbdbm} module is intended as a last resort fallback for |
| 11 | the \refmodule{anydbm} module when no more robust module is available. |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 12 | The \module{dumbdbm} module is not written for speed and is not nearly as |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 13 | heavily used as the other database modules. |
| 14 | \end{notice} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 15 | |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 16 | The \module{dumbdbm} module provides a persistent dictionary-like interface |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 17 | which is written entirely in Python. Unlike other modules such as |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 18 | \refmodule{gdbm} and \refmodule{bsddb}, no external library is required. As |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 19 | with other persistent mappings, the keys and values must always be strings. |
| 20 | |
| 21 | The module defines the following: |
| 22 | |
| 23 | \begin{excdesc}{error} |
| 24 | Raised on dumbdbm-specific errors, such as I/O errors. \exception{KeyError} |
| 25 | is raised for general mapping errors like specifying an incorrect key. |
| 26 | \end{excdesc} |
| 27 | |
| 28 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 29 | Open a dumbdbm database and return a dumbdbm object. The \var{filename} |
| 30 | argument is the basename of the database file (without any specific |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 31 | extensions). When a dumbdbm database is created, files with \file{.dat} and |
| 32 | \file{.dir} extensions are created. |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 33 | |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 34 | The optional \var{flag} argument is currently ignored; the database is |
| 35 | always opened for update, and will be created if it does not exist. |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 36 | |
| 37 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 38 | only when the database has to be created. It defaults to octal |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 39 | \code{0666} (and will be modified by the prevailing umask). |
| 40 | \versionchanged[The \var{mode} argument was ignored in earlier |
| 41 | versions]{2.2} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 42 | \end{funcdesc} |
| 43 | |
Fred Drake | 6c49709 | 2003-07-21 15:30:15 +0000 | [diff] [blame] | 44 | |
| 45 | \begin{seealso} |
| 46 | \seemodule{anydbm}{Generic interface to \code{dbm}-style databases.} |
| 47 | \seemodule{dbm}{Similar interface to the DBM/NDBM library.} |
| 48 | \seemodule{gdbm}{Similar interface to the GNU GDBM library.} |
| 49 | \seemodule{shelve}{Persistence module which stores non-string data.} |
| 50 | \seemodule{whichdb}{Utility module used to determine the type of an |
| 51 | existing database.} |
| 52 | \end{seealso} |
| 53 | |
| 54 | |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 55 | \subsection{Dumbdbm Objects \label{dumbdbm-objects}} |
| 56 | |
| 57 | In addition to the methods provided by the \class{UserDict.DictMixin} class, |
| 58 | \class{dumbdbm} objects provide the following methods. |
| 59 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 60 | \begin{methoddesc}[dumbdbm]{sync}{} |
Skip Montanaro | d54c5dd | 2003-07-14 12:12:37 +0000 | [diff] [blame] | 61 | Synchronize the on-disk directory and data files. This method is called by |
| 62 | the \method{sync} method of \class{Shelve} objects. |
| 63 | \end{methoddesc} |