MCPcopy
hub / github.com/ComposioHQ/composio / _try_resolve_pointer

Function _try_resolve_pointer

python/composio/utils/json_schema.py:80–108  ·  view source on GitHub ↗

Walk a local JSON Pointer (``#/a/b/0``) against ``root``. Returns a tagged result so the caller can distinguish a malformed pointer from a structurally valid pointer whose target is absent.

(root: t.Dict[str, t.Any], pointer: str)

Source from the content-addressed store, hash-verified

78
79
80def _try_resolve_pointer(root: t.Dict[str, t.Any], pointer: str) -> _Resolution:
81 """Walk a local JSON Pointer (``#/a/b/0``) against ``root``.
82
83 Returns a tagged result so the caller can distinguish a malformed pointer
84 from a structurally valid pointer whose target is absent.
85 """
86 if pointer in ("#", ""):
87 return _Resolution(ok=True, value=root)
88 if not pointer.startswith("#/"):
89 return _Resolution(ok=False, reason="malformed-pointer")
90
91 cursor: t.Any = root
92 for raw_segment in pointer[2:].split("/"):
93 segment = _decode_pointer_segment(raw_segment)
94 if isinstance(cursor, list):
95 try:
96 index = int(segment)
97 except ValueError:
98 return _Resolution(ok=False, reason="missing-target", failed_at=segment)
99 if index < 0 or index >= len(cursor):
100 return _Resolution(ok=False, reason="missing-target", failed_at=segment)
101 cursor = cursor[index]
102 elif isinstance(cursor, dict):
103 if segment not in cursor:
104 return _Resolution(ok=False, reason="missing-target", failed_at=segment)
105 cursor = cursor[segment]
106 else:
107 return _Resolution(ok=False, reason="missing-target", failed_at=segment)
108 return _Resolution(ok=True, value=cursor)
109
110
111def _raise_resolution_error(pointer: str, resolution: _Resolution) -> t.NoReturn:

Callers 1

walkFunction · 0.85

Calls 2

_ResolutionClass · 0.85
_decode_pointer_segmentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…