"""Tiny client for the Buryans Tool Gateway.""" import json import urllib.parse import urllib.request BASE = "http://127.0.0.1:9137" def call(tool, params=None): url = BASE + "/v1/call?tool=" + urllib.parse.quote(tool) if params: url += "&" + urllib.parse.urlencode(params) with urllib.request.urlopen(url, timeout=25) as r: d = json.loads(r.read().decode()) body = d.get("body") if isinstance(body, str): try: return json.loads(body) except Exception: return {"raw": body} return body or {}