summaryrefslogtreecommitdiff
path: root/Lib/dbm/dumb.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-08-27 04:03:26 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-08-27 04:03:26 +0000
commitc87b0b55733a717d67b88e622fd250b2cb33baec (patch)
tree7b45f4cd812c6793c7e4f009acaa12114d6d9891 /Lib/dbm/dumb.py
parent1e57a267d3d6b0c901726fb81c63a2345c5b6910 (diff)
parent058e6a49c6e7b2847286eea5284a89b2757148d9 (diff)
downloadcpython-c87b0b55733a717d67b88e622fd250b2cb33baec.tar.gz
Issue #19884: Merge Readline updates from 3.5
Diffstat (limited to 'Lib/dbm/dumb.py')
-rw-r--r--Lib/dbm/dumb.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index 7777a7cae6..e7c6440ee6 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -47,6 +47,7 @@ class _Database(collections.MutableMapping):
def __init__(self, filebasename, mode, flag='c'):
self._mode = mode
+ self._readonly = (flag == 'r')
# The directory file is a text file. Each line looks like
# "%r, (%d, %d)\n" % (key, pos, siz)
@@ -80,6 +81,11 @@ class _Database(collections.MutableMapping):
try:
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)
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
self._chmod(self._datfile)
else:
@@ -178,6 +184,10 @@ class _Database(collections.MutableMapping):
f.write("%r, %r\n" % (key.decode("Latin-1"), pos_and_siz_pair))
def __setitem__(self, key, val):
+ if self._readonly:
+ import warnings
+ warnings.warn('The database is opened for reading only',
+ DeprecationWarning, stacklevel=2)
if isinstance(key, str):
key = key.encode('utf-8')
elif not isinstance(key, (bytes, bytearray)):
@@ -212,6 +222,10 @@ class _Database(collections.MutableMapping):
# (so that _commit() never gets called).
def __delitem__(self, key):
+ if self._readonly:
+ import warnings
+ warnings.warn('The database is opened for reading only',
+ DeprecationWarning, stacklevel=2)
if isinstance(key, str):
key = key.encode('utf-8')
self._verify_open()
@@ -300,4 +314,8 @@ def open(file, flag='c', mode=0o666):
else:
# 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)
return _Database(file, mode, flag=flag)