Ejemplo n.º 1
0
    def test_tree_events(self):
        event_prefixed_items = [(STARTEVENT, 'a'), (ENDEVENT, 'a')]
        rootitem, childs = build_subtree(iter(event_prefixed_items[1:]))
        self.assertEquals('a', rootitem)
        self.assertEquals(0, len(childs))

        event_prefixed_items = [
            (STARTEVENT, 'a'),
            (STARTEVENT, 'b'),
            (ENDEVENT, 'b'),
            (ENDEVENT, 'a')
        ]
        self.assertEquals(
            ('a', [('b', [])]),
            build_subtree(iter(event_prefixed_items[1:]))
        )

        event_prefixed_items = [
            (STARTEVENT, 'a'),
            (STARTEVENT, 'b'),
            (STARTEVENT, 'c'), (ENDEVENT, 'c'),
            (STARTEVENT, 'd'), (ENDEVENT, 'd'),
            (ENDEVENT, 'b'),
            (ENDEVENT, 'a')
        ]

        result = build_subtree(iter(event_prefixed_items[1:]))
        self.assertEquals(
            ('a', [('b', [('c', []), ('d', [])])]),
            result
        )

        back = list(tree_events(*result))
        self.assertEquals(event_prefixed_items, back)
Ejemplo n.º 2
0
    def test_tree_events(self):
        from hwp5.treeop import STARTEVENT, ENDEVENT
        from hwp5.treeop import build_subtree
        from hwp5.treeop import tree_events
        event_prefixed_items = [ (STARTEVENT, 'a'), (ENDEVENT, 'a') ]
        rootitem, childs = build_subtree(iter(event_prefixed_items[1:]))
        self.assertEquals('a', rootitem)
        self.assertEquals(0, len(childs))

        event_prefixed_items = [ (STARTEVENT, 'a'), (STARTEVENT, 'b'), (ENDEVENT, 'b'), (ENDEVENT, 'a') ]
        self.assertEquals( ('a', [('b', [])]), build_subtree(iter(event_prefixed_items[1:])))

        event_prefixed_items = [
            (STARTEVENT, 'a'),
                (STARTEVENT, 'b'),
                    (STARTEVENT, 'c'), (ENDEVENT, 'c'),
                    (STARTEVENT, 'd'), (ENDEVENT, 'd'),
                (ENDEVENT, 'b'),
            (ENDEVENT, 'a')]

        result = build_subtree(iter(event_prefixed_items[1:]))
        self.assertEquals( ('a', [('b', [('c', []), ('d', [])])]), result)

        back = list(tree_events(*result))
        self.assertEquals(event_prefixed_items, back)
Ejemplo n.º 3
0
def meci_controlchar(event, stack, item, attributes):
    if event is STARTEVENT:
        if attributes['kind'] is ControlChar.EXTENDED:
            paragraph = stack[-1]
            paragraph_controls = paragraph.get(Control)
            control_subtree = paragraph_controls.pop(0)
            tev = tree_events(*control_subtree)
            # to evade the Control/STARTEVENT trigger
            # in parse_models_pass3()
            yield tev.next()

            for k in make_extended_controls_inline(tev, stack):
                yield k
        else:
            yield STARTEVENT, item
            yield ENDEVENT, item