2022-07-09 12:26:53 +01:00
|
|
|
from typing import Iterator
|
|
|
|
|
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def cache_bool(func, param):
|
|
|
|
"""Check cache for a bool prop"""
|
|
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
self, *rem = args
|
2022-06-16 16:10:06 +01:00
|
|
|
cmd = f"{self.identifier}.{param}"
|
2022-04-29 02:57:47 +01:00
|
|
|
if cmd in self._remote.cache:
|
|
|
|
return self._remote.cache.pop(cmd) == 1
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
def cache_string(func, param):
|
|
|
|
"""Check cache for a string prop"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def wrapper(*args, **kwargs):
|
2022-04-29 02:57:47 +01:00
|
|
|
self, *rem = args
|
2022-06-16 16:10:06 +01:00
|
|
|
cmd = f"{self.identifier}.{param}"
|
2022-04-29 02:57:47 +01:00
|
|
|
if cmd in self._remote.cache:
|
|
|
|
return self._remote.cache.pop(cmd)
|
|
|
|
return func(*args, **kwargs)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
return wrapper
|
2022-04-27 14:50:48 +01:00
|
|
|
|
|
|
|
|
2022-04-29 21:53:44 +01:00
|
|
|
def depth(d):
|
|
|
|
if isinstance(d, dict):
|
|
|
|
return 1 + (max(map(depth, d.values())) if d else 0)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2022-04-27 14:50:48 +01:00
|
|
|
def script(func):
|
|
|
|
"""Convert dictionary to script"""
|
|
|
|
|
|
|
|
def wrapper(*args):
|
|
|
|
remote, script = args
|
|
|
|
if isinstance(script, dict):
|
|
|
|
params = ""
|
|
|
|
for key, val in script.items():
|
|
|
|
obj, m2, *rem = key.split("-")
|
|
|
|
index = int(m2) if m2.isnumeric() else int(*rem)
|
|
|
|
params += ";".join(
|
|
|
|
f"{obj}{f'.{m2}stream' if not m2.isnumeric() else ''}[{index}].{k}={int(v) if isinstance(v, bool) else v}"
|
|
|
|
for k, v in val.items()
|
|
|
|
)
|
|
|
|
params += ";"
|
|
|
|
script = params
|
|
|
|
return func(remote, script)
|
|
|
|
|
|
|
|
return wrapper
|
2022-07-09 12:26:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
def comp(t0: tuple, t1: tuple) -> Iterator[bool]:
|
|
|
|
"""
|
|
|
|
Generator function, accepts two tuples.
|
|
|
|
|
|
|
|
Evaluates equality of each member in both tuples.
|
|
|
|
"""
|
|
|
|
for a, b in zip(t0, t1):
|
|
|
|
if b <= 9500:
|
|
|
|
yield a == b
|
|
|
|
yield True
|