pyx12¶
Validation with pyx12. Needs pip install "oxedi[pyx12]". See
Validating with pyx12 for the guide.
validate ¶
validate(source: Source) -> list[Diagnostic]
Validates an 835 file with pyx12 and returns what it finds.
source is the file's bytes, a path, or a file object open in binary
mode. pyx12 picks its map from the file's own version declaration.
pyx12's own defaults apply: extended character set (charset="E"),
no external code lists excluded (exclude_external_codes=None),
and user/system configuration files (~/.pyx12.conf.xml,
<prefix>/etc/pyx12.conf.xml) are not read, so findings do not
depend on the machine.
Every error pyx12's engine records is returned: interchange, group and
transaction errors, segment errors and element errors, including those
of the envelope segments. They are read from the error tree pyx12
builds; pyx12's logging is not used. The pyx12 logger gets a
logging.NullHandler the first time, when it has none, so pyx12's
records are not printed by default and still reach the handlers the
caller configures; levels, propagation and logging.disable stay as
the caller set them.
Each finding is an oxedi.Diagnostic, the type parse
returns, so both lists mix, sort by level and filter by origin.
A pyx12 finding has kind == "External", origin == "pyx12" and
code set to pyx12's own error code; rule is pyx12's message.
level follows where pyx12 reports it: interchange, group and
transaction findings are level 1, segment and element findings level 2.
segment is the index of the segment at fault in the file's document
(None when pyx12 names none), and document[d.segment].span gives
its byte range. An interchange, group or transaction finding about a
trailer (a count or a control number that does not match) lands on the
trailer segment at the element holding that value; one about a
duplicate or missing control structure lands on the header, at its
control number when that is the offending value. datum is the value
pyx12 reports, or else the bytes of the element in the file, or the
segment id for a finding with no element. Findings come in
segment order. path names the loops open at that segment, as in the
diagnostics parse gives about the same segment.
A file pyx12 cannot read, or an exception inside pyx12, gives one
level 1 finding with no code whose rule starts with could
not finish validating, instead of raising: a file pyx12 rejects
points at the segment holding the ISA with its bytes as the datum; a
failure while reading names the segment pyx12 was processing, and one
after the last segment names the last segment it completed. A file
with no ISA to read the delimiters from raises oxedi.ParseError,
as oxedi.parse does. Nothing is written to disk and no
acknowledgement is generated.