beeseek-devs team mailing list archive
-
beeseek-devs team
-
Mailing list archive
-
Message #00131
[Branch ~beeseek-devs/beeseek/trunk] Rev 210: Add a __contains__ method for databases.
------------------------------------------------------------
revno: 210
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2009-02-08 13:32:01 +0100
message:
Add a __contains__ method for databases.
Developers can now check if a key is present in a database with a fast
and safe way using a code like 'key in database'.
modified:
beeseek/database/base.py
beeseek/database/nested.py
------------------------------------------------------------
revno: 208.1.18
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: database-__contains__
timestamp: Sat 2009-02-07 14:09:42 +0100
message:
Add __contains__ for nested databases.
modified:
beeseek/database/nested.py
------------------------------------------------------------
revno: 208.1.17
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: database-__contains__
timestamp: Sat 2009-02-07 14:07:58 +0100
message:
Add __contains__ for FileDatabase class.
modified:
beeseek/database/base.py
------------------------------------------------------------
revno: 208.1.16
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: database-__contains__
timestamp: Sat 2009-02-07 14:05:59 +0100
message:
Update interface.
modified:
beeseek/database/base.py
=== modified file 'beeseek/database/base.py'
--- beeseek/database/base.py 2009-02-06 17:47:23 +0000
+++ beeseek/database/base.py 2009-02-07 13:07:58 +0000
@@ -32,6 +32,9 @@
def __getitem__(self, name):
"""Return the specified item."""
+ def __contains__(self, name):
+ """Return true if the database has the given key."""
+
def __setitem__(self, name, value):
"""Store the item."""
@@ -124,6 +127,13 @@
finally:
self._lock.release()
+ def __contains__(self, name):
+ self._lock.acquire()
+ try:
+ return bool(self._get_reference(name))
+ finally:
+ self._lock.release()
+
def _find_reference(self, key):
index_file = self._index
index_file.seek(self._start)
=== modified file 'beeseek/database/nested.py'
--- beeseek/database/nested.py 2009-02-05 17:19:24 +0000
+++ beeseek/database/nested.py 2009-02-07 13:09:42 +0000
@@ -66,6 +66,13 @@
finally:
self._lock.release()
+ def __contains__(self, name):
+ self._lock.acquire()
+ try:
+ return name in self._get_file(name)
+ finally:
+ self._lock.release()
+
def __setitem__(self, name, values):
self._lock.acquire()
try:
--
BeeSeek mainline
https://code.launchpad.net/~beeseek-devs/beeseek/trunk
Your team BeeSeek Developers is subscribed to branch lp:beeseek.
To unsubscribe from this branch go to https://code.launchpad.net/~beeseek-devs/beeseek/trunk/+edit-subscription.