[pybsddb] Please add this simple function

Yong Li codercoder at 10gic.net
Wed Apr 29 05:22:26 CEST 2009


Well, has_key is also not protected by transactions, right? So I don't
think it's worse off than using has_key. Maybe you can just make it
clear that __contains__ just acts as an alias for has_key so that it
acts more like a Python dict. Of course I defer judgments to you since
you know more about this than I do.

On Mon, Apr 27, 2009 at 1:21 PM, Jesus Cea <jcea at argo.es> wrote:
> -----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-----
> _______________________________________________
> pybsddb mailing list
> pybsddb at argo.es
> http://mailman.argo.es/listinfo/pybsddb
> http://www.argo.es/~jcea/programacion/pybsddb.htm
>



More information about the pybsddb mailing list