summaryrefslogtreecommitdiffstats
path: root/Lib/dbm
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-07 09:02:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-07 09:02:18 (GMT)
commit43153e4d49100b46a603afa8deeca415eb18d180 (patch)
tree85fcb5017fe9ce2b58baa853868c7b7fedee587b /Lib/dbm
parentc29ba8b48962f59ffd5916731b35ac934f96304a (diff)
parent520348e5c0284668738e0ba98b86e7d1a5fd8600 (diff)
downloadcpython-43153e4d49100b46a603afa8deeca415eb18d180.zip
cpython-43153e4d49100b46a603afa8deeca415eb18d180.tar.gz
cpython-43153e4d49100b46a603afa8deeca415eb18d180.tar.bz2
Issue #28847: dbm.dumb now supports reading read-only files and no longer
writes the index file when it is not changed.
Diffstat (limited to 'Lib/dbm')
-rw-r--r--Lib/dbm/dumb.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index e7c6440..2296dbf 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -97,8 +97,9 @@ class _Database(collections.MutableMapping):
try:
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
except OSError:
- pass
+ self._modified = not self._readonly
else:
+ self._modified = False
with f:
for line in f:
line = line.rstrip()
@@ -113,7 +114,7 @@ class _Database(collections.MutableMapping):
# CAUTION: It's vital that _commit() succeed, and _commit() can
# be called from __del__(). Therefore we must never reference a
# global in this routine.
- if self._index is None:
+ if self._index is None or not self._modified:
return # nothing to do
try:
@@ -197,6 +198,7 @@ class _Database(collections.MutableMapping):
elif not isinstance(val, (bytes, bytearray)):
raise TypeError("values must be bytes or strings")
self._verify_open()
+ self._modified = True
if key not in self._index:
self._addkey(key, self._addval(val))
else:
@@ -229,6 +231,7 @@ class _Database(collections.MutableMapping):
if isinstance(key, str):
key = key.encode('utf-8')
self._verify_open()
+ self._modified = True
# The blocks used by the associated value are lost.
del self._index[key]
# XXX It's unclear why we do a _commit() here (the code always