[Python-bugs-list] whichdb is coded wrong (PR#97)
alvin_nonaka@yahoo.com
alvin_nonaka@yahoo.com
Wed, 6 Oct 1999 08:41:21 -0400 (EDT)
Full_Name: Alvin Y. Nonaka
Version: 1.5.2
OS: Linux -- SuSE 6.2 distribution
Submission from: (NULL) (209.241.96.11)
I attempted to reproduce the exercise in Lutz's "Programming Python" book using
the anydbm module, pp. 39-41. After creating the underlying file, I re-open the
file using again anydbm and a simple program fails with
File "/user/lib/python1.5/anydbm.py, line 83, in open
raise error, "db type cannot be determined"
anydbm.error: db type cannot be determined
I created a series of simple test cases where <file> being one of dbhash, gdbm,
dbm, dumbdbm:
import <file>
file=<file>.open('test_<file>','c'>
file['Batman_<file>']='this is <file>'
file.close()
The file types and first four bytes are as follows:
test_dbhash 00 00 00 00
test_dbm.db 00 00 00 00
test_dumbdbm.dat 74 68 69 73 'this is dumbdbm'
test_dumbdbm.dir 27 42 61 74 'Batman_dumbdbm'
test_gdbm ce 9a 57 13
I used "hex editor" and "binary editor" from the kde interface under the
"utility" menu.
whichdb in pseudo-code:
file has file extension .pag and .dir => "dbm"
magic =1st 4 bytes of file
magic == 0x13579ace => "gdbm"
magic == 0x00061561 or magic == 0x61150600 => "dbhash"
return ""
My interpretation of the test cases tells me that the code should be:
.dat and .dir => "dumbdbm"
.db => "dbm"
magic == 0x00000000 => "dbhash"
magic == 0xce9a5713 => "gdbm"
return ""
It is no problem for me to code my own personal whichdb module that will work on
my machine but I don't understand why whichdb is coded the way it is. I might
grant different byte ordering for the "gdbm" case as I am running Linux on an
Intel platform using the SuSE 6.2 distribution. The command line python echoes:
Python 1.5.2 (#1, Jul 23, 19999, 06:38:16) [GCC egcs-2.91.66 19990314/Linux
(egcs -- on linux2
However, with test cases for "dbhash", "dbm" and "dumbdbm", I can't determine
why whichdb is coded the way it is.
Instead of staticly coding whichdb, which might fail for various
distribution/platform types, couldn't you create a generator that for the
various test cases above generate a "tailored" whichdb for that particular
distribution/platform?