Skip to content

Commit

Permalink
[py3] Followup bad0d3e: Don't decode unencoded strings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 7, 2016
1 parent 7a8d9dd commit d0feea5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/utils.py
Expand Up @@ -65,9 +65,18 @@


def showWarning(message, category, filename, lineno, file=None, line=None):
stk = ''.join([s.decode(sys.getfilesystemencoding()) for s in traceback.format_stack()[:-2]])
stk = ""
for s in traceback.format_stack()[:-2]:
if hasattr(s, 'decode'):
stk += s.decode(sys.getfilesystemencoding())
else:
stk += s
if hasattr(filename, 'decode'):
decoded_filename = filename.decode(sys.getfilesystemencoding())
else:
decoded_filename = filename
QgsMessageLog.logMessage(
u"warning:{}\ntraceback:{}".format(warnings.formatwarning(message, category, filename.decode(sys.getfilesystemencoding()), lineno), stk),
u"warning:{}\ntraceback:{}".format(warnings.formatwarning(message, category, decoded_filename, lineno), stk),
QCoreApplication.translate("Python", "Python warning")
)

Expand Down

0 comments on commit d0feea5

Please sign in to comment.