Added spine-to-snake function for new plugin routes

This commit is contained in:
Joel Collins 2019-12-13 15:17:35 +00:00
parent 4eef909d13
commit 469e8218e0
2 changed files with 13 additions and 3 deletions

View file

@ -12,12 +12,14 @@ def deserialise_array_b64(b64_string, dtype, shape):
flat_arr = np.fromstring(base64.b64decode(b64_string), dtype)
return flat_arr.reshape(shape)
def serialise_array_b64(npy_arr):
b64_string = base64.b64encode(npy_arr).decode('ascii')
b64_string = base64.b64encode(npy_arr).decode("ascii")
dtype = str(npy_arr.dtype)
shape = npy_arr.shape
return b64_string, dtype, shape
def get_by_path(root, items):
"""Access a nested object in root by item sequence."""
return reduce(operator.getitem, items, root)
@ -69,6 +71,10 @@ def camel_to_spine(name):
return re.sub("([a-z0-9])([A-Z])", r"\1-\2", s1).lower()
def snake_to_spine(name):
return name.replace("_", "-")
@contextmanager
def set_properties(obj, **kwargs):
"""A context manager to set, then reset, certain properties of an object.