Something went wrong. Try again.
a fork of EvalEx by ezylang with a handful of breaking changes
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344from collections.abc import Callablefrom typing import Any
import httpx
from cross.service import InputService, OutputServicefrom database.connection import DatabasePool
input_factories: dict[ str, Callable[[DatabasePool, httpx.Client, dict[str, Any]], InputService]] = {}output_factories: dict[ str, Callable[[DatabasePool, httpx.Client, dict[str, Any]], OutputService]] = {}
def create_input_service( db: DatabasePool, http: httpx.Client, data: dict[str, Any]) -> InputService: if "type" not in data: raise ValueError("No 'type' field in input data!") type: str = str(data["type"]) del data["type"]
factory = input_factories.get(type) if not factory: raise KeyError(f"No such input service {type}!") return factory(db, http, data)
def create_output_service( db: DatabasePool, http: httpx.Client, data: dict[str, Any]) -> OutputService: if "type" not in data: raise ValueError("No 'type' field in input data!") type: str = str(data["type"]) del data["type"]
factory = output_factories.get(type) if not factory: raise KeyError(f"No such output service {type}!") return factory(db, http, data)