@@ -52,6 +52,10 @@ the Oracle Berkeley DB.
52
52
.. |flag_n | replace ::
53
53
Always create a new, empty database, open for reading and writing.
54
54
55
+ .. |mode_param_doc | replace ::
56
+ The Unix file access mode of the file (default: octal ``0o666``),
57
+ used only when the database has to be created.
58
+
55
59
.. |incompat_note | replace ::
56
60
The file formats created by :mod: `dbm.gnu` and :mod:`dbm.ndbm` are incompatible
57
61
and can not be used interchangeably.
@@ -69,14 +73,13 @@ the Oracle Berkeley DB.
69
73
:type file: :term: `path-like object `
70
74
71
75
:param str flag:
72
- * ``'r' `` (default), |flag_r |
73
- * ``'w' ``, |flag_w |
74
- * ``'c' ``, |flag_c |
75
- * ``'n' ``, |flag_n |
76
+ * ``'r' `` (default): |flag_r |
77
+ * ``'w' ``: |flag_w |
78
+ * ``'c' ``: |flag_c |
79
+ * ``'n' ``: |flag_n |
76
80
77
81
:param int mode:
78
- The Unix file access mode of the file (default: octal ``0o666 ``),
79
- used only when the database has to be created.
82
+ |mode_param_doc |
80
83
81
84
.. versionchanged :: 3.11
82
85
*file * accepts a :term: `path-like object `.
@@ -171,47 +174,45 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
171
174
172
175
.. function :: open(filename, flag="r", mode=0o666, /)
173
176
174
- Open a GDBM database and return a :class: `!gdbm ` object. The *filename *
175
- argument is the name of the database file.
176
-
177
- The optional *flag * argument can be:
177
+ Open a GDBM database and return a :class: `!gdbm ` object.
178
178
179
- .. csv-table ::
180
- :header: "Value", "Meaning"
179
+ :param filename:
180
+ The database file to open.
181
+ :type filename: :term: `path-like object `
181
182
182
- ``'r' `` (default), |flag_r |
183
- ``'w' ``, |flag_w |
184
- ``'c' ``, |flag_c |
185
- ``'n' ``, |flag_n |
183
+ :param str flag:
184
+ * ``'r' `` (default): |flag_r |
185
+ * ``'w' ``: |flag_w |
186
+ * ``'c' ``: |flag_c |
187
+ * ``'n' ``: |flag_n |
186
188
187
- The following additional characters may be appended to the flag to control
188
- how the database is opened:
189
+ The following additional characters may be appended
190
+ to control how the database is opened:
189
191
190
- +---------+--------------------------------------------+
191
- | Value | Meaning |
192
- +=========+============================================+
193
- | ``'f' `` | Open the database in fast mode. Writes |
194
- | | to the database will not be synchronized. |
195
- +---------+--------------------------------------------+
196
- | ``'s' `` | Synchronized mode. This will cause changes |
197
- | | to the database to be immediately written |
198
- | | to the file. |
199
- +---------+--------------------------------------------+
200
- | ``'u' `` | Do not lock database. |
201
- +---------+--------------------------------------------+
192
+ * ``'f' ``: Open the database in fast mode.
193
+ Writes to the database will not be synchronized.
194
+ * ``'s' ``: Synchronized mode.
195
+ Changes to the database will be written immediately to the file.
196
+ * ``'u' ``: Do not lock database.
202
197
203
- Not all flags are valid for all versions of GDBM. The module constant
204
- :const: `open_flags ` is a string of supported flag characters. The exception
205
- :exc: `error ` is raised if an invalid flag is specified.
198
+ Not all flags are valid for all versions of GDBM.
199
+ See the :data: `open_flags ` member for a list of supported flag characters.
206
200
207
- The optional * mode * argument is the Unix mode of the file, used only when the
208
- database has to be created. It defaults to octal `` 0o666 ``.
201
+ :param int mode:
202
+ | mode_param_doc |
209
203
210
- In addition to the dictionary-like methods, :class: ` gdbm ` objects have the
211
- following methods:
204
+ :raises error:
205
+ If an invalid * flag * argument is passed.
212
206
213
207
.. versionchanged :: 3.11
214
- Accepts :term: `path-like object ` for filename.
208
+ *filename * accepts a :term: `path-like object `.
209
+
210
+ .. data :: open_flags
211
+
212
+ A string of characters the *flag * parameter of :meth: `~dbm.gnu.open ` supports.
213
+
214
+ In addition to the dictionary-like methods, :class: `gdbm ` objects have the
215
+ following methods and attributes:
215
216
216
217
.. method :: gdbm.firstkey()
217
218
@@ -298,22 +299,20 @@ This module can be used with the "classic" NDBM interface or the
298
299
.. function :: open(filename, flag="r", mode=0o666, /)
299
300
300
301
Open an NDBM database and return an :class: `!ndbm ` object.
301
- The *filename * argument is the name of the database file
302
- (without the :file: `.dir ` or :file: `.pag ` extensions).
303
-
304
- The optional *flag * argument must be one of these values:
305
302
306
- .. csv-table ::
307
- :header: "Value", "Meaning"
303
+ :param filename:
304
+ The basename of the database file
305
+ (without the :file: `.dir ` or :file: `.pag ` extensions).
306
+ :type filename: :term: `path-like object `
308
307
309
- ``'r' `` (default), |flag_r |
310
- ``'w' ``, |flag_w |
311
- ``'c' ``, |flag_c |
312
- ``'n' ``, |flag_n |
308
+ :param str flag:
309
+ * ``'r' `` (default): |flag_r |
310
+ * ``'w' ``: |flag_w |
311
+ * ``'c' ``: |flag_c |
312
+ * ``'n' ``: |flag_n |
313
313
314
- The optional *mode * argument is the Unix mode of the file, used only when the
315
- database has to be created. It defaults to octal ``0o666 `` (and will be
316
- modified by the prevailing umask).
314
+ :param int mode:
315
+ |mode_param_doc |
317
316
318
317
In addition to the dictionary-like methods, :class: `!ndbm ` objects
319
318
provide the following method:
@@ -382,25 +381,21 @@ The :mod:`!dbm.dumb` module defines the following:
382
381
:type database: :term: `path-like object `
383
382
384
383
:param str flag:
385
- .. csv-table ::
386
- :header: "Value", "Meaning"
387
-
388
- ``'r' ``, |flag_r |
389
- ``'w' ``, |flag_w |
390
- ``'c' `` (default), |flag_c |
391
- ``'n' ``, |flag_n |
384
+ * ``'r' ``: |flag_r |
385
+ * ``'w' ``: |flag_w |
386
+ * ``'c' `` (default): |flag_c |
387
+ * ``'n' ``: |flag_n |
392
388
393
389
:param int mode:
394
- The Unix file access mode of the file (default: ``0o666 ``),
395
- used only when the database has to be created.
390
+ |mode_param_doc |
396
391
397
392
.. warning ::
398
393
It is possible to crash the Python interpreter when loading a database
399
394
with a sufficiently large/complex entry due to stack depth limitations in
400
395
Python's AST compiler.
401
396
402
397
.. versionchanged :: 3.5
403
- :func: `open ` always creates a new database when *flag * is ``'n' ``.
398
+ :func: `~dbm.dumb. open ` always creates a new database when *flag * is ``'n' ``.
404
399
405
400
.. versionchanged :: 3.8
406
401
A database opened read-only if *flag * is ``'r' ``.
0 commit comments