Esempio n. 1
0
    def __call__(self, stream, directives, ctxt, **vars):
        info = ctxt._choice_stack and ctxt._choice_stack[-1]
        if not info:
            raise TemplateRuntimeError('"when" directives can only be used '
                                       'inside a "choose" directive',
                                       self.filename, *(next(stream))[2][1:])
        if info[0]:
            return []
        if not self.expr and not info[1]:
            raise TemplateRuntimeError('either "choose" or "when" directive '
                                       'must have a test expression',
                                       self.filename, *(next(stream))[2][1:])
        if info[1]:
            value = info[2]
            if self.expr:
                matched = value == _eval_expr(self.expr, ctxt, vars)
            else:
                matched = bool(value)
        else:
            matched = bool(_eval_expr(self.expr, ctxt, vars))
        info[0] = matched
        if not matched:
            return []

        return _apply_directives(stream, directives, ctxt, vars)
Esempio n. 2
0
    def __call__(self, stream, directives, ctxt, **vars):
        info = ctxt._choice_stack and ctxt._choice_stack[-1]
        if not info:
            raise TemplateRuntimeError('an "otherwise" directive can only be '
                                       'used inside a "choose" directive',
                                       self.filename, *(next(stream))[2][1:])
        if info[0]:
            return []
        info[0] = True

        return _apply_directives(stream, directives, ctxt, vars)
Esempio n. 3
0
 def __init__(self, name, owner=UNDEFINED):
     if owner is not UNDEFINED:
         message = '%s has no member named "%s"' % (repr(owner), name)
     else:
         message = '"%s" not defined' % name
     TemplateRuntimeError.__init__(self, message)
Esempio n. 4
0
 def __init__(self, name, owner=UNDEFINED):
     if owner is not UNDEFINED:
         message = '%s has no member named "%s"' % (repr(owner), name)
     else:
         message = '"%s" not defined' % name
     TemplateRuntimeError.__init__(self, message)