Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@ntrrgc

Fix for #304

@mitsuhiko
Owner

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/lexer.py
View
14 jinja2/lexer.py
@@ -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.