(instr: bytes, base_va: int)
| 70 | "na", |
| 71 | "todo", |
| 72 | "tbd", |
| 73 | "unknown", |
| 74 | "<unknown>", |
| 75 | "unnamed", |
| 76 | "anonymous", |
| 77 | "placeholder", |
| 78 | "undefined", |
| 79 | ] |
| 80 | ) |
| 81 | |
| 82 | EXACT_LOWERCASE_PLACEHOLDERS = frozenset(["none", "null", "nil"]) |
| 83 | |
| 84 | |
| 85 | class BackendUnavailable(Exception): |
| 86 | """The backend's tooling is not installed. Distinct from it failing.""" |
| 87 | |
| 88 | |
| 89 | class BackendFailed(Exception): |
| 90 | """The backend ran and could not produce a model.""" |
| 91 | |
| 92 | |
| 93 | def _is_placeholder(text: str) -> bool: |
| 94 | t = text.strip() |
| 95 | return t in EXACT_LOWERCASE_PLACEHOLDERS or t.lower() in CASE_INSENSITIVE_PLACEHOLDERS |
| 96 | |
| 97 | def _usable_value(text: str) -> bool: |
| 98 | return bool(text) and not _is_placeholder(text) |
| 99 | |
| 100 | |
| 101 | # -------------------------------------------------------------------------- |
| 102 | # protocol v1 |
| 103 | # -------------------------------------------------------------------------- |
| 104 | |
| 105 | |
| 106 | def _sha256(data: bytes) -> str: |
| 107 | return hashlib.sha256(data).hexdigest() |
| 108 | |
| 109 | |
| 110 | def _load_request(path: Path) -> dict: |
| 111 | try: |
| 112 | request = json.loads(path.read_text(encoding="utf-8")) |
| 113 | except (OSError, json.JSONDecodeError) as exc: |
| 114 | raise ValueError(f"request is not readable JSON: {exc}") from exc |
| 115 | if request.get("protocol_major") != PROTOCOL_MAJOR: |
| 116 | raise ValueError( |
no test coverage detected