ws.diff module

ws.diff.diff_highlighted(old, new, fromfile='', tofile='', fromfiledate='', tofiledate='')

Returns a diff between two texts formatted with ANSI color sequences suitable for output in 256-color terminal.

When available, the WikEdDiff library and its AnsiFormatter is used. Otherwise the difflib module from the standard library is used to generate the diff in unified format and pygments is used (when available) as the highlighter.

Parameters:
  • old – text to compare (old revision)
  • new – text to compare (new revision)
  • fromfile – original file name (used as meta data to format diff header)
  • tofile – new file name (used as meta data to format diff header)
  • fromfiledate – original file timestamp (used as meta data to format diff header)
  • tofiledate – new file timestamp (used as meta data to format diff header)
Returns:

diff formatted with ANSI color sequences

class ws.diff.RevisionDiffer(api)

Bases: object

Object for comparing revisions.

Parameters:api – a MediaWiki.api.API instance to operate on
diff(oldrevid, newrevid)

Method to get highlighted diff of two revisions. Uses ANSI color sequences for output in a 256-color terminal.

Basic meta data (title, username, timestamp and comment) is included in the diff header. Original unified diff format supports only file name and timestamp fields, we show more.

Parameters:
  • oldrevid – revision ID for old revision
  • newrevid – revision ID for new revision