[Python-bugs-list] [ python-Bugs-731501 ] Importing anydbm generates exception if _bsddb unavailable

SourceForge.net noreply@sourceforge.net
Mon, 05 May 2003 07:27:39 -0700


Bugs item #731501, was opened at 2003-05-02 12:56
Message generated for change (Comment added) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=731501&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Vargish (vargish)
Assigned to: Skip Montanaro (montanaro)
Summary: Importing anydbm generates exception if _bsddb unavailable

Initial Comment:
The anydbm module attempts to import the dbhash module,
which fails if there is no BSD DB module available.

Relevant portion of backtrace:

  File "/diska/netsite-docs/cgi-bin/waisdb2.py", line
124, in _getsystemsdbm
    dbsrc = anydbm.open(self.dbfile)
  File
"/usr/local/python-2.3b1/lib/python2.3/anydbm.py", line
82, in open
    mod = __import__(result)
  File
"/usr/local/python-2.3b1/lib/python2.3/dbhash.py", line
5, in ?
    import bsddb
  File
"/usr/local/python-2.3b1/lib/python2.3/bsddb/__init__.py",
line 40, in ?
    import _bsddb
ImportError: No module named _bsddb

Tests that explicitly use "import dbm" rather than
anydbm are successful on this system.


----------------------------------------------------------------------

>Comment By: Skip Montanaro (montanaro)
Date: 2003-05-05 09:27

Message:
Logged In: YES 
user_id=44345

I believe the attached patch does what's necessary to get this to work again.
It does a few things:
  * setup.py builds the bsddb185 under the right (restrictive) circumstances.
    /usr/include/db.h must exist and HASHVERSION must be 2.  In this case
    the bsddb185 module will be built without any extra includes, libraries
    or #defines, forcing whatever is present in /usr/include/db.h and libc to
    be used to build the module.

  * whichdb.py detects the older hash file format and returns "bsddb185".

  * bsddbmodule.c grows an extra undocumented attribute, "open".

The last two changes avoid having to change dbhash.py in complicated
ways to distinguish between new and old file versions.  The format-
detecting mess remains isolated to whichdb.py.

Using this setup I was successfully able to open /etc/pwd.db on my
system using anydbm.open(), which I was unable to do previously.  I can
also still open a more recent hash file created with anydbm.open.  Finally,
new files created with anydbm.open are in the later format.

Please give it a try.


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-05-03 04:02

Message:
Logged In: YES 
user_id=21627

I think this is not a bug. open() has determined that this
is a bsddb file, but bsddb is not supported on the system.

Or did you mean to suggest that opening the very same file
with dbm would be successful?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=731501&group_id=5470