# HG changeset patch # User cmlenz # Date 1188996380 0 # Node ID 12d0357440b3b07f1995bfa91a7f680ce8043de2 # Parent 60a1fb39f915396ea6e979c9833890d2c4656af8 Minor performance improvement for expressions that evaluate to numbers: the result is wrapped in a `Markup` object, meaning we'll not have to escape the string in the serialization stage. diff --git a/genshi/template/base.py b/genshi/template/base.py --- a/genshi/template/base.py +++ b/genshi/template/base.py @@ -23,7 +23,8 @@ from StringIO import StringIO import sys -from genshi.core import Attrs, Stream, StreamEventKind, START, TEXT, _ensure +from genshi.core import Attrs, Markup, Stream, StreamEventKind, START, TEXT, \ + _ensure from genshi.input import ParseError __all__ = ['Context', 'Template', 'TemplateError', 'TemplateRuntimeError', @@ -470,11 +471,13 @@ elif kind is EXPR: result = data.evaluate(ctxt) if result is not None: - # First check for a string, otherwise the iterable test below - # succeeds, and the string will be chopped up into individual - # characters + # First check for a string, otherwise the iterable test + # below succeeds, and the string will be chopped up into + # individual characters if isinstance(result, basestring): yield TEXT, result, pos + elif isinstance(result, (int, float, long)): + yield TEXT, Markup(result), pos elif hasattr(result, '__iter__'): substream = _ensure(result) for filter_ in filters: