Pylons/pyramid_debugtoolbar — pull request #126 by nbasu02 (2013-09-18 00:39:29+00:00)
Title: Added support for python2 objects with unicode __repr__()

See issue #70

When an object in Python 2 is passed to a template and has unicode characters in its __repr__() output

ex:

class foo(object):
def __repr__(self):
return u'あ'.encode('utf-8')

a UnicodeDecodeError is thrown.

This patch (mostly taken from Benwah in the comments of #70), converts the renderings in the toolbar to utf-8 unicode. I have observed this has fixed the issue and works for unicode characters encoded as unicode, ascii characters encoded as unicode, and ascii characters not encoded.

This patch is ignored in Python 3, as unicode is used by default.