Skip to content

Commit d0feea5

Browse files
committed
[py3] Followup bad0d3e: Don't decode unencoded strings
1 parent 7a8d9dd commit d0feea5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

python/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,18 @@
6565

6666

6767
def showWarning(message, category, filename, lineno, file=None, line=None):
68-
stk = ''.join([s.decode(sys.getfilesystemencoding()) for s in traceback.format_stack()[:-2]])
68+
stk = ""
69+
for s in traceback.format_stack()[:-2]:
70+
if hasattr(s, 'decode'):
71+
stk += s.decode(sys.getfilesystemencoding())
72+
else:
73+
stk += s
74+
if hasattr(filename, 'decode'):
75+
decoded_filename = filename.decode(sys.getfilesystemencoding())
76+
else:
77+
decoded_filename = filename
6978
QgsMessageLog.logMessage(
70-
u"warning:{}\ntraceback:{}".format(warnings.formatwarning(message, category, filename.decode(sys.getfilesystemencoding()), lineno), stk),
79+
u"warning:{}\ntraceback:{}".format(warnings.formatwarning(message, category, decoded_filename, lineno), stk),
7180
QCoreApplication.translate("Python", "Python warning")
7281
)
7382

0 commit comments

Comments
 (0)