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
# 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':