@@ -127,26 +127,16 @@ will automatically close them when done.
127127Key and Value Types
128128-------------------
129129
130- The accepted types for keys and values vary by backend:
130+ The accepted types for keys and values vary by backend. Keys and values are
131+ handled identically:
131132
132- ** Keys: **
133+ * ** Traditional backends **:
133134
134- * **All backends **: Accept :class: `str ` and :class: `bytes ` objects
135- * **String keys ** are automatically converted to bytes using the default
136- encoding
137- * **Bytes keys ** are stored as-is
138-
139- **Values: **
140-
141- * **Traditional backends ** (``dbm.gnu ``, ``dbm.ndbm ``, ``dbm.dumb ``): Only
142- accept :class: `str ` and :class: `bytes ` objects
143- * **SQLite backend ** (``dbm.sqlite3 ``): Accepts any object that can be
144- converted to bytes:
145-
146- * **Accepted **: :class: `str `, :class: `bytes `, :class: `int `,
147- :class: `float `, :class: `bool `
148- * **Rejected **: :class: `None `, :class: `list `, :class: `dict `,
149- :class: `tuple `, custom objects
135+ * :mod: `dbm.gnu ` and :mod: `dbm.ndbm `: Accept :class: `str ` and :class: `bytes ` objects
136+ * :mod: `dbm.dumb `: Accepts :class: `str `, :class: `bytes `, and :class: `bytearray ` objects
137+ * **SQLite backend ** (:mod: `dbm.sqlite3 `): Accepts :class: `str `, :class: `bytes `,
138+ :class: `int `, :class: `float `, :class: `bool `, :class: `bytearray `,
139+ :class: `memoryview `, and :class: `array.array ` objects
150140
151141**Storage Format: **
152142
@@ -157,9 +147,13 @@ type stored.
157147**Type Conversion Examples: **
158148
159149* ``db['key'] = 'string' `` stored as ``b'string' ``
160- * ``db['key'] = 42 `` stored as ``b'42' `` (sqlite3 only)
161- * ``db['key'] = 3.14 `` stored as ``b'3.14' `` (sqlite3 only)
162- * ``db['key'] = True `` stored as ``b'True' `` (sqlite3 only)
150+ * ``db['key'] = bytearray(b'data') `` stored as ``b'data' `` (:mod: `dbm.dumb ` and :mod: `dbm.sqlite3 ` only)
151+ * ``db['key'] = 42 `` stored as ``b'42' `` (:mod: `dbm.sqlite3 ` only)
152+ * ``db['key'] = 3.14 `` stored as ``b'3.14' `` (:mod: `dbm.sqlite3 ` only)
153+ * ``db['key'] = True `` stored as ``b'1' `` (:mod: `dbm.sqlite3 ` only)
154+ * ``db['key'] = False `` stored as ``b'0' `` (:mod: `dbm.sqlite3 ` only)
155+ * ``db['key'] = memoryview(b'data') `` stored as ``b'data' `` (:mod: `dbm.sqlite3 ` only)
156+ * ``db['key'] = array.array('i', [1, 2, 3]) `` stored as binary data (:mod: `dbm.sqlite3 ` only)
163157* ``db['key'] = None `` fails on all backends
164158* ``db['key'] = [1, 2, 3] `` fails on all backends
165159
0 commit comments