template¶
-
class
lucidity.template.Template(name, pattern, anchor=1, default_placeholder_expression='[\w_.\-]+', duplicate_placeholder_mode=1, template_resolver=None)[source]¶ Bases:
objectA template.
-
ANCHOR_START= 1¶
-
ANCHOR_END= 2¶
-
ANCHOR_BOTH= 3¶
-
RELAXED= 1¶
-
STRICT= 2¶
-
__init__(name, pattern, anchor=1, default_placeholder_expression='[\\w_.\\-]+', duplicate_placeholder_mode=1, template_resolver=None)[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_ENDwill match against the end of a path. To anchor at both the start and end (a full path match) useANCHOR_BOTH. Finally,Nonewill try to match the pattern once anywhere in the path.duplicate_placeholder_mode determines how duplicate placeholders will be handled during parsing.
RELAXEDmode extracts the last matching value without checking the other values.STRICTmode ensures that all duplicate placeholders extract the same value and raisesParseErrorif they do not.If template_resolver is supplied, use it to resolve any template references in the pattern during operations. It should conform to the
Resolverinterface. It can be changed at any time on the instance to affect future operations.
-
name¶ Return name of template.
-
pattern¶ Return template pattern.
-
expanded_pattern()[source]¶ Return pattern with all referenced templates expanded recursively.
Raise
lucidity.error.ResolveErrorif pattern contains a reference that cannot be resolved by currently set template_resolver.
-
parse(path)[source]¶ Return dictionary of data extracted from path using this template.
Raise
ParseErrorif path is not parsable by this template.
-
format(data)[source]¶ Return a path formatted by applying data to this template.
Raise
FormatErrorif data does not supply enough information to fill the template fields.
-