@@ -90,10 +90,13 @@ the Oracle Berkeley DB.
90
90
.. versionchanged :: 3.11
91
91
*file * accepts a :term: `path-like object `.
92
92
93
- The object returned by :func: `~dbm.open ` supports the same basic functionality as a
94
- :class: `dict `; keys and their corresponding values can be stored, retrieved, and
95
- deleted, and the :keyword: `in ` operator and the :meth: `!keys ` method are
96
- available, as well as :meth: `!get ` and :meth: `!setdefault ` methods.
93
+ The object returned by :func: `~dbm.open ` supports the basic
94
+ functionality of mutable :term: `mappings <mapping> `;
95
+ keys and their corresponding values can be stored, retrieved, and
96
+ deleted, and iteration, the :keyword: `in ` operator and methods :meth: `!keys `,
97
+ :meth: `!get `, :meth: `!setdefault ` and :meth: `!clear ` are available.
98
+ The :meth: `!keys ` method returns a list instead of a view object.
99
+ The :meth: `!setdefault ` method requires two arguments.
97
100
98
101
Key and values are always stored as :class: `bytes `. This means that when
99
102
strings are used they are implicitly converted to the default encoding before
@@ -114,6 +117,10 @@ will automatically close them when done.
114
117
Deleting a key from a read-only database raises a database module specific exception
115
118
instead of :exc: `KeyError `.
116
119
120
+ .. versionchanged :: 3.13
121
+ :meth: `!clear ` methods are now available for all :mod: `dbm ` backends.
122
+
123
+
117
124
The following example records some hostnames and a corresponding title, and
118
125
then prints out the contents of the database::
119
126
@@ -173,9 +180,6 @@ or any other SQLite browser, including the SQLite CLI.
173
180
.. function :: open(filename, /, flag="r", mode=0o666)
174
181
175
182
Open an SQLite database.
176
- The returned object behaves like a :term: `mapping `,
177
- implements a :meth: `!close ` method,
178
- and supports a "closing" context manager via the :keyword: `with ` keyword.
179
183
180
184
:param filename:
181
185
The path to the database to be opened.
@@ -192,6 +196,17 @@ or any other SQLite browser, including the SQLite CLI.
192
196
The Unix file access mode of the file (default: octal ``0o666 ``),
193
197
used only when the database has to be created.
194
198
199
+ The returned database object behaves similar to a mutable :term: `mapping `,
200
+ but the :meth: `!keys ` method returns a list, and
201
+ the :meth: `!setdefault ` method requires two arguments.
202
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
203
+
204
+ The following methods are also provided:
205
+
206
+ .. method :: sqlite3.close()
207
+
208
+ Close the SQLite database.
209
+
195
210
.. method :: sqlite3.reorganize()
196
211
197
212
If you have carried out a lot of deletions and would like to shrink the space
@@ -204,6 +219,7 @@ or any other SQLite browser, including the SQLite CLI.
204
219
205
220
.. versionadded :: next
206
221
222
+
207
223
:mod: `dbm.gnu ` --- GNU database manager
208
224
---------------------------------------
209
225
@@ -232,6 +248,11 @@ functionality like crash tolerance.
232
248
raised for general mapping errors like specifying an incorrect key.
233
249
234
250
251
+ .. data :: open_flags
252
+
253
+ A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
254
+
255
+
235
256
.. function :: open(filename, flag="r", mode=0o666, /)
236
257
237
258
Open a GDBM database and return a :class: `!gdbm ` object.
@@ -270,14 +291,25 @@ functionality like crash tolerance.
270
291
.. versionchanged :: 3.11
271
292
*filename * accepts a :term: `path-like object `.
272
293
273
- .. data :: open_flags
294
+ :class: `!gdbm ` objects behave similar to mutable :term: `mappings <mapping> `,
295
+ but methods :meth: `!items `, :meth: `!values `, :meth: `!pop `, :meth: `!popitem `,
296
+ and :meth: `!update ` are not supported,
297
+ the :meth: `!keys ` method returns a list, and
298
+ the :meth: `!setdefault ` method requires two arguments.
299
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
300
+
301
+ .. versionchanged :: 3.2
302
+ Added the :meth: `!get ` and :meth: `!setdefault ` methods.
274
303
275
- A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
304
+ .. versionchanged :: 3.13
305
+ Added the :meth: `!clear ` method.
276
306
277
- :class: `!gdbm ` objects behave similar to :term: `mappings <mapping> `,
278
- but :meth: `!items ` and :meth: `!values ` methods are not supported.
279
307
The following methods are also provided:
280
308
309
+ .. method :: gdbm.close()
310
+
311
+ Close the GDBM database.
312
+
281
313
.. method :: gdbm.firstkey()
282
314
283
315
It's possible to loop over every key in the database using this method and the
@@ -313,16 +345,6 @@ functionality like crash tolerance.
313
345
When the database has been opened in fast mode, this method forces any
314
346
unwritten data to be written to the disk.
315
347
316
- .. method :: gdbm.close()
317
-
318
- Close the GDBM database.
319
-
320
- .. method :: gdbm.clear()
321
-
322
- Remove all items from the GDBM database.
323
-
324
- .. versionadded :: 3.13
325
-
326
348
327
349
:mod: `dbm.ndbm ` --- New Database Manager
328
350
----------------------------------------
@@ -383,22 +405,27 @@ This module can be used with the "classic" NDBM interface or the
383
405
:param int mode:
384
406
|mode_param_doc |
385
407
386
- :class: `!ndbm ` objects behave similar to :term: `mappings <mapping> `,
387
- but :meth: `!items ` and :meth: `!values ` methods are not supported.
388
- The following methods are also provided:
389
-
390
408
.. versionchanged :: 3.11
391
409
Accepts :term: `path-like object ` for filename.
392
410
393
- .. method :: ndbm.close()
411
+ :class: `!ndbm ` objects behave similar to mutable :term: `mappings <mapping> `,
412
+ but methods :meth: `!items `, :meth: `!values `, :meth: `!pop `, :meth: `!popitem `,
413
+ and :meth: `!update ` are not supported,
414
+ the :meth: `!keys ` method returns a list, and
415
+ the :meth: `!setdefault ` method requires two arguments.
416
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
394
417
395
- Close the NDBM database.
418
+ .. versionchanged :: 3.2
419
+ Added the :meth: `!get ` and :meth: `!setdefault ` methods.
396
420
397
- .. method :: ndbm.clear()
421
+ .. versionchanged :: 3.13
422
+ Added the :meth: `!clear ` method.
398
423
399
- Remove all items from the NDBM database.
424
+ The following method is also provided:
400
425
401
- .. versionadded :: 3.13
426
+ .. method :: ndbm.close()
427
+
428
+ Close the NDBM database.
402
429
403
430
404
431
:mod: `dbm.dumb ` --- Portable DBM implementation
@@ -436,9 +463,6 @@ The :mod:`!dbm.dumb` module defines the following:
436
463
.. function :: open(filename, flag="c", mode=0o666)
437
464
438
465
Open a :mod: `!dbm.dumb ` database.
439
- The returned database object behaves similar to a :term: `mapping `,
440
- in addition to providing :meth: `~dumbdbm.sync ` and :meth: `~dumbdbm.close `
441
- methods.
442
466
443
467
:param filename:
444
468
The basename of the database file (without extensions).
@@ -477,14 +501,12 @@ The :mod:`!dbm.dumb` module defines the following:
477
501
.. versionchanged :: 3.11
478
502
*filename * accepts a :term: `path-like object `.
479
503
480
- In addition to the methods provided by the
481
- :class: `collections.abc.MutableMapping ` class,
482
- the following methods are provided:
504
+ The returned database object behaves similar to a mutable :term: `mapping `,
505
+ but the :meth: `!keys ` and :meth: `!items ` methods return lists, and
506
+ the :meth: `!setdefault ` method requires two arguments.
507
+ It also supports a "closing" context manager via the :keyword: `with ` keyword.
483
508
484
- .. method :: dumbdbm.sync()
485
-
486
- Synchronize the on-disk directory and data files. This method is called
487
- by the :meth: `shelve.Shelf.sync ` method.
509
+ The following methods are also provided:
488
510
489
511
.. method :: dumbdbm.close()
490
512
@@ -501,3 +523,8 @@ The :mod:`!dbm.dumb` module defines the following:
501
523
that this factor changes for each :mod: `dbm ` submodule.
502
524
503
525
.. versionadded :: next
526
+
527
+ .. method :: dumbdbm.sync()
528
+
529
+ Synchronize the on-disk directory and data files. This method is called
530
+ by the :meth: `shelve.Shelf.sync ` method.
0 commit comments