@@ -58,41 +58,33 @@ the Oracle Berkeley DB.
58
58
59
59
.. function :: open(file, flag='r', mode=0o666)
60
60
61
- Open the database file * file * and return a corresponding object.
61
+ Open a database and return the corresponding database object.
62
62
63
- If the database file already exists, the :func: `whichdb ` function is used to
64
- determine its type and the appropriate module is used; if it does not exist,
65
- the first module listed above that can be imported is used.
63
+ :param file:
64
+ The database file to open.
66
65
67
- The optional *flag * argument can be:
66
+ If the database file already exists, the :func: `whichdb ` function is used to
67
+ determine its type and the appropriate module is used; if it does not exist,
68
+ the first submodule listed above that can be imported is used.
69
+ :type file: :term: `path-like object `
68
70
69
- .. csv-table ::
70
- :header: "Value", "Meaning"
71
+ :param str flag:
72
+ * ``'r' `` (default), |flag_r |
73
+ * ``'w' ``, |flag_w |
74
+ * ``'c' ``, |flag_c |
75
+ * ``'n' ``, |flag_n |
71
76
72
- ``'r' `` (default), |flag_r |
73
- ``'w' ``, |flag_w |
74
- ``'c' ``, |flag_c |
75
- ``'n' ``, |flag_n |
76
-
77
- The optional *mode * argument is the Unix mode of the file, used only when the
78
- database has to be created. It defaults to octal ``0o666 `` (and will be
79
- modified by the prevailing umask).
77
+ :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.
80
80
81
81
.. versionchanged :: 3.11
82
82
*file * accepts a :term: `path-like object `.
83
83
84
-
85
- The object returned by :func: `open ` supports the same basic functionality as a
84
+ The object returned by :func: `~dbm.open ` supports the same basic functionality as a
86
85
:class: `dict `; keys and their corresponding values can be stored, retrieved, and
87
86
deleted, and the :keyword: `in ` operator and the :meth: `!keys ` method are
88
- available, as well as :meth: `!get ` and :meth: `!setdefault `.
89
-
90
- .. versionchanged :: 3.2
91
- :meth: `!get ` and :meth: `!setdefault ` are now available in all database modules.
92
-
93
- .. versionchanged :: 3.8
94
- Deleting a key from a read-only database raises database module specific error
95
- instead of :exc: `KeyError `.
87
+ available, as well as :meth: `!get ` and :meth: `!setdefault ` methods.
96
88
97
89
Key and values are always stored as :class: `bytes `. This means that when
98
90
strings are used they are implicitly converted to the default encoding before
@@ -101,9 +93,17 @@ being stored.
101
93
These objects also support being used in a :keyword: `with ` statement, which
102
94
will automatically close them when done.
103
95
96
+ .. versionchanged :: 3.2
97
+ :meth: `!get ` and :meth: `!setdefault ` methods are now available for all
98
+ :mod: `dbm ` backends.
99
+
104
100
.. versionchanged :: 3.4
105
101
Added native support for the context management protocol to the objects
106
- returned by :func: `.open `.
102
+ returned by :func: `~dbm.open `.
103
+
104
+ .. versionchanged :: 3.8
105
+ Deleting a key from a read-only database raises a database module specific exception
106
+ instead of :exc: `KeyError `.
107
107
108
108
The following example records some hostnames and a corresponding title, and
109
109
then prints out the contents of the database::
0 commit comments