any2human / app /engine /ingest /__init__.py
idnameraj's picture
Upload 142 files
8f6d79d verified
Raw
History Blame Contribute Delete
607 Bytes
"""Document ingest — raw text / bytes → UTF-8 string."""
from __future__ import annotations
def ingest_text(source: str | bytes | None, *, encoding: str = "utf-8") -> str:
"""Normalize input into a UTF-8 Unicode string."""
if source is None:
return ""
if isinstance(source, bytes):
for enc in (encoding, "utf-8", "utf-8-sig", "latin-1"):
try:
return source.decode(enc)
except (UnicodeDecodeError, LookupError):
continue
return source.decode("utf-8", errors="replace")
return str(source)