MCPcopy Create free account
hub / github.com/caverav/flutterdec / _selector_from_string

Function _selector_from_string

adapters/python/adapter_template.py:128–151  ·  view source on GitHub ↗
(s: str)

Source from the content-addressed store, hash-verified

126 return request
127
128
129def _handle(request: dict, region: str) -> dict:
130 for handle in request["inputs"]:
131 if handle.get("region") == region:
132 return handle
133 raise ValueError(f"request omits input region {region}")
134
135
136def _read_region(request: dict, region: str) -> bytes:
137 handle = _handle(request, region)
138 path = Path(handle["path"])
139 try:
140 data = path.read_bytes()
141 except OSError as exc:
142 raise FileNotFoundError(f"input {region} is not readable: {exc}") from exc
143 # The digest is the point of the handle: without it "the adapter read the
144 # snapshot" only means "the adapter read a file".
145 if len(data) != handle["size"]:
146 raise ValueError(
147 f"input {region} is {len(data)} bytes, request declared {handle['size']}"
148 )
149 actual = _sha256(data)
150 if actual != handle["sha256"]:
151 raise ValueError(
152 f"input {region} digest {actual} does not match declared {handle['sha256']}"
153 )
154 return data

Callers 4

_pool_entriesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected