Edgewall Software

Ticket #68: select-namespaces-68-stab1.patch

File select-namespaces-68-stab1.patch, 1.5 KB (added by David Fraser <davidf@…>, 17 years ago)

initial stab at producing namespace code using the namespace dictionary

  • genshi/path.py

     
    3535import re
    3636
    3737from genshi.core import Stream, Attrs, Namespace, QName
    38 from genshi.core import START, END, TEXT, COMMENT, PI
     38from genshi.core import START, END, START_NS, END_NS, TEXT, COMMENT, PI
    3939
    4040__all__ = ['Path', 'PathSyntaxError']
    4141
     
    117117        stream = iter(stream)
    118118        def _generate():
    119119            test = self.test()
     120            start_namespace_events = []
     121            reverse_namespaces = dict([(value, key) for (key, value) in namespaces.items()])
    120122            for kind, data, pos in stream:
     123                if kind is START_NS:
     124                    prefix, namespace = data
     125                    if namespace in reverse_namespaces:
     126                        yield (kind, (reverse_namespaces[namespace], namespace), pos)
    121127                result = test(kind, data, pos, namespaces, variables)
    122128                if result is True:
    123129                    yield kind, data, pos
     
    130136                            depth -= 1
    131137                        yield subkind, subdata, subpos
    132138                        test(subkind, subdata, subpos, namespaces, variables)
     139                    start_namespace_events = []
    133140                elif result:
    134141                    yield result
     142                elif kind is END_NS:
     143                    yield END_NS, data, pos
    135144        return Stream(_generate())
    136145
    137146    def test(self, ignore_context=False):