From: Armin Ronacher Date: Fri, 6 Jun 2014 15:48:42 +0000 (+0600) Subject: Fix for #304 X-Git-Tag: 2.8~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06badebe3b0985c9fe3365ab446f690d1af3a512;p=thirdparty%2Fjinja.git Fix for #304 --- diff --git a/jinja2/lexer.py b/jinja2/lexer.py index 36042e01..d751cff0 100644 --- a/jinja2/lexer.py +++ b/jinja2/lexer.py @@ -21,7 +21,7 @@ from collections import deque from jinja2.exceptions import TemplateSyntaxError from jinja2.utils import LRUCache from jinja2._compat import iteritems, implements_iterator, text_type, \ - intern + intern, PY2 # cache for the lexers. Exists in order to be able to have multiple @@ -578,10 +578,11 @@ class Lexer(object): # we do that for support of semi broken APIs # as datetime.datetime.strftime. On python 3 this # call becomes a noop thanks to 2to3 - try: - value = str(value) - except UnicodeError: - pass + if PY2: + try: + value = value.encode('ascii') + except UnicodeError: + pass elif token == 'integer': value = int(value) elif token == 'float':