template
¶
-
class
lucidity.template.
Template
(name, pattern, anchor=1, default_placeholder_expression='[\w_.\-]+', duplicate_placeholder_mode=1)[source]¶ Bases:
object
A template.
-
__init__
(name, pattern, anchor=1, default_placeholder_expression='[\\w_.\\-]+', duplicate_placeholder_mode=1)[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) useANCHOR_BOTH
. Finally,None
will try to match the pattern once anywhere in the path.duplicate_placeholder_mode determines how duplicate placeholders will be handled during parsing.
RELAXED
mode extracts the last matching value without checking the other values.STRICT
mode ensures that all duplicate placeholders extract the same value and raisesParseError
if they do not.
-
name
¶ Return name of template.
-
pattern
¶ 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.
-
ANCHOR_BOTH
= 3¶
-
ANCHOR_END
= 2¶
-
ANCHOR_START
= 1¶
-
RELAXED
= 1¶
-
STRICT
= 2¶
-