Fix unicode errors when changing to .format(...)
This commit is contained in:
parent
8bb8b91357
commit
0d65783dce
|
@ -2,7 +2,7 @@
|
||||||
# CHANGES:
|
# CHANGES:
|
||||||
# - some_str is replaced, trying to create unicode strings
|
# - some_str is replaced, trying to create unicode strings
|
||||||
#
|
#
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
import types
|
import types
|
||||||
from six import text_type
|
from six import text_type
|
||||||
|
|
||||||
|
@ -51,17 +51,17 @@ def format_exception_only(etype, value):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
filename = filename or "<string>"
|
filename = filename or "<string>"
|
||||||
lines.append(' File "%s", line %d\n' % (filename, lineno))
|
lines.append(' File "{}", line {}\n'.format(filename, lineno))
|
||||||
if badline is not None:
|
if badline is not None:
|
||||||
if isinstance(badline, bytes): # python 2 only
|
if isinstance(badline, bytes): # python 2 only
|
||||||
badline = badline.decode("utf-8", "replace")
|
badline = badline.decode("utf-8", "replace")
|
||||||
lines.append(u" %s\n" % badline.strip())
|
lines.append(" {}\n".format(badline.strip()))
|
||||||
if offset is not None:
|
if offset is not None:
|
||||||
caretspace = badline.rstrip("\n")[:offset].lstrip()
|
caretspace = badline.rstrip("\n")[:offset].lstrip()
|
||||||
# non-space whitespace (likes tabs) must be kept for alignment
|
# non-space whitespace (likes tabs) must be kept for alignment
|
||||||
caretspace = ((c.isspace() and c or " ") for c in caretspace)
|
caretspace = ((c.isspace() and c or " ") for c in caretspace)
|
||||||
# only three spaces to account for offset1 == pos 0
|
# only three spaces to account for offset1 == pos 0
|
||||||
lines.append(" %s^\n" % "".join(caretspace))
|
lines.append(" {}^\n".format("".join(caretspace)))
|
||||||
value = msg
|
value = msg
|
||||||
|
|
||||||
lines.append(_format_final_exc_line(stype, value))
|
lines.append(_format_final_exc_line(stype, value))
|
||||||
|
@ -72,9 +72,9 @@ def _format_final_exc_line(etype, value):
|
||||||
"""Return a list of a single line -- normal case for format_exception_only"""
|
"""Return a list of a single line -- normal case for format_exception_only"""
|
||||||
valuestr = _some_str(value)
|
valuestr = _some_str(value)
|
||||||
if value is None or not valuestr:
|
if value is None or not valuestr:
|
||||||
line = "%s\n" % etype
|
line = "{}\n".format(etype)
|
||||||
else:
|
else:
|
||||||
line = "%s: %s\n" % (etype, valuestr)
|
line = "{}: {}\n".format(etype, valuestr)
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ def _some_str(value):
|
||||||
return text_type(value)
|
return text_type(value)
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
return str(value)
|
return bytes(value).decode("UTF-8", "replace")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return "<unprintable %s object>" % type(value).__name__
|
return "<unprintable {} object>".format(type(value).__name__)
|
||||||
|
|
Loading…
Reference in New Issue