Mercurial > genshi > genshi-test
diff markup/template.py @ 10:c5890ef863ba
Moved the template-specific stream event kinds into the template module.
author | cmlenz |
---|---|
date | Sun, 04 Jun 2006 12:34:17 +0000 |
parents | 5da45906dda7 |
children | bf9de5a4c896 |
line wrap: on
line diff
--- a/markup/template.py +++ b/markup/template.py @@ -47,7 +47,7 @@ import re from StringIO import StringIO -from markup.core import Attributes, Stream +from markup.core import Attributes, Stream, StreamEventKind from markup.eval import Expression from markup.filters import EvalFilter, IncludeFilter, MatchFilter, \ WhitespaceFilter @@ -241,13 +241,12 @@ kind, data, pos = stream.next() if kind is Stream.START: yield kind, data, pos # emit start tag - yield Stream.EXPR, self.expr, pos + yield Template.EXPR, self.expr, pos previous = stream.next() for event in stream: previous = event - else: - if previous is not None: - yield previous + if previous is not None: + yield previous class DefDirective(Directive): @@ -450,7 +449,7 @@ """ def __call__(self, stream, ctxt): kind, data, pos = stream.next() - yield Stream.EXPR, self.expr, pos + yield Template.EXPR, self.expr, pos class StripDirective(Directive): @@ -513,8 +512,6 @@ strip = True if strip: stream.next() # skip start tag - # can ignore StopIteration since it will just break from this - # generator previous = stream.next() for event in stream: yield previous @@ -530,6 +527,9 @@ """ NAMESPACE = 'http://purl.org/kid/ns#' + EXPR = StreamEventKind('expr') # an expression + SUB = StreamEventKind('sub') # a "subprogram" + directives = [('def', DefDirective), ('match', MatchDirective), ('for', ForDirective), @@ -620,7 +620,7 @@ if (depth, data) in dirmap: directives, start_offset = dirmap.pop((depth, data)) substream = stream[start_offset:] - stream[start_offset:] = [(Stream.SUB, + stream[start_offset:] = [(Template.SUB, (directives, substream), pos)] elif kind is Stream.TEXT: @@ -643,7 +643,7 @@ try: for kind, data, pos in stream: - if kind is Stream.SUB: + if kind is Template.SUB: # This event is a list of directives and a list of # nested events to which those directives should be # applied @@ -686,7 +686,7 @@ def _interpolate(text): for idx, group in enumerate(patterns.pop(0).split(text)): if idx % 2: - yield Stream.EXPR, Expression(group), (lineno, offset) + yield Template.EXPR, Expression(group), (lineno, offset) elif group: if patterns: for result in _interpolate(group):