Add an object model for DiffX files.

Review Request #11729 — Created July 17, 2021 and submitted

Information

DiffX
master

Reviewers

This introduces the DOM, the DiffX Object Model, which is a hierarchical
representation of DiffX files. It can be used to assemble a DiffX file
section-by-section, or to load in a DiffX file and process or manipulate
it.

There's an object for each type of section, organized into a tree. These
are divided into container and content sections, just as in the
specification.

To ease use, consumers really only have to deal with the container
sections (DiffX, DiffXChangeSection, and DiffXFileSection). The
content and options for each child content section is accessible via
forwarding attributes. For example, a DiffXChangeSection's preamble
text can be accessed directly through a preamble attribute, and the
preamble encoding can be accessed through preamble_encoding.

All attributes are type-safe, ensuring there are no problems when
writing a DiffX file. The classes are also limited in what attributes
can be set by defining __slots__, which helps to avoid accidentally
setting the wrong attribute name.

These objects manage data storage. All reading/writing is still done via
the underlying stream reader/writer, with specializations to convert
to-and-from the DOM.

It's expected that most users of the pydiffx module will use the DOM
implementaton, as it provides the easiest way of working with DiffX.
Future updates are planned to automatically calculate insert/line/file
statistics for metadata and to extract information from vendor-specific
Unified Diff variants.

Unit tests pass on Python 2 and 3.

Used this with an experimental diff parser for Review Board and diff
generator for RBTools.

Summary ID
Add an object model for DiffX files.
This introduces the DOM, the DiffX Object Model, which is a hierarchical representation of DiffX files. It can be used to assemble a DiffX file section-by-section, or to load in a DiffX file and process or manipulate it. There's an object for each type of section, organized into a tree. These are divided into container and content sections, just as in the specification. To ease use, consumers really only have to deal with the container sections (`DiffX`, `DiffXChangeSection`, and `DiffXFileSection`). The content and options for each child content section is accessible via forwarding attributes. For example, a `DiffXChangeSection`'s preamble text can be accessed directly through a `preamble` attribute, and the preamble encoding can be accessed through `preamble_encoding`. All attributes are type-safe, ensuring there are no problems when writing a DiffX file. The classes are also limited in what attributes can be set by defining `__slots__`, which helps to avoid accidentally setting the wrong attribute name. These objects manage data storage. All reading/writing is still done via the underlying stream reader/writer, with specializations to convert to-and-from the DOM. It's expected that most users of the `pydiffx` module will use the DOM implementaton, as it provides the easiest way of working with DiffX. Future updates are planned to automatically calculate insert/line/file statistics for metadata and to extract information from vendor-specific Unified Diff variants.
b4701d61ff6556b1d1f6d5020f51e930e7a008f4
Description From Last Updated

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

F401 'io' imported but unused

reviewbotreviewbot

F401 'pydiffx.errors.DiffXSectionOrderError' imported but unused

reviewbotreviewbot

F401 'pydiffx.errors.DiffXContentError' imported but unused

reviewbotreviewbot

F401 'pydiffx.reader.DiffXReader' imported but unused

reviewbotreviewbot

F401 'pydiffx.writer.DiffXWriter' imported but unused

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (4fabf93)
Loading...