summaryrefslogtreecommitdiffstats
path: root/Lib/dbm
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-02-05 20:47:31 (GMT)
committerGitHub <noreply@github.com>2018-02-05 20:47:31 (GMT)
commit6c85efa5a66d7b254aa22a39d47f36c040d7a04e (patch)
tree9f9c5f626364ac0b1a768a27a694c4ae0b4e6e6b /Lib/dbm
parentc309bcfb9fb295e70a235c461d9edcaa54c821d0 (diff)
downloadcpython-6c85efa5a66d7b254aa22a39d47f36c040d7a04e.zip
cpython-6c85efa5a66d7b254aa22a39d47f36c040d7a04e.tar.gz
cpython-6c85efa5a66d7b254aa22a39d47f36c040d7a04e.tar.bz2
bpo-32749: Make dbm.dumb databases more cosistent with other dbm databases. (#5497)
Diffstat (limited to 'Lib/dbm')
-rw-r--r--Lib/dbm/dumb.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index 5064668..e5c17f5 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -82,10 +82,7 @@ class _Database(collections.abc.MutableMapping):
f = _io.open(self._datfile, 'r', encoding="Latin-1")
except OSError:
if flag not in ('c', 'n'):
- import warnings
- warnings.warn("The database file is missing, the "
- "semantics of the 'c' flag will be used.",
- DeprecationWarning, stacklevel=4)
+ raise
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
self._chmod(self._datfile)
else:
@@ -93,18 +90,15 @@ class _Database(collections.abc.MutableMapping):
# Read directory file into the in-memory index dict.
def _update(self, flag):
+ self._modified = False
self._index = {}
try:
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
except OSError:
- self._modified = not self._readonly
if flag not in ('c', 'n'):
- import warnings
- warnings.warn("The index file is missing, the "
- "semantics of the 'c' flag will be used.",
- DeprecationWarning, stacklevel=4)
+ raise
+ self._modified = True
else:
- self._modified = False
with f:
for line in f:
line = line.rstrip()
@@ -191,9 +185,7 @@ class _Database(collections.abc.MutableMapping):
def __setitem__(self, key, val):
if self._readonly:
- import warnings
- warnings.warn('The database is opened for reading only',
- DeprecationWarning, stacklevel=2)
+ raise ValueError('The database is opened for reading only')
if isinstance(key, str):
key = key.encode('utf-8')
elif not isinstance(key, (bytes, bytearray)):
@@ -230,9 +222,7 @@ class _Database(collections.abc.MutableMapping):
def __delitem__(self, key):
if self._readonly:
- import warnings
- warnings.warn('The database is opened for reading only',
- DeprecationWarning, stacklevel=2)
+ raise ValueError('The database is opened for reading only')
if isinstance(key, str):
key = key.encode('utf-8')
self._verify_open()
@@ -323,7 +313,5 @@ def open(file, flag='c', mode=0o666):
# Turn off any bits that are set in the umask
mode = mode & (~um)
if flag not in ('r', 'w', 'c', 'n'):
- import warnings
- warnings.warn("Flag must be one of 'r', 'w', 'c', or 'n'",
- DeprecationWarning, stacklevel=2)
+ raise ValueError("Flag must be one of 'r', 'w', 'c', or 'n'")
return _Database(file, mode, flag=flag)