Hello,

I have run into some issues with utf-8 encoded data being displayed in 
Jinja2. More specifically, if I have a variable 'X' encoded as utf-8, and I 
refer to it in a template like {{ X }}, an exception is raised if it is a 
non-ascii unicode character. I can solve individual issues with {{ 
X.decode('utf-8') }}, but I have hundreds of references to various 
variables that may or may not have similar issues, and I'd rather handle it 
once (than dozens of times now and in the future).

What I want to do is to have every value to be output passed through a 
function that properly decodes as necessary. Something like...

def auto_decode(st):
  if isinstance(st, unicode):
    return st
  elif isinstance(st, str):
    return unicode(st, 'utf-8')
  else:
    return unicode(st)

I know this *should* be possible, autoescaping does a similar kind of thing 
(anyone know where the function is that does the autoescaping?)

How could/should I make this happen? Is there some sort of magical 
monkey-patching I can perform (I'm not above replacing code objects on 
functions)? Is there a visitor that I can write that replaces some node 
reference with another node that does what I describe above? Can I just add 
a piece that consumes a TemplateStream and handles the manipulation there?

Any pointers, ideas, etc., would be greatly appreciated.

Regards,
 - Josiah

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pocoo-libs/-/2eVf4FFrk_MJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to