drothlis/stb-tester — pull request #194 by LewisHaley (2014-07-02 09:59:58+00:00)
Title: stbt.{warn,debug,ddebug}: don't cast unicode to python-string

Commit 0f71ebe7 made all logging output encoded as utf-8. This was to
support utf-8 characters read by OCR. However, the commit did not update
the `warn`, `debug` and `ddebug` functions, which were casting their
messages to python-string type (which is ascii) and this was causing
errors because you *can't* cast utf-8 encoded characters to ascii (not
just using `str()` anyway). This was raising UnicodeEncodeError.

e.g.:
In [8]: print 'ä'
ä
In [9]: print str('ä')
ä
In [10]: print u'ä'
ä
In [11]: print str(u'ä')
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
in ()
----> 1 print str(u'ä')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in...
position 0: ordinal not in range(128)

This commit fixes the issue by removing the `str()` cast. This shouldn't
cause breakage because the python string formatter `%s` used to insert
the message into the output string is *already* calling the objects
`__repr__` or `__str__` methods (so something like `debug(1)` will just
cast the `int(1)` to `str('1')` anyway).