2019-09-26 10:42:15 +02:00
|
|
|
"""
|
|
|
|
src/storage/storage.py
|
|
|
|
======================
|
|
|
|
"""
|
2017-05-27 19:03:27 +02:00
|
|
|
import collections
|
|
|
|
|
|
|
|
InventoryItem = collections.namedtuple('InventoryItem', 'type stream payload expires tag')
|
|
|
|
|
2019-09-25 13:09:15 +02:00
|
|
|
|
2017-05-27 19:03:27 +02:00
|
|
|
class Storage(object):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Base class for storing inventory (extendable for other items to store)"""
|
2017-05-27 19:03:27 +02:00
|
|
|
pass
|
|
|
|
|
2019-09-25 13:09:15 +02:00
|
|
|
|
2017-05-27 19:03:27 +02:00
|
|
|
class InventoryStorage(Storage, collections.MutableMapping):
|
2019-09-26 10:42:15 +02:00
|
|
|
"""Module used for inventory storage"""
|
2017-05-27 19:03:27 +02:00
|
|
|
def __init__(self):
|
2019-09-26 10:42:15 +02:00
|
|
|
# pylint: disable=super-init-not-called
|
2017-05-27 19:03:27 +02:00
|
|
|
self.numberOfInventoryLookupsPerformed = 0
|
|
|
|
|
2019-09-26 10:42:15 +02:00
|
|
|
def __contains__(self, _):
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-09-26 10:42:15 +02:00
|
|
|
def __getitem__(self, _):
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-09-26 10:42:15 +02:00
|
|
|
def __setitem__(self, _, value):
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-09-26 10:42:15 +02:00
|
|
|
def __delitem__(self, _):
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2017-06-24 12:13:35 +02:00
|
|
|
def by_type_and_tag(self, objectType, tag):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Return objects filtered by object type and tag"""
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def unexpired_hashes_by_stream(self, stream):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Return unexpired inventory vectors filtered by stream"""
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def flush(self):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Flush cache"""
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def clean(self):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Free memory / perform garbage collection"""
|
2017-05-27 19:03:27 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-09-25 13:09:15 +02:00
|
|
|
|
2019-09-26 10:42:15 +02:00
|
|
|
class MailboxStorage(Storage, collections.MutableMapping): # pylint: disable=abstract-method
|
|
|
|
"""Method for storing mails"""
|
2017-05-27 19:03:27 +02:00
|
|
|
def __init__(self):
|
2019-09-26 10:42:15 +02:00
|
|
|
# pylint: disable=super-init-not-called
|
2017-05-27 19:03:27 +02:00
|
|
|
pass
|