summaryrefslogtreecommitdiff
path: root/Lib/dbm
diff options
context:
space:
mode:
authorbriancurtin <brian.curtin@gmail.com>2011-03-14 15:35:35 -0400
committerbriancurtin <brian.curtin@gmail.com>2011-03-14 15:35:35 -0400
commit46514558f9373a5f0f8fca723963951f1bd8275e (patch)
treeb0120286c1042867b028b20ab611d128856e4475 /Lib/dbm
parente7a21706b4e7c5c8020858ca384e5f7270c7f171 (diff)
downloadcpython-46514558f9373a5f0f8fca723963951f1bd8275e.tar.gz
Fix #11491. When dbm.open was called with a file which already exists and
the "flag" argument is "n", dbm.error was being raised. As documented, dbm.open(...,flag='n') will now "Always create a new, empty database, open for reading and writing", regardless of a previous file existing.
Diffstat (limited to 'Lib/dbm')
-rw-r--r--Lib/dbm/__init__.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py
index c224847597..99c16379a9 100644
--- a/Lib/dbm/__init__.py
+++ b/Lib/dbm/__init__.py
@@ -68,10 +68,10 @@ def open(file, flag = 'r', mode = 0o666):
if not _defaultmod:
raise ImportError("no dbm clone found; tried %s" % _names)
- # guess the type of an existing database
- result = whichdb(file)
+ # guess the type of an existing database, if not creating a new one
+ result = whichdb(file) if 'n' not in flag else None
if result is None:
- # db doesn't exist
+ # db doesn't exist or 'n' flag was specified to create a new db
if 'c' in flag or 'n' in flag:
# file doesn't exist and the new flag was used so use default type
mod = _defaultmod