# HG changeset patch # User cmlenz # Date 1188996380 0 # Node ID 7e666e3e4f1b595a1e18b9e05795eb8fb73385ed # Parent 2910e2532a60c2aa761d1d4690433540346cda1c 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: