-
-
-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"""
- # note: SDL "*" usage is inconsistent with real python regex, where it would be ".*"
- ret_dict = self.sdl.find_and_get(A1NS, "{0}*".format(prefix))
- return {k: msgpack.unpackb(v, raw=False) for k, v in ret_dict.items()}
-
- def delete(self, key):
- """ delete a key"""
- self.sdl.remove(A1NS, {key})
-
-
-SDL = SDLWrapper()
-