diff options
| author | mmoore <mmoore@anthropic.com> | 2026-09-25 12:17:32 -0700 |
|---|---|---|
| committer | mmoore <mmoore@anthropic.com> | 2026-09-25 12:17:32 -0700 |
| commit | 7de0de8eea27161166002620246a03ed68aed927 (patch) | |
| tree | 0f25456ef90b9bd55bd9ce836ef73e61d1c7825d /plugins/claude-security/scripts/lib/strictjson.py | |
| parent | ad30d62cd52ad0d0af1beda1eab7f61c601045d0 (diff) | |
Claude Security Plugin - v0.12.0claude-security-v0.12.0
Diffstat (limited to 'plugins/claude-security/scripts/lib/strictjson.py')
| -rw-r--r-- | plugins/claude-security/scripts/lib/strictjson.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/plugins/claude-security/scripts/lib/strictjson.py b/plugins/claude-security/scripts/lib/strictjson.py index 91d4ee30..b1b6f267 100644 --- a/plugins/claude-security/scripts/lib/strictjson.py +++ b/plugins/claude-security/scripts/lib/strictjson.py @@ -15,9 +15,11 @@ import re from collections.abc import Mapping from typing import TYPE_CHECKING, NoReturn, cast +# pyright: reportMissingModuleSource=false if TYPE_CHECKING: from pathlib import Path - from typing import TypeGuard + + from typing_extensions import TypeGuard JsonMap = Mapping[str, object] @@ -65,14 +67,18 @@ def _finite(digits: str) -> float: return value +def loads(document: str) -> object: + """The JSON value in `document`; ValueError if not strict JSON.""" + try: + return cast("object", json.loads(document, parse_constant=_refuse, parse_float=_finite)) + except RecursionError as error: + msg = "nested too deeply" + raise ValueError(msg) from error + + def load(path: Path) -> object: """The JSON value in `path`; OSError if unreadable, ValueError if not strict JSON.""" - with path.open(encoding="utf-8") as handle: - try: - return cast("object", json.load(handle, parse_constant=_refuse, parse_float=_finite)) - except RecursionError as error: - msg = "nested too deeply" - raise ValueError(msg) from error + return loads(path.read_text(encoding="utf-8")) def text(value: object, indent: int | None = None) -> str: |
