-
-
-class SDLWrapper:
- """
- This is a wrapper around the expected SDL Python interface.
- The usage of POLICY_DATA will be replaced with SDL when SDL for python is available.
- The eventual SDL API is expected to be very close to what is here.
-
- We use msgpack for binary (de)serialization: https://msgpack.org/index.html
- """
-
- def __init__(self):
- self.sdl = SyncStorage()
-
- def set(self, key, value):
- """set a key"""
- self.sdl.set(A1NS, {key: msgpack.packb(value, use_bin_type=True)})
-
- def get(self, key):
- """get a key"""
- ret_dict = self.sdl.get(A1NS, {key})
- if key in ret_dict:
- return msgpack.unpackb(ret_dict[key], raw=False)
-
- return None
-
- def find_and_get(self, prefix):
- """get all k v pairs that start with prefix"""
- ret_dict = self.sdl.find_and_get(A1NS, "{0}".format(prefix), atomic=True)
- found = {k: msgpack.unpackb(v, raw=False) for k, v in ret_dict.items()}
- # TODO: upgrade to sdl 2.0.0 which does the sorting for us
- return {k: found[k] for k in sorted(found)}
-
- def delete(self, key):
- """ delete a key"""
- self.sdl.remove(A1NS, {key})
-
-
-SDL = SDLWrapper()
-