Add a streaming writer for DiffX files.
Review Request #11713 — Created July 10, 2021 and submitted — Latest diff uploaded
This introduces
diffx.writer.DiffXWriter
, a streaming writer for the
DiffX file format. This is a low-level interface for writing DiffX
files to a stream (such as a local file, an in-progress HTTP response,
or a memory-backed stream) progressively, section-by-section, according
to the DiffX specification.It carefully ensures that sections are never generated in the wrong
order, using the same state tree used for parsing. It also validates
that values going into options.The writer tends to be thorough when it generates sections, opting to
explicitly provide information like the line ending types or the
metadata format, even when optional in DiffX files.It's up to the consumer to write the correct preambles, metadata, diff
content, and any options not otherwise handled by the writer. However,
the writer will take care to compute some things, like line ending
types, if not otherwise provided (though it's recommended that callers
still provide these if they know them).
DiffXWriter
should now be usable for production DiffX generation
(pending any new changes to the spec).
Unit tests pass on Python 2 and 3.