Left: | ||
Right: |
OLD | NEW |
---|---|
1 :mod:`dbm` --- Interfaces to Unix "databases" | 1 :mod:`dbm` --- Interfaces to Unix "databases" |
2 ============================================= | 2 ============================================= |
3 | 3 |
4 .. module:: dbm | 4 .. module:: dbm |
5 :synopsis: Interfaces to various Unix "database" formats. | 5 :synopsis: Interfaces to various Unix "database" formats. |
6 | 6 |
7 :mod:`dbm` is a generic interface to variants of the DBM database --- | 7 :mod:`dbm` is a generic interface to variants of the DBM database --- |
8 :mod:`dbm.gnu` or :mod:`dbm.ndbm`. If none of these modules is installed, the | 8 :mod:`dbm.gnu` or :mod:`dbm.ndbm`. If none of these modules is installed, the |
9 slow-but-simple implementation in module :mod:`dbm.dumb` will be used. There | 9 slow-but-simple implementation in module :mod:`dbm.dumb` will be used. There |
10 is a `third party interface <http://www.jcea.es/programacion/pybsddb.htm>`_ to | 10 is a `third party interface <http://www.jcea.es/programacion/pybsddb.htm>`_ to |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | | for reading and writing | | 56 | | for reading and writing | |
57 +---------+-------------------------------------------+ | 57 +---------+-------------------------------------------+ |
58 | 58 |
59 The optional *mode* argument is the Unix mode of the file, used only when the | 59 The optional *mode* argument is the Unix mode of the file, used only when the |
60 database has to be created. It defaults to octal ``0o666`` (and will be | 60 database has to be created. It defaults to octal ``0o666`` (and will be |
61 modified by the prevailing umask). | 61 modified by the prevailing umask). |
62 | 62 |
63 | 63 |
64 The object returned by :func:`.open` supports the same basic functionality as | 64 The object returned by :func:`.open` supports the same basic functionality as |
65 dictionaries; keys and their corresponding values can be stored, retrieved, and | 65 dictionaries; keys and their corresponding values can be stored, retrieved, and |
66 deleted, and the :keyword:`in` operator and the :meth:`keys` method are | 66 deleted, and the :keyword:`in` operator and the :meth:`keys`, :meth:`values`, |
67 available, as well as :meth:`get` and :meth:`setdefault`. | 67 :meth:`items` methods are available, as well as :meth:`get`, :meth:`setdefault`, |
68 :meth:`pop`, :meth:`popitem` :meth:`clear` and :meth:`update`. | |
68 | 69 |
69 .. versionchanged:: 3.2 | 70 .. versionchanged:: 3.2 |
70 :meth:`get` and :meth:`setdefault` are now available in all database modules. | 71 The MutableMapping interfaces and :meth:`setdefault` are now available in all |
72 database modules. | |
merwok
2011/02/10 21:53:49
3.2 being in rc stage, your additions will go into
ray
2011/02/12 16:40:06
Done.
| |
71 | 73 |
72 Key and values are always stored as bytes. This means that when | 74 Key and values are always stored as bytes. This means that when |
73 strings are used they are implicitly converted to the default encoding before | 75 strings are used they are implicitly converted to the default encoding before |
74 being stored. | 76 being stored. |
75 | 77 |
76 The following example records some hostnames and a corresponding title, and | 78 The following example records some hostnames and a corresponding title, and |
77 then prints out the contents of the database:: | 79 then prints out the contents of the database:: |
78 | 80 |
79 import dbm | 81 import dbm |
80 | 82 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 :synopsis: GNU's reinterpretation of dbm. | 121 :synopsis: GNU's reinterpretation of dbm. |
120 | 122 |
121 | 123 |
122 This module is quite similar to the :mod:`dbm` module, but uses the GNU library | 124 This module is quite similar to the :mod:`dbm` module, but uses the GNU library |
123 ``gdbm`` instead to provide some additional functionality. Please note that the | 125 ``gdbm`` instead to provide some additional functionality. Please note that the |
124 file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible. | 126 file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible. |
125 | 127 |
126 The :mod:`dbm.gnu` module provides an interface to the GNU DBM library. | 128 The :mod:`dbm.gnu` module provides an interface to the GNU DBM library. |
127 ``dbm.gnu.gdbm`` objects behave like mappings (dictionaries), except that keys a nd | 129 ``dbm.gnu.gdbm`` objects behave like mappings (dictionaries), except that keys a nd |
128 values are always converted to bytes before storing. Printing a ``gdbm`` | 130 values are always converted to bytes before storing. Printing a ``gdbm`` |
129 object doesn't print the | 131 object doesn't print the keys and values. |
130 keys and values, and the :meth:`items` and :meth:`values` methods are not | |
131 supported. | |
132 | 132 |
133 .. exception:: error | 133 .. exception:: error |
134 | 134 |
135 Raised on :mod:`dbm.gnu`-specific errors, such as I/O errors. :exc:`KeyError` is | 135 Raised on :mod:`dbm.gnu`-specific errors, such as I/O errors. :exc:`KeyError` is |
136 raised for general mapping errors like specifying an incorrect key. | 136 raised for general mapping errors like specifying an incorrect key. |
137 | 137 |
138 | 138 |
139 .. function:: open(filename[, flag[, mode]]) | 139 .. function:: open(filename[, flag[, mode]]) |
140 | 140 |
141 Open a ``gdbm`` database and return a :class:`gdbm` object. The *filename* | 141 Open a ``gdbm`` database and return a :class:`gdbm` object. The *filename* |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 ------------------------------------------- | 221 ------------------------------------------- |
222 | 222 |
223 .. module:: dbm.ndbm | 223 .. module:: dbm.ndbm |
224 :platform: Unix | 224 :platform: Unix |
225 :synopsis: The standard "database" interface, based on ndbm. | 225 :synopsis: The standard "database" interface, based on ndbm. |
226 | 226 |
227 | 227 |
228 The :mod:`dbm.ndbm` module provides an interface to the Unix "(n)dbm" library. | 228 The :mod:`dbm.ndbm` module provides an interface to the Unix "(n)dbm" library. |
229 Dbm objects behave like mappings (dictionaries), except that keys and values are | 229 Dbm objects behave like mappings (dictionaries), except that keys and values are |
230 always stored as bytes. Printing a ``dbm`` object doesn't print the keys and | 230 always stored as bytes. Printing a ``dbm`` object doesn't print the keys and |
231 values, and the :meth:`items` and :meth:`values` methods are not supported. | 231 values. |
232 | 232 |
233 This module can be used with the "classic" ndbm interface or the GNU GDBM | 233 This module can be used with the "classic" ndbm interface or the GNU GDBM |
234 compatibility interface. On Unix, the :program:`configure` script will attempt | 234 compatibility interface. On Unix, the :program:`configure` script will attempt |
235 to locate the appropriate header file to simplify building this module. | 235 to locate the appropriate header file to simplify building this module. |
236 | 236 |
237 .. exception:: error | 237 .. exception:: error |
238 | 238 |
239 Raised on :mod:`dbm.ndbm`-specific errors, such as I/O errors. :exc:`KeyError ` is raised | 239 Raised on :mod:`dbm.ndbm`-specific errors, such as I/O errors. :exc:`KeyError ` is raised |
240 for general mapping errors like specifying an incorrect key. | 240 for general mapping errors like specifying an incorrect key. |
241 | 241 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 database has to be created. It defaults to octal ``0o666`` (and will be modi fied | 317 database has to be created. It defaults to octal ``0o666`` (and will be modi fied |
318 by the prevailing umask). | 318 by the prevailing umask). |
319 | 319 |
320 In addition to the methods provided by the :class:`collections.MutableMapping ` class, | 320 In addition to the methods provided by the :class:`collections.MutableMapping ` class, |
321 :class:`dumbdbm` objects provide the following method: | 321 :class:`dumbdbm` objects provide the following method: |
322 | 322 |
323 .. method:: dumbdbm.sync() | 323 .. method:: dumbdbm.sync() |
324 | 324 |
325 Synchronize the on-disk directory and data files. This method is called | 325 Synchronize the on-disk directory and data files. This method is called |
326 by the :meth:`Shelve.sync` method. | 326 by the :meth:`Shelve.sync` method. |
OLD | NEW |