@@ -84,10 +84,13 @@ the Oracle Berkeley DB.
84
84
.. versionchanged :: 3.11
85
85
*file * accepts a :term: `path-like object `.
86
86
87
- The object returned by :func: `~dbm.open ` supports the same basic functionality as a
88
- :class: `dict `; keys and their corresponding values can be stored, retrieved, and
89
- deleted, and the :keyword: `in ` operator and the :meth: `!keys ` method are
90
- available, as well as :meth: `!get ` and :meth: `!setdefault ` methods.
87
+ The object returned by :func: `~dbm.open ` supports the basic
88
+ functionality of mutable :term: `mappings <mapping> `;
89
+ keys and their corresponding values can be stored, retrieved, and
90
+ deleted, and iteration, the :keyword: `in ` operator and methods :meth: `!keys `,
91
+ :meth: `!get `, :meth: `!setdefault ` and :meth: `!clear ` are available.
92
+ The :meth: `!keys ` method returns a list instead of a view object.
93
+ The :meth: `!setdefault ` method requires two arguments.
91
94
92
95
Key and values are always stored as :class: `bytes `. This means that when
93
96
strings are used they are implicitly converted to the default encoding before
@@ -108,6 +111,10 @@ will automatically close them when done.
108
111
Deleting a key from a read-only database raises a database module specific exception
109
112
instead of :exc: `KeyError `.
110
113
114
+ .. versionchanged :: 3.13
115
+ :meth: `!clear ` methods are now available for all :mod: `dbm ` backends.
116
+
117
+
111
118
The following example records some hostnames and a corresponding title, and
112
119
then prints out the contents of the database::
113
120
@@ -167,9 +174,6 @@ or any other SQLite browser, including the SQLite CLI.
167
174
.. function :: open(filename, /, flag="r", mode=0o666)
168
175
169
176
Open an SQLite database.
170
- The returned object behaves like a :term: `mapping `,
171
- implements a :meth: `!close ` method,
172
- and supports a "closing" context manager via the :keyword: `with ` keyword.
173
177
174
178
:param filename:
175
179
The path to the database to be opened.
@@ -186,6 +190,17 @@ or any other SQLite browser, including the SQLite CLI.
186
190
The Unix file access mode of the file (default: octal ``0o666 ``),
187
191
used only when the database has to be created.
188
192
193
+ The returned database object behaves similar to a mutable :term: `mapping `,
194
+ but the :meth: `!keys ` method returns a list, and
195
+ the :meth: `!setdefault ` method requires two arguments.
196
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
197
+
198
+ The following method is also provided:
199
+
200
+ .. method :: sqlite3.close()
201
+
202
+ Close the SQLite database.
203
+
189
204
190
205
:mod: `dbm.gnu ` --- GNU database manager
191
206
---------------------------------------
@@ -215,6 +230,11 @@ functionality like crash tolerance.
215
230
raised for general mapping errors like specifying an incorrect key.
216
231
217
232
233
+ .. data :: open_flags
234
+
235
+ A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
236
+
237
+
218
238
.. function :: open(filename, flag="r", mode=0o666, /)
219
239
220
240
Open a GDBM database and return a :class: `!gdbm ` object.
@@ -250,14 +270,25 @@ functionality like crash tolerance.
250
270
.. versionchanged :: 3.11
251
271
*filename * accepts a :term: `path-like object `.
252
272
253
- .. data :: open_flags
273
+ :class: `!gdbm ` objects behave similar to mutable :term: `mappings <mapping> `,
274
+ but methods :meth: `!items `, :meth: `!values `, :meth: `!pop `, :meth: `!popitem `,
275
+ and :meth: `!update ` are not supported,
276
+ the :meth: `!keys ` method returns a list, and
277
+ the :meth: `!setdefault ` method requires two arguments.
278
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
279
+
280
+ .. versionchanged :: 3.2
281
+ Added the :meth: `!get ` and :meth: `!setdefault ` methods.
254
282
255
- A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
283
+ .. versionchanged :: 3.13
284
+ Added the :meth: `!clear ` method.
256
285
257
- :class: `!gdbm ` objects behave similar to :term: `mappings <mapping> `,
258
- but :meth: `!items ` and :meth: `!values ` methods are not supported.
259
286
The following methods are also provided:
260
287
288
+ .. method :: gdbm.close()
289
+
290
+ Close the GDBM database.
291
+
261
292
.. method :: gdbm.firstkey()
262
293
263
294
It's possible to loop over every key in the database using this method and the
@@ -289,16 +320,6 @@ functionality like crash tolerance.
289
320
When the database has been opened in fast mode, this method forces any
290
321
unwritten data to be written to the disk.
291
322
292
- .. method :: gdbm.close()
293
-
294
- Close the GDBM database.
295
-
296
- .. method :: gdbm.clear()
297
-
298
- Remove all items from the GDBM database.
299
-
300
- .. versionadded :: 3.13
301
-
302
323
303
324
:mod: `dbm.ndbm ` --- New Database Manager
304
325
----------------------------------------
@@ -359,22 +380,27 @@ This module can be used with the "classic" NDBM interface or the
359
380
:param int mode:
360
381
|mode_param_doc |
361
382
362
- :class: `!ndbm ` objects behave similar to :term: `mappings <mapping> `,
363
- but :meth: `!items ` and :meth: `!values ` methods are not supported.
364
- The following methods are also provided:
365
-
366
383
.. versionchanged :: 3.11
367
384
Accepts :term: `path-like object ` for filename.
368
385
369
- .. method :: ndbm.close()
386
+ :class: `!ndbm ` objects behave similar to mutable :term: `mappings <mapping> `,
387
+ but methods :meth: `!items `, :meth: `!values `, :meth: `!pop `, :meth: `!popitem `,
388
+ and :meth: `!update ` are not supported,
389
+ the :meth: `!keys ` method returns a list, and
390
+ the :meth: `!setdefault ` method requires two arguments.
391
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
370
392
371
- Close the NDBM database.
393
+ .. versionchanged :: 3.2
394
+ Added the :meth: `!get ` and :meth: `!setdefault ` methods.
372
395
373
- .. method :: ndbm.clear()
396
+ .. versionchanged :: 3.13
397
+ Added the :meth: `!clear ` method.
374
398
375
- Remove all items from the NDBM database.
399
+ The following method is also provided:
376
400
377
- .. versionadded :: 3.13
401
+ .. method :: ndbm.close()
402
+
403
+ Close the NDBM database.
378
404
379
405
380
406
:mod: `dbm.dumb ` --- Portable DBM implementation
@@ -412,9 +438,6 @@ The :mod:`!dbm.dumb` module defines the following:
412
438
.. function :: open(filename, flag="c", mode=0o666)
413
439
414
440
Open a :mod: `!dbm.dumb ` database.
415
- The returned database object behaves similar to a :term: `mapping `,
416
- in addition to providing :meth: `~dumbdbm.sync ` and :meth: `~dumbdbm.close `
417
- methods.
418
441
419
442
:param filename:
420
443
The basename of the database file (without extensions).
@@ -448,15 +471,18 @@ The :mod:`!dbm.dumb` module defines the following:
448
471
.. versionchanged :: 3.11
449
472
*filename * accepts a :term: `path-like object `.
450
473
451
- In addition to the methods provided by the
452
- :class: `collections.abc.MutableMapping ` class,
453
- the following methods are provided:
474
+ The returned database object behaves similar to a mutable :term: `mapping `,
475
+ but the :meth: `!keys ` and :meth: `!items ` methods return lists, and
476
+ the :meth: `!setdefault ` method requires two arguments.
477
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
454
478
455
- .. method :: dumbdbm.sync()
456
-
457
- Synchronize the on-disk directory and data files. This method is called
458
- by the :meth: `shelve.Shelf.sync ` method.
479
+ The following methods are also provided:
459
480
460
481
.. method :: dumbdbm.close()
461
482
462
483
Close the database.
484
+
485
+ .. method :: dumbdbm.sync()
486
+
487
+ Synchronize the on-disk directory and data files. This method is called
488
+ by the :meth: `shelve.Shelf.sync ` method.
0 commit comments