MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / safe_console_text

Function safe_console_text

agents/master-coordinator/main.py:908–915  ·  view source on GitHub ↗

Return a console-safe preview that will not crash on Windows GBK terminals.

(text: Any, max_len: int = 120)

Source from the content-addressed store, hash-verified

906
907
908def safe_console_text(text: Any, max_len: int = 120) -> str:
909 """Return a console-safe preview that will not crash on Windows GBK terminals."""
910 preview = str(text).replace("\r", "").replace("\n", "\\n")[:max_len]
911 encoding = getattr(sys.stdout, "encoding", None) or "utf-8"
912 try:
913 return preview.encode(encoding, errors="replace").decode(encoding, errors="replace")
914 except Exception:
915 return preview.encode("ascii", errors="replace").decode("ascii")
916
917
918PROFILE_WEIGHT_COMMAND_RE = re.compile(

Callers 1

processMethod · 0.85

Calls 2

decodeMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected