Exemple #1
0
def sub(match, **context):
    """
    Default tag processor.
    Returns the appropriate value from **context for a matched tag.
    """
    tag = helpers.get_single_group(match)
    if re.search(r"\[.+\]|\.", tag):
        # Attribute/Indice lookup
        val = utils.unicode(eval(tag, {"__builtins__": None}, context))
    else:
        # Straight value
        val = utils.unicode(context.get(tag, "")) # TODO: Error check
    if not val and tag not in context.keys():
        warnings.warn(
            "No context variable matched the tag %s" % tag,
            ContextWarning
        )
    return val
Exemple #2
0
def register(*tag_list):
    """Register a sequence of tags."""
    manager = get_manager()
    for tag in tag_list:
        manager.add(tag)
        LOGGER.info("Registered: %s", utils.unicode(tag))