removed stultus out of the module it be a standalone
This commit is contained in:
parent
7517480cf9
commit
9129fabe03
@ -1,54 +0,0 @@
|
||||
from .custom import (
|
||||
EQUALS, GREATER, LESSER, GREATER_EQUAL,
|
||||
LESSER_EQUAL, NOT, AND, OR
|
||||
)
|
||||
|
||||
from .logic import (
|
||||
StultusMixin, StultusInt, StultusFloat,
|
||||
StultusStr, StultusBool, StultusList, StultusDict
|
||||
)
|
||||
|
||||
from .handler import ping, StultusUnavailable
|
||||
|
||||
from .math_ops import ADD, SUB, MUL, DIV, RANDINT, RANGE
|
||||
from .lists import LEN, LIST_INDEX, LIST_PUSH, LIST_POP
|
||||
from .dicts import DICT_GET
|
||||
from .strings import UPPER, INVERT
|
||||
from .truthy import TRUTH, BOOLIFY
|
||||
from .crypto import HASH_PASSWORD
|
||||
from .time_utils import TIME
|
||||
|
||||
__all__ = [
|
||||
# logic
|
||||
"EQUALS", "GREATER", "LESSER",
|
||||
"GREATER_EQUAL", "LESSER_EQUAL", "NOT",
|
||||
"AND", "OR",
|
||||
|
||||
# types
|
||||
"StultusMixin", "StultusInt", "StultusFloat",
|
||||
"StultusStr", "StultusBool", "StultusList", "StultusDict",
|
||||
|
||||
# base
|
||||
"ping", "StultusUnavailable",
|
||||
|
||||
# math
|
||||
"ADD", "SUB", "MUL", "DIV", "RANDINT", "RANGE",
|
||||
|
||||
# lists
|
||||
"LEN", "LIST_INDEX", "LIST_PUSH", "LIST_POP",
|
||||
|
||||
# dicts
|
||||
"DICT_GET",
|
||||
|
||||
# strings
|
||||
"UPPER", "INVERT",
|
||||
|
||||
# truthiness
|
||||
"TRUTH", "BOOLIFY",
|
||||
|
||||
# crypto
|
||||
"HASH_PASSWORD",
|
||||
|
||||
# time
|
||||
"TIME"
|
||||
]
|
||||
@ -1,5 +0,0 @@
|
||||
from .handler import _post
|
||||
|
||||
def HASH_PASSWORD(password: str, algo: str = "sha256"):
|
||||
result = _post("hash_password", {"password": password, "algo": algo})
|
||||
return result.get("hash")
|
||||
@ -1,54 +0,0 @@
|
||||
from .logic import (
|
||||
EQUALS, GREATER, LESSER, GREATER_EQUAL,
|
||||
LESSER_EQUAL, NOT, AND, OR
|
||||
)
|
||||
from .math_ops import ADD, SUB, MUL, DIV
|
||||
from .strings import UPPER, INVERT
|
||||
from .truthy import TRUTH
|
||||
from .lists import LIST_INDEX, LIST_PUSH, LIST_POP
|
||||
from .dicts import DICT_GET
|
||||
|
||||
# Core mixin for logic + math
|
||||
class StultusMixin:
|
||||
def __eq__(self, other): return EQUALS(self, other)
|
||||
def __ne__(self, other): return NOT(EQUALS(self, other))
|
||||
def __gt__(self, other): return GREATER(self, other)
|
||||
def __lt__(self, other): return LESSER(self, other)
|
||||
def __ge__(self, other): return GREATER_EQUAL(self, other)
|
||||
def __le__(self, other): return LESSER_EQUAL(self, other)
|
||||
def __and__(self, other): return AND(self, other)
|
||||
def __or__(self, other): return OR(self, other)
|
||||
def __bool__(self): return TRUTH(self)
|
||||
|
||||
# Math extensions
|
||||
class StultusInt(StultusMixin, int):
|
||||
def __add__(self, other): return ADD(self, other)
|
||||
def __sub__(self, other): return SUB(self, other)
|
||||
def __mul__(self, other): return MUL(self, other)
|
||||
def __truediv__(self, other): return DIV(self, other)
|
||||
|
||||
class StultusFloat(StultusMixin, float):
|
||||
def __add__(self, other): return ADD(self, other)
|
||||
def __sub__(self, other): return SUB(self, other)
|
||||
def __mul__(self, other): return MUL(self, other)
|
||||
def __truediv__(self, other): return DIV(self, other)
|
||||
|
||||
# String extensions
|
||||
class StultusStr(StultusMixin, str):
|
||||
def upper(self): return UPPER(self)
|
||||
def invert(self): return INVERT(self)
|
||||
def __getitem__(self, index): return LIST_INDEX(list(self), index)
|
||||
|
||||
# Bool wrapper
|
||||
class StultusBool(StultusMixin, bool):
|
||||
pass # already supports logic
|
||||
|
||||
# List wrapper
|
||||
class StultusList(StultusMixin, list):
|
||||
def push(self, item): return LIST_PUSH(self.copy(), item)
|
||||
def pop(self): return LIST_POP(self.copy())
|
||||
def __getitem__(self, index): return LIST_INDEX(self, index)
|
||||
|
||||
# Dict wrapper
|
||||
class StultusDict(StultusMixin, dict):
|
||||
def __getitem__(self, key): return DICT_GET(self, key)
|
||||
@ -1,3 +0,0 @@
|
||||
from .handler import _post
|
||||
|
||||
def DICT_GET(dct, key): return _post("dict_get", {"dict": dct, "key": key})
|
||||
@ -1,30 +0,0 @@
|
||||
import requests
|
||||
|
||||
BASE_URL = "https://stultus.chipperfluff.at"
|
||||
|
||||
class StultusUnavailable(Exception):
|
||||
pass
|
||||
|
||||
def _get(path: str, params: dict | list = None) -> any:
|
||||
try:
|
||||
r = requests.get(f"{BASE_URL}/{path}", params=params, timeout=5)
|
||||
r.raise_for_status()
|
||||
return r.json().get("result")
|
||||
except Exception as e:
|
||||
raise StultusUnavailable(f"[STULTUS] Failed GET {path}: {e}")
|
||||
|
||||
def _post(path: str, json: dict = None) -> any:
|
||||
try:
|
||||
r = requests.post(f"{BASE_URL}/{path}", json=json, timeout=5)
|
||||
r.raise_for_status()
|
||||
return r.json().get("result") or r.json()
|
||||
except Exception as e:
|
||||
raise StultusUnavailable(f"[STULTUS] Failed POST {path}: {e}")
|
||||
|
||||
def ping() -> bool:
|
||||
try:
|
||||
r = requests.get(f"{BASE_URL}/ping", timeout=2)
|
||||
return r.status_code == 200 and r.json().get("status") == "ok"
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
from .handler import _post
|
||||
|
||||
def LEN(value): return _post("len", {"value": value}).get("length")
|
||||
def LIST_INDEX(lst, index): return _post("list_index", {"list": lst, "index": index})
|
||||
def LIST_PUSH(lst, item): return _post("list_push", {"list": lst, "item": item})
|
||||
def LIST_POP(lst): return _post("list_pop", {"list": lst})
|
||||
@ -1,11 +0,0 @@
|
||||
from .handler import _get
|
||||
|
||||
def EQUALS(a, b): return _get("equals", {"a": a, "b": b})
|
||||
def GREATER(a, b): return _get("greater", {"a": a, "b": b})
|
||||
def LESSER(a, b): return _get("lesser", {"a": a, "b": b})
|
||||
def NOT(x): return _get("not", {"val": str(x).lower()})
|
||||
def AND(*args): return _get("and", [("val", str(v).lower()) for v in args])
|
||||
def OR(*args): return _get("or", [("val", str(v).lower()) for v in args])
|
||||
|
||||
def GREATER_EQUAL(a, b): return OR(GREATER(a, b), EQUALS(a, b))
|
||||
def LESSER_EQUAL(a, b): return OR(LESSER(a, b), EQUALS(a, b))
|
||||
@ -1,8 +0,0 @@
|
||||
from .handler import _get
|
||||
|
||||
def ADD(a, b): return _get("add", {"a": a, "b": b})
|
||||
def SUB(a, b): return _get("sub", {"a": a, "b": b})
|
||||
def MUL(a, b): return _get("mul", {"a": a, "b": b})
|
||||
def DIV(a, b): return _get("div", {"a": a, "b": b})
|
||||
def RANDINT(a, b): return _get("randint", {"a": a, "b": b})
|
||||
def RANGE(n, shuffle=False): return _get("range", {"n": n, "shuffle": str(shuffle).lower()})
|
||||
@ -1,4 +0,0 @@
|
||||
from .handler import _get
|
||||
|
||||
def UPPER(value: str): return _get("upper", {"value": value})
|
||||
def INVERT(value: str): return _get("invert_string", {"value": value})
|
||||
@ -1,5 +0,0 @@
|
||||
from .handler import _get
|
||||
|
||||
def TIME():
|
||||
data = _get("time")
|
||||
return data # epoch, iso, certainty
|
||||
@ -1,4 +0,0 @@
|
||||
from .handler import _post, _get
|
||||
|
||||
def TRUTH(value): return _post("truth", {"value": value}).get("truth")
|
||||
def BOOLIFY(value: str): return _get("boolify", {"value": value})
|
||||
Loading…
x
Reference in New Issue
Block a user