Exemple #1
0
    def test_none(self):
        stack = NamespaceStack()
        stack.append({})
        repeat = NamespaceStack()

        expression = evaluate('none', stack, repeat)
        self.assertEqual(expression, None)
Exemple #2
0
    def test_none(self):
        stack = NamespaceStack()
        stack.append({})
        repeat = NamespaceStack()

        expression = evaluate('none', stack, repeat)
        self.assertEqual(expression, None)
def substitute(data, stack, repeat_stack):
    """Interprets the given data as a substitution string with the "${expr}"
    format, where the expression within the brackets is an STL expression.

    Returns the interpreted string.
    """
    segments = subs_expr.split(data)
    for i, segment in enumerate(segments):
        if i % 2:
            # if
            if segment[:3] == u"if ":
                yield evaluate_if(segment[3:], stack, repeat_stack)
            # endif
            elif segment == u"endif":
                yield ENDIF
            # repeat
            elif segment[:7] == u"repeat ":
                yield evaluate_repeat(segment[7:], stack, repeat_stack)
            # endrepeat
            elif segment == u"endrepeat":
                yield ENDREPEAT
            # Evaluate expression
            else:
                value = evaluate(segment, stack, repeat_stack)
                if isinstance(value, odf_element):
                    # Return a copy because nodes are not reusable
                    yield value.clone()
                else:
                    # Do not expect anything else that unicode for text
                    yield unicode(value)
        elif segment:
            yield segment
Exemple #4
0
def substitute(data, stack, repeat_stack):
    """Interprets the given data as a substitution string with the "${expr}"
    format, where the expression within the brackets is an STL expression.

    Returns the interpreted string.
    """
    segments = subs_expr.split(data)
    for i, segment in enumerate(segments):
        if i % 2:
            # if
            if segment[:3] == u"if ":
                yield evaluate_if(segment[3:], stack, repeat_stack)
            # endif
            elif segment == u"endif":
                yield ENDIF
            # repeat
            elif segment[:7] == u"repeat ":
                yield evaluate_repeat(segment[7:], stack, repeat_stack)
            # endrepeat
            elif segment == u"endrepeat":
                yield ENDREPEAT
            # Evaluate expression
            else:
                value = evaluate(segment, stack, repeat_stack)
                if isinstance(value, odf_element):
                    # Return a copy because nodes are not reusable
                    yield value.clone()
                else:
                    # Do not expect anything else that unicode for text
                    yield unicode(value)
        elif segment:
            yield segment
Exemple #5
0
    def test_traversal(self):
        namespace = {'a': {'b': {'c': 'hello world'}}}
        stack = NamespaceStack()
        stack.append(namespace)
        repeat = NamespaceStack()

        value = evaluate('a/b/c', stack, repeat)
        self.assertEqual(value, 'hello world')
Exemple #6
0
    def test_traversal(self):
        namespace = {'a': {'b': {'c': 'hello world'}}}
        stack = NamespaceStack()
        stack.append(namespace)
        repeat = NamespaceStack()

        value = evaluate('a/b/c', stack, repeat)
        self.assertEqual(value, 'hello world')