The URIFormatter class

class ferenda.URIFormatter(*formatters)[source]

Companion class to ferenda.CitationParser, that handles the work of formatting the dicts or dict-like objects that CitationParser creates.

The class is initialized with a list of formatters, where each formatter is a tuple (key, callable). When format() is passed a citation reference in the form of a pyparsing.ParseResult object (which has a .getName method), the name of that reference is matched against the key of all formatters. If there is a match, the corresponding callable is called with the parseresult object as a single parameter, and the resulting string is returned.

An initialized URIFormatter object is not used directly. Instead, call ferenda.CitationParser.set_formatter() with the object as parameter. See Citation parsing.

Parameters:*formatters (list) – Formatters, each provided as a (name, callable) tuple.
format(parseresult)[source]

Given a pyparsing.ParseResult object, finds a appropriate formatter for that result, and formats the result into a URI using that formatter.

addformatter(key, func)[source]

Add a single formatter to the list of registered formatters after initialization.

formatterfor(key)[source]

Returns an appropriate formatting callable for the given key, or None if not found.