diff options
| author | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
| commit | 7aba3deae3ff17d032c37e07d2929d1426b34278 (patch) | |
| tree | 9c482f9acda1599bd2f9bed95a6a46b75e634e80 /plugins/claude-security/scripts/lib/strictjson.py | |
| parent | 5472f5f56e0070feeeb464318b316714fe3e9105 (diff) | |
| parent | b8331dd69ab3e132bbf8cd6e89b5d8c1747e21b1 (diff) | |
Merge remote-tracking branch 'origin/main' into add-plugin/xcodeadd-plugin/xcode
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: |
