superdiff API

superdiff.Differ

class Differ(ignore_case=False, ignore_non_newline_whitespace=False, ignore_non_newline_whitespace_changes=False, ignore_newline_changes=False, ignore_blank_lines=False, ignore_leading_whitespace=False, ignore_trailing_whitespace=False)[source]

This class can be used to flexibly compare two pieces of text and return diff information in a variety of formats.

Definitions of common terms used:

  • non-newline whitespace: Tabs and spaces
  • newline: Any of the following line endings: \n, \r, or \r\n
  • whitespace: A combination of newlines and non-newline whitespace
  • empty line: A line consisting of only whitespace
Return type:None
__init__(ignore_case=False, ignore_non_newline_whitespace=False, ignore_non_newline_whitespace_changes=False, ignore_newline_changes=False, ignore_blank_lines=False, ignore_leading_whitespace=False, ignore_trailing_whitespace=False)[source]
Parameters:
  • ignore_case (bool) – Ignore case differences between the two texts.
  • ignore_non_newline_whitespace (bool) – Completely ignore differences in non-newline whitespace.
  • ignore_non_newline_whitespace_changes (bool) – Treat consecutive sequences of non-newline whitespace as equal. For example, when this option is True, a single space, two spaces, a tab character, and a mix of tabs and spaces will be considered equal.
  • ignore_newline_changes (bool) – Treat consecutive sequences of newline characters as equal. For example, when this option is True, \r, \r\r\n, and \n\n will all be considered equal.
  • ignore_blank_lines (bool) – Ignore lines consisting of only whitespace.
  • ignore_leading_whitespace (bool) – Ignore whitespace characters at the beginning of lines. Note that this will cause empty lines to be treated as the empty string.
  • ignore_trailing_whitespace (bool) – Ignore whitespace characters at the end of lines. Note that this will cause empty lines to be treated as the empty string.
Return type:

None

compare(first, second)[source]

Performs a line-by-line comparision of the strings first and second and returns a sequence of (tag, left, right) tuples specifying the differences between the strings.

tag can be any of the values of “tag” used in https://docs.python.org/3.5/library/difflib.html#difflib.SequenceMatcher.get_opcodes and have the same meanings.

If the two strings are equal, returns an empty iterable.

Return type:Iterable

superdiff.parser

class Line(tokens, settings)[source]

Bases: object

A line consists of a series of Tokens, with the final token being a NewlineToken.

Return type:None
original_text
transformed_text
class NewlineToken(regex_match, settings)[source]

Bases: superdiff.parser.Token

A NewlineNode stores one or more newline characters.

Return type:None
class Parser(ignore_case=False, ignore_non_newline_whitespace=False, ignore_non_newline_whitespace_changes=False, ignore_newline_changes=False, ignore_blank_lines=False, ignore_leading_whitespace=False, ignore_trailing_whitespace=False)[source]

Bases: object

class Settings(ignore_case=False, ignore_non_newline_whitespace=False, ignore_non_newline_whitespace_changes=False, ignore_newline_changes=False, ignore_blank_lines=False, ignore_leading_whitespace=False, ignore_trailing_whitespace=False)[source]

Bases: object

Parser.parse(text)[source]
Return type:Sequence
class Token(regex_match, settings)[source]

Bases: object

Return type:None
original_text
transformed_text
class WhitespaceToken(regex_match, settings)[source]

Bases: superdiff.parser.Token

An InlineWhitespaceNode stores one or more non-newline whitespace characters (i.e. tabs and spaces).

Return type:None
class WordToken(regex_match, settings)[source]

Bases: superdiff.parser.Token

A WordToken stores a string of non-whitespace characters.

Return type:None
token_factory(token_type, regex_match, parser_settings)[source]

Instantiates a token of the specified type.

Return type:Token