changeset 635:12d0357440b3

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.
author cmlenz
date Wed, 05 Sep 2007 12:46:20 +0000
parents 60a1fb39f915
children e0f12a6f3612
files genshi/template/base.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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:
Copyright (C) 2012-2017 Edgewall Software