Reference client for Bitmessage: a P2P encrypted decentralised communication protocol:
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

"""The Inventory singleton"""
# TODO make this dynamic, and watch out for frozen, like with messagetypes
import storage.filesystem
import storage.sqlite
from bmconfigparser import BMConfigParser
from singleton import Singleton
class Inventory():
Inventory singleton class which uses storage backends
to manage the inventory.
def __init__(self):
self._moduleName = BMConfigParser().safeGet("inventory", "storage")
self._inventoryClass = getattr(
getattr(storage, self._moduleName),
self._realInventory = self._inventoryClass()
self.numberOfInventoryLookupsPerformed = 0
# cheap inheritance copied from asyncore
def __getattr__(self, attr):
if attr == "__contains__":
self.numberOfInventoryLookupsPerformed += 1
realRet = getattr(self._realInventory, attr)
except AttributeError:
raise AttributeError(
"%s instance has no attribute '%s'" %
(self.__class__.__name__, attr)
return realRet
# hint for pylint: this is dictionary like object
def __getitem__(self, key):
return self._realInventory[key]