[Python-3000] Strange code in bsddb that doesn't work in Python 3.0

Jesus Cea jcea at jcea.es
Mon Jul 21 17:00:27 CEST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Trying to find why I can't import bsddb in python3.0, I have found that
this code fails:

"""
~    /* Some magic to make DBNotFoundError and DBKeyEmptyError derive
~     * from both DBError and KeyError, since the API only supports
~     * using one base class. */
~    PyDict_SetItemString(d, "KeyError", PyExc_KeyError);
~    PyRun_String("class DBNotFoundError(DBError, KeyError): pass\n"
~                 "class DBKeyEmptyError(DBError, KeyError): pass",
~                 Py_file_input, d, d);
~    DBNotFoundError = PyDict_GetItemString(d, "DBNotFoundError");
~    DBKeyEmptyError = PyDict_GetItemString(d, "DBKeyEmptyError");
~    PyDict_DelItemString(d, "KeyError");
"""

"Some magic" comment is a bit scary :-), although the code seems fairly
obvious.

This code works in Python 2.x, but fails in 3.0.

The line that fails is "PyRun_String()". The error is: "ImportError:
__build_class__ not found".

:-?

Ideas welcomed!

The code should work in python2.[3-6] and python3.0. Conditional
compilation can be used.

PS: Googling around, I see that Python 2.5 allows a tuple being used as
base for exception creation.  Is this available in Python3.0?. Searching
for "PyErr_NewException" in 3.0 documentation online shows no results.

Ok, the index show the function. It should work.

I'm still interested in knowing WHY the original code fails.

- --
Jesus Cea Avion                         _/_/      _/_/_/        _/_/_/
jcea at jcea.es - http://www.jcea.es/     _/_/    _/_/  _/_/    _/_/  _/_/
jabber / xmpp:jcea at jabber.org         _/_/    _/_/          _/_/_/_/_/
.                              _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSISkhplgi5GaxT1NAQIyMQP/R2GmrLsMT+AKaM2toJtJQqrWDF8EzmAa
gqaW+vvi8fivYGXWm4IzHOzNCSW48N/5rMHQQREkHliRQxVypukYU48VSr4lRfAC
3m8EnS/dVgyP2GN19mm50xa+gWK9OpAopN6GLwDXlG2pxiHCMLmfI+PusQdGsIsU
kHhkWRUkwwo=
=ofiW
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list