Skip to content


Subversion checkout URL

You can clone with
Download ZIP


In Python 2, convert literal strings explicitly to ASCII when possible #305

wants to merge 1 commit into from

2 participants


Fix for #304


Not going to merge this, see other comment.

@mitsuhiko mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 7 deletions.
  1. +7 −7 jinja2/
14 jinja2/
@@ -21,7 +21,7 @@
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
@@ -576,12 +576,12 @@ def wrap(self, stream, name=None, filename=None):
raise TemplateSyntaxError(msg, lineno, name, filename)
# if we can express it as bytestring (ascii only)
# 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
+ # as datetime.datetime.strftime.
+ if PY2:
+ try:
+ value = value.encode('ascii')
+ except UnicodeError:
+ pass
elif token == 'integer':
value = int(value)
elif token == 'float':
Something went wrong with that request. Please try again.