mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
250324952e
commit
94eceeb89c
4 changed files with 16 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue