Source code for smax.smax_client

import datetime
from abc import ABC, abstractmethod
import numpy as np


from .smax_data_types import SmaxData, \
    SmaxInt, SmaxFloat, SmaxBool, SmaxStr, SmaxStrArray, SmaxArray, SmaxStruct, \
    SmaxInt8, SmaxInt16, SmaxInt32, SmaxInt64, SmaxFloat32, SmaxFloat64, \
    _TYPE_MAP, _REVERSE_TYPE_MAP, _SMAX_TYPE_MAP, _REVERSE_SMAX_TYPE_MAP, \
    optional_metadata

# The separator used in key names
smax_sep = ':'
    
[docs] class SmaxConnectionError(RuntimeError): pass
[docs] class SmaxKeyError(RuntimeError): pass
[docs] class SmaxUnderflowWarning(RuntimeWarning): pass
[docs] class SmaxClient(ABC): def __init__(self, *args, **kwargs): # All child classes will call their smax_connect_to() when constructed. self._client = self.smax_connect_to(*args, **kwargs) def __enter__(self, *args, **kwargs): return self def __exit__(self, *args, **kwargs): return self.smax_disconnect()
[docs] @abstractmethod def smax_connect_to(self, *args, **kwargs): pass
[docs] @abstractmethod def smax_disconnect(self): pass
[docs] @abstractmethod def smax_pull(self, table, key): pass
[docs] @abstractmethod def smax_share(self, table, key, value): pass
[docs] @abstractmethod def smax_subscribe(self, pattern): pass
[docs] @abstractmethod def smax_unsubscribe(self, pattern): pass
[docs] @abstractmethod def smax_wait_on_subscribed(self, pattern): pass
[docs] @abstractmethod def smax_wait_on_any_subscribed(self): pass
[docs] @abstractmethod def smax_set_description(self, table, description): pass
[docs] @abstractmethod def smax_get_description(self, table): pass
[docs] @abstractmethod def smax_set_units(self, table, unit): pass
[docs] @abstractmethod def smax_get_units(self, table): pass
[docs] @abstractmethod def smax_set_coordinate_system(self, table, coordinate_system): pass
[docs] @abstractmethod def smax_get_coordinate_system(self, table): pass
[docs] @abstractmethod def smax_create_coordinate_system(self, n_axis): pass
[docs] @abstractmethod def smax_push_meta(self, meta, table, value): pass
[docs] @abstractmethod def smax_pull_meta(self, table, meta): pass
[docs] def join(*args): """Join SMA-X tables and keys. We use this method to avoid the TypeErrors from string.join() params: *args : SMA-X key elements to join """ if len(args) == 1: if args[0].startswith(smax_sep): args[0] = args[0][1:] return str(args[0]) elif len(args) == 0: return None else: out = "" for a in args: if a is None or a == '': pass else: if type(a) is not str: a = str(a) if a.startswith(smax_sep): a = a[1:] out += f'{a}{smax_sep}' return out[:-1]
[docs] def normalize_pair(*args): """Return a SMA-X table, key pair with exactly one level in the key params: *args : SMA-X key elements to join and split """ full_key = join(*args) table_key = full_key.rsplit(":", maxsplit=1) if len(table_key) == 1: table_key = ["", table_key[0]] return table_key