Connection
Base URL, credentials and a reachable server.
Keep escaped object-key fixtures next to the lookup code and trace each decoded segment before it chooses a dictionary member or list index.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
import re
def pointer_get(root, pointer):
if not isinstance(pointer, str): raise ValueError("pointer text")
if pointer == "": return root
if not pointer.startswith("/"): raise ValueError("root slash")
value = root
for raw in pointer[1:].split("/"):
if re.search(r"~(?![01])", raw): raise ValueError("escape")
key = raw.replace("~1", "/").replace("~0", "~")
if isinstance(value, dict): value = value[key]
elif isinstance(value, list):
if not re.fullmatch(r"0|[1-9][0-9]*", key):
raise ValueError("array index")
if len(key) > len(str(len(value))): raise IndexError(key)
value = value[int(key)]
else: raise ValueError("not a container")
return value