"""Small display-text normalizers for model and persisted proposal content.""" from __future__ import annotations import re from typing import Any _LITERAL_UNICODE_ESCAPE = re.compile(r"(? Any: """Decode only literal ``\\uXXXX`` sequences accidentally returned as text. JSON parsing normally handles Unicode escapes. This is deliberately narrow so a user-entered path or other ordinary backslash content is not reinterpreted. """ if isinstance(value, str): return _LITERAL_UNICODE_ESCAPE.sub( lambda match: chr(int(match.group(1), 16)), value ) if isinstance(value, list): return [decode_literal_unicode_escapes(item) for item in value] if isinstance(value, dict): return {key: decode_literal_unicode_escapes(item) for key, item in value.items()} return value