2019-09-26 10:42:15 +02:00
|
|
|
"""
|
2019-12-24 13:53:48 +01:00
|
|
|
Storing inventory items
|
2019-09-26 10:42:15 +02:00
|
|
|
"""
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
from abc import ABCMeta, abstractmethod
|
2022-09-20 22:50:28 +02:00
|
|
|
from collections import namedtuple
|
|
|
|
try:
|
|
|
|
from collections import MutableMapping # pylint: disable=deprecated-class
|
|
|
|
except ImportError:
|
|
|
|
from collections.abc import MutableMapping
|
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
import six
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2019-09-25 13:09:15 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag')
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2019-09-25 13:09:15 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
class InventoryStorage(MutableMapping):
|
|
|
|
"""
|
|
|
|
Base class for storing inventory
|
|
|
|
(extendable for other items to store)
|
|
|
|
"""
|
2019-12-24 13:53:48 +01:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
def __init__(self):
|
2017-05-27 19:03:27 +02:00
|
|
|
self.numberOfInventoryLookupsPerformed = 0
|
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@abstractmethod
|
|
|
|
def __contains__(self, item):
|
|
|
|
pass
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@abstractmethod
|
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"""
|
2022-09-21 00:02:36 +02:00
|
|
|
pass
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@abstractmethod
|
2017-05-27 19:03:27 +02:00
|
|
|
def unexpired_hashes_by_stream(self, stream):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Return unexpired inventory vectors filtered by stream"""
|
2022-09-21 00:02:36 +02:00
|
|
|
pass
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@abstractmethod
|
2017-05-27 19:03:27 +02:00
|
|
|
def flush(self):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Flush cache"""
|
2022-09-21 00:02:36 +02:00
|
|
|
pass
|
2017-05-27 19:03:27 +02:00
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@abstractmethod
|
2017-05-27 19:03:27 +02:00
|
|
|
def clean(self):
|
2019-09-24 11:20:20 +02:00
|
|
|
"""Free memory / perform garbage collection"""
|
2022-09-21 00:02:36 +02:00
|
|
|
pass
|
2019-12-24 13:53:48 +01:00
|
|
|
|
|
|
|
|
2022-09-21 00:02:36 +02:00
|
|
|
@six.add_metaclass(ABCMeta)
|
|
|
|
class MailboxStorage(MutableMapping):
|
|
|
|
"""An abstract class for storing mails. TODO"""
|
|
|
|
pass
|