The Pyramid debug toolbar is a real blessing. I think we need to rip it for use with TurboGears, too ;-)

However, I have experienced some issues with exceptions when they have a non-ascii error message (I remember there were similar problems with the Pylons weberror module). For instance, PostgreSQL creates error messages in latin-1 or utf-8 depending on how it is configured. The debug toolbar assumes that error messages are always ascii strings or unicode and crashes with a UnicodeDecodeError on such exceptions.

Is this a known problem?

My solution was to wrap exceptions and tracebacks in text_() calls, e.g. in render_summary, render_full and generate_plaintext_traceback.

This avoids the crashes, but utf-8 messages will look odd because text_() assumes latin-1 encoding by default. My suggestion is to replace the latin-1 default with utf-8 and fall back to latin-1 only in case the text is not decodable as utf-8. Like this:

def text_(s, encoding=None, errors='strict'):
    if isinstance(s, binary_type):
        if not encoding:
            try:
                return s.decode('utf-8')
            except UnicodeDecodeError:
                encoding = 'latin-1'
        return s.decode(encoding, errors)
    return s # pragma: no cover

This has been working nicely for me. Thougts?

If you think that makes sense, I can submit a patch on github.

-- Christoph

--
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to