Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
17fb5079
Commit
17fb5079
authored
Jun 14, 2003
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
parent
8316feb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
Lib/test/test_whichdb.py
Lib/test/test_whichdb.py
+5
-0
Lib/whichdb.py
Lib/whichdb.py
+7
-3
No files found.
Lib/test/test_whichdb.py
View file @
17fb5079
...
...
@@ -45,7 +45,12 @@ for name in anydbm._names:
def
test_whichdb_name
(
self
,
name
=
name
,
mod
=
mod
):
# Check whether whichdb correctly guesses module name
# for databases opened with module mod.
# Try with empty files first
f
=
mod
.
open
(
_fname
,
'c'
)
f
.
close
()
self
.
assertEqual
(
name
,
whichdb
.
whichdb
(
_fname
))
# Now add a key
f
=
mod
.
open
(
_fname
,
'w'
)
f
[
"1"
]
=
"1"
f
.
close
()
self
.
assertEqual
(
name
,
whichdb
.
whichdb
(
_fname
))
...
...
Lib/whichdb.py
View file @
17fb5079
...
...
@@ -50,15 +50,19 @@ def whichdb(filename):
# Check for dumbdbm next -- this has a .dir and and a .dat file
try
:
f
=
open
(
filename
+
os
.
extsep
+
"dat"
,
"rb"
)
f
.
close
()
# First check for presence of files
sizes
=
os
.
stat
(
filename
+
os
.
extsep
+
"dat"
).
st_size
,
\
os
.
stat
(
filename
+
os
.
extsep
+
"dir"
).
st_size
# dumbdbm files with no keys are empty
if
sizes
==
(
0
,
0
):
return
"dumbdbm"
f
=
open
(
filename
+
os
.
extsep
+
"dir"
,
"rb"
)
try
:
if
f
.
read
(
1
)
in
[
"'"
,
'"'
]:
return
"dumbdbm"
finally
:
f
.
close
()
except
IOError
:
except
(
OSError
,
IOError
)
:
pass
# See if the file exists, return None if not
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment