Byte report
byte_report
Byte-exact reporting on a payload already read from disk.
Pure, in-memory helpers: every function receives bytes or decoded text and returns a report. No file, network or process boundary is crossed here — the I/O belongs to the calling AXMTool.
The module implements lesson L4: an escape sequence present on disk is a run
of ASCII characters (chr(92) + "u00e9" is six characters), not a single
codepoint. Comparing the two requires looking at the bytes, never at a value
that Python already decoded.
MAX_OCCURRENCES = 50
module-attribute
Upper bound on every occurrence list carried by a report.
MISMATCH_WINDOW = 40
module-attribute
Characters kept on each side of the first divergence.
ByteReport
dataclass
Byte-exact verdict on a payload, with its supporting evidence.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
LiteralEscape
dataclass
An escape sequence present verbatim, as ASCII text, on disk.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
MismatchDetail
dataclass
Localised divergence between the expected and the actual content.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
NonAsciiOccurrence
dataclass
A single non-ASCII character located in the decoded text.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
build_hint(verdict)
build_report(data, expected=None, expect_escaped=None)
Build the byte-exact report for data.
data is hashed as-is, decoded strictly to determine encoding_ok,
then decoded tolerantly so a readable report can be produced even for
undecodable bytes. No exception escapes this function.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
compare_expected(expected, actual)
Return the first divergence between two texts, None if equal.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
decide_verdict(encoding_ok, mismatch, non_ascii_total, literal_escapes_total, expect_escaped=None)
Pick the verdict under a strict priority.
Decode error first, then divergence, then the escaping inconsistency, and
ok otherwise. Without an explicit expect_escaped contract no
escaping verdict is ever emitted.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
scan_literal_escapes(text, limit=MAX_OCCURRENCES)
Locate escape sequences written as plain ASCII text on disk.
Only the numeric forms are reported (\xNN, \uNNNN,
\UNNNNNNNN); each sequence is kept verbatim.
Source code in packages/axm-edit/src/axm_edit/core/byte_report.py
scan_non_ascii(text, limit=MAX_OCCURRENCES)
Locate non-ASCII characters, 1-based line/col, UTF-8 byte offset.
At most limit occurrences are returned; the offset counts UTF-8 bytes
from the start of the text, not characters.