(s: str)
| 126 | return request |
| 127 | |
| 128 | |
| 129 | def _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 | |
| 136 | def _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 |
no outgoing calls
no test coverage detected