Files
pgames-manager/backend/app/converter/source.py
T

16 lines
555 B
Python

"""Decode source text without silently replacing characters in localisations."""
import io
from pathlib import Path
import tokenize
from app.converter.rpy_lexer import ParseError
def read_source(path: Path) -> str:
raw = path.read_bytes()
try:
encoding, _ = tokenize.detect_encoding(io.BytesIO(raw).readline)
return raw.decode(encoding)
except (UnicodeError, SyntaxError, LookupError) as exc:
raise ParseError(f"Не удалось прочитать кодировку сценария: {exc}", path.name) from exc