2016-12-09 07:41:07 +01:00
|
|
|
"""Store interface
|
|
|
|
|
|
|
|
Allows arbitrary classes to offer a simple get/set
|
|
|
|
store interface by deriving from the Store class in
|
|
|
|
this module
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Store(object):
|
2016-12-09 08:43:14 +01:00
|
|
|
"""Interface for storing and retrieving simple values"""
|
2016-12-09 07:41:07 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._data = {}
|
2019-12-25 13:40:02 +01:00
|
|
|
self._unused = {}
|
2016-12-09 07:41:07 +01:00
|
|
|
|
|
|
|
def set(self, key, value):
|
2016-12-09 08:43:14 +01:00
|
|
|
"""Set 'key' to 'value', overwriting 'key' if it exists already"""
|
2016-12-09 07:41:07 +01:00
|
|
|
self._data[key] = value
|
2019-12-25 13:40:02 +01:00
|
|
|
self._unused[key] = value
|
|
|
|
|
|
|
|
def unused_keys(self):
|
|
|
|
return self._unused.keys()
|
2016-12-09 07:41:07 +01:00
|
|
|
|
|
|
|
def get(self, key, default=None):
|
2016-12-09 08:43:14 +01:00
|
|
|
"""Return the current value of 'key', or 'default' if 'key' is not set"""
|
2019-12-25 13:40:02 +01:00
|
|
|
self._unused.pop(key, None)
|
2016-12-09 07:41:07 +01:00
|
|
|
return self._data.get(key, default)
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|