template

class lucidity.template.Template(name, pattern, anchor=1, default_placeholder_expression='[\w_.\-]+')[source]

Bases: object

A template.

__init__(name, pattern, anchor=1, default_placeholder_expression='[\w_.\-]+')[source]

Initialise with name and pattern.

anchor determines how the pattern is anchored during a parse. A value of ANCHOR_START (the default) will match the pattern against the start of a path. ANCHOR_END will match against the end of a path. To anchor at both the start and end (a full path match) use ANCHOR_BOTH. Finally, None will try to match the pattern once anywhere in the path.

name[source]

Return name of template.

pattern[source]

Return template pattern.

parse(path)[source]

Return dictionary of data extracted from path using this template.

Raise ParseError if path is not parseable by this template.

format(data)[source]

Return a path formatted by applying data to this template.

Raise FormatError if data does not supply enough information to fill the template fields.

keys()[source]

Return unique set of placeholders in pattern.

ANCHOR_BOTH = 3
ANCHOR_END = 2
ANCHOR_START = 1