On Thu, Oct 4, 2012 at 1:25 AM, Ben Darnell <b
...@bendarnell.com> wrote:
> This looks like a bug in the template system. Does it work if you
> return utf8(_LINK_RE.sub())? The problem looks like the template
> system generally turns unicode strings into utf8 for you, but not for
> the output of apply blocks. It'll work as long as you either
> pre-encode your strings or everything happens to be ascii-only, but it
> will blow up if you get any non-ascii characters in a unicode string.
> -Ben
> On Wed, Oct 3, 2012 at 10:02 AM, DLC <dmit...@gmail.com> wrote:
> > I'm trying to create a template function that turns @mentions or hash
> tags
> > into their corresponding href links (sample code here:
> > https://gist.github.com/3828280#file_p.py), but I've run into a snag.
> > It works most of the time, but when I use my own {% apply *function* %}
> {%
> > end %} I sometimes run into an error like:
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
> > ordinal not in range(128)
> > Here is a traceback: https://gist.github.com/3828280#file_gistfile1.pytb
> > And here's the general form of the template:
> > https://gist.github.com/3828280#file_t.html
> > If I remove that apply function, I no longer get the error. I'm not quite
> > what causes the error though. I tried using tornado.escape.linkify in
> it's
> > place, but I still get the error, and so believe I may be doing something
> > wrong, or it may be a bug in the template rendering code.
> > I noted in the documentation
> > http://www.tornadoweb.org/documentation/template.html#syntax-referenceit
> > cautions using apply blocks in for loops with breaks or continues,
> however I
> > do not use them. I do extend from a base template.
> > If anyone has any insight, would love to hear!
> > D