-
-
-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.POLICY_DATA = {}
-
- def set(self, key, value):
- """set a key"""
- self.POLICY_DATA[key] = msgpack.packb(value, use_bin_type=True)
-
- def get(self, key):
- """get a key"""
- if key in self.POLICY_DATA:
- return msgpack.unpackb(self.POLICY_DATA[key], raw=False)
- return None
-
- def find_and_get(self, prefix):
- """get all k v pairs that start with prefix"""
- return {k: msgpack.unpackb(v, raw=False) for k, v in self.POLICY_DATA.items() if k.startswith(prefix)}
-
- def delete(self, key):
- """ delete a key"""
- del self.POLICY_DATA[key]
-
-
-SDL = SDLWrapper()
-