File size: 528 Bytes
026f63e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | """Torch-free text helpers."""
from __future__ import annotations
import re
_HEX = re.compile(r"\b0x[0-9a-fA-F]+\b|\b[0-9a-f]{8,}\b")
_TS = re.compile(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:[.,]\d+)?Z?")
_NUM = re.compile(r"\b\d+(?:\.\d+)?\b")
def normalise_log(text: str, max_lines: int = 20) -> str:
lines = text.strip().splitlines()[-max_lines:]
out = []
for ln in lines:
ln = _TS.sub("<ts>", ln)
ln = _HEX.sub("<id>", ln)
out.append(_NUM.sub("<n>", ln))
return "\n".join(out)
|