mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Honor the mode argument to dumbdbm.open(); there is not good reason not to,
especially since the documentation described it in detail. This partially closes SF bug #490098.
This commit is contained in:
parent
301d0f89bb
commit
2c8373bc23
1 changed files with 7 additions and 6 deletions
|
@ -32,7 +32,8 @@ error = IOError # For anydbm
|
||||||
|
|
||||||
class _Database:
|
class _Database:
|
||||||
|
|
||||||
def __init__(self, file):
|
def __init__(self, file, mode):
|
||||||
|
self._mode = mode
|
||||||
self._dirfile = file + _os.extsep + 'dir'
|
self._dirfile = file + _os.extsep + 'dir'
|
||||||
self._datfile = file + _os.extsep + 'dat'
|
self._datfile = file + _os.extsep + 'dat'
|
||||||
self._bakfile = file + _os.extsep + 'bak'
|
self._bakfile = file + _os.extsep + 'bak'
|
||||||
|
@ -40,7 +41,7 @@ class _Database:
|
||||||
try:
|
try:
|
||||||
f = _open(self._datfile, 'r')
|
f = _open(self._datfile, 'r')
|
||||||
except IOError:
|
except IOError:
|
||||||
f = _open(self._datfile, 'w')
|
f = _open(self._datfile, 'w', self._mode)
|
||||||
f.close()
|
f.close()
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ class _Database:
|
||||||
except _os.error: pass
|
except _os.error: pass
|
||||||
try: _os.rename(self._dirfile, self._bakfile)
|
try: _os.rename(self._dirfile, self._bakfile)
|
||||||
except _os.error: pass
|
except _os.error: pass
|
||||||
f = _open(self._dirfile, 'w')
|
f = _open(self._dirfile, 'w', self._mode)
|
||||||
for key, (pos, siz) in self._index.items():
|
for key, (pos, siz) in self._index.items():
|
||||||
f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`))
|
f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`))
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -100,7 +101,7 @@ class _Database:
|
||||||
|
|
||||||
def _addkey(self, key, (pos, siz)):
|
def _addkey(self, key, (pos, siz)):
|
||||||
self._index[key] = (pos, siz)
|
self._index[key] = (pos, siz)
|
||||||
f = _open(self._dirfile, 'a')
|
f = _open(self._dirfile, 'a', self._mode)
|
||||||
f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`))
|
f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -146,6 +147,6 @@ class _Database:
|
||||||
self._datfile = self._dirfile = self._bakfile = None
|
self._datfile = self._dirfile = self._bakfile = None
|
||||||
|
|
||||||
|
|
||||||
def open(file, flag=None, mode=None):
|
def open(file, flag=None, mode=0666):
|
||||||
# flag, mode arguments are currently ignored
|
# flag, mode arguments are currently ignored
|
||||||
return _Database(file)
|
return _Database(file, mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue