[pybsddb] Please add this simple function

Jesus Cea jcea at argo.es
Mon Apr 27 22:21:45 CEST 2009


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

Yong Li wrote:
> Hi,
> 
> Please add a __contains__ to the DB object in pybsddb. Right now if you do
> 
> key in db
> 
> Python treats db as a iterable and iterates across the entire db
> because there is no __contains__ but there is an __iter__. Please add
> this to DB:
> 
> def __contains__(self, key):
>     return self.has_key(key)

The code is far more complicated, because we need to implement this in C.

This change will be available in pybsddb 4.7.6. But, beware, the
"__contains__()" call will be NOT protected by transactions.

I don't actually like this. Would you rather prefer to raise an
exception when doing "if key in DB:" to warning about the lack of
transaction isolation?. Recent versions of Berkeley DB has a
"DB.exists()" *transactional* function. I can implement something
similar for all supported BDB versions.

In my "to to" I just wrote:

"""
* 20090427: "__contains__()" is not transactionally protected. This is
  a problem. Maybe we should raise an exception to avoid the usage
  of patterns like "if key in DB", not transactionally protected.
  Think about this.

"""

- --
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

iQCVAwUBSfYT1plgi5GaxT1NAQJ1PwP+MKBjhtTYumBmzWkpC7mR1TdO/xFJMW9X
99ga0yYKdOEjP0lF+dsz/T4F2dfI/lbb7iF2Qr0gZZeTyAUqUJqCdthbuI3MAt/P
iSHlJa5MjnUFK5bABqmBi9HBo7Ctrd/62majPl1noPxBcmViC1+VfM6IHn7c/8Hm
ushyEQ6ODog=
=pMmG
-----END PGP SIGNATURE-----



More information about the pybsddb mailing list