@@ -339,61 +339,67 @@ This module can be used with the "classic" NDBM interface or the
339
339
340
340
--------------
341
341
342
- The :mod: `dbm.dumb ` module provides a persistent dictionary -like interface which
343
- is written entirely in Python. Unlike other modules such as :mod: ` dbm.gnu ` no
344
- external library is required. As with other persistent mappings, the keys and
345
- values are always stored as bytes .
346
-
347
- The module defines the following:
342
+ The :mod: `dbm.dumb ` module provides a persistent :class: ` dict ` -like
343
+ interface which is written entirely in Python.
344
+ Unlike other :mod: ` dbm ` backends, such as :mod: ` dbm.gnu `, no
345
+ external library is required .
346
+ As with other :mod: ` dbm ` backends,
347
+ the keys and values are always stored as :class: ` bytes `.
348
348
349
+ The :mod: `!dbm.dumb ` module defines the following:
349
350
350
351
.. exception :: error
351
352
352
353
Raised on :mod: `dbm.dumb `-specific errors, such as I/O errors. :exc: `KeyError ` is
353
354
raised for general mapping errors like specifying an incorrect key.
354
355
355
356
356
- .. function :: open(filename[ , flag[ , mode]] )
357
+ .. function :: open(filename, flag="c" , mode=0o666 )
357
358
358
- Open a `` dumbdbm `` database and return a dumbdbm object. The * filename * argument is
359
- the basename of the database file (without any specific extensions). When a
360
- dumbdbm database is created, files with :file: ` .dat ` and :file: ` .dir ` extensions
361
- are created .
359
+ Open a :mod: ` !dbm.dumb ` database.
360
+ The returned database object behaves similar to a :term: ` mapping `,
361
+ in addition to providing :meth: ` ~dumbdbm.sync ` and :meth: ` ~dumbdbm.close `
362
+ methods .
362
363
363
- The optional *flag * argument can be:
364
+ :param filename:
365
+ The basename of the database file (without extensions).
366
+ A new database creates the following files:
364
367
365
- .. csv-table ::
366
- :header: "Value", "Meaning"
368
+ - :file: `{ filename } .dat `
369
+ - :file: `{ filename } .dir `
370
+ :type database: :term: `path-like object `
367
371
368
- ``'r' ``, |flag_r |
369
- ``'w' ``, |flag_w |
370
- ``'c' `` (default), |flag_c |
371
- ``'n' ``, |flag_n |
372
+ :param str flag:
373
+ .. csv-table ::
374
+ :header: "Value", "Meaning"
372
375
373
- The optional *mode * argument is the Unix mode of the file, used only when the
374
- database has to be created. It defaults to octal ``0o666 `` (and will be modified
375
- by the prevailing umask).
376
+ ``'r' ``, |flag_r |
377
+ ``'w' ``, |flag_w |
378
+ ``'c' `` (default), |flag_c |
379
+ ``'n' ``, |flag_n |
380
+
381
+ :param int mode:
382
+ The Unix file access mode of the file (default: ``0o666 ``),
383
+ used only when the database has to be created.
376
384
377
385
.. warning ::
378
386
It is possible to crash the Python interpreter when loading a database
379
387
with a sufficiently large/complex entry due to stack depth limitations in
380
388
Python's AST compiler.
381
389
382
390
.. versionchanged :: 3.5
383
- :func: `.open ` always creates a new database when the flag has the value
384
- ``'n' ``.
391
+ :func: `open ` always creates a new database when *flag * is ``'n' ``.
385
392
386
393
.. versionchanged :: 3.8
387
- A database opened with flags ``'r' `` is now read-only. Opening with
388
- flags ``'r' `` and ``'w' `` no longer creates a database if it does not
389
- exist.
394
+ A database opened read-only if *flag * is ``'r' ``.
395
+ A database is not created if it does not exist if *flag * is ``'r' `` or ``'w' ``.
390
396
391
397
.. versionchanged :: 3.11
392
- Accepts :term: `path-like object ` for filename .
398
+ * filename * accepts a :term: `path-like object `.
393
399
394
400
In addition to the methods provided by the
395
- :class: `collections.abc.MutableMapping ` class, :class: ` dumbdbm ` objects
396
- provide the following methods:
401
+ :class: `collections.abc.MutableMapping ` class,
402
+ the following methods are provided :
397
403
398
404
.. method :: dumbdbm.sync()
399
405
@@ -402,5 +408,5 @@ The module defines the following:
402
408
403
409
.. method :: dumbdbm.close()
404
410
405
- Close the `` dumbdbm `` database.
411
+ Close the database.
406
412
0 commit comments