202
202
filename.decode(fs_enc, "replace"),
204
204
name.decode("ascii", "replace"),
205
line.decode(_get_source_encoding(filename), "replace")))
205
line and line.decode(
206
_get_source_encoding(filename), "replace")))
206
207
list.extend(traceback.format_list(extracted_list))
209
210
if evalue is None:
210
211
# Is a (deprecated) string exception
211
list.append(sclass.decode("ascii", "replace"))
212
elif isinstance(evalue, SyntaxError) and len(evalue.args) > 1:
212
list.append((eclass + "\n").decode("ascii", "replace"))
214
if isinstance(evalue, SyntaxError):
213
215
# Avoid duplicating the special formatting for SyntaxError here,
214
216
# instead create a new instance with unicode filename and line
215
217
# Potentially gives duff spacing, but that's a pre-existing issue
216
filename, lineno, offset, line = evalue.args[1]
219
msg, (filename, lineno, offset, line) = evalue
220
except (TypeError, ValueError):
221
pass # Strange exception instance, fall through to generic code
218
223
# Errors during parsing give the line from buffer encoded as
219
224
# latin-1 or utf-8 or the encoding of the file depending on the
220
225
# coding and whether the patch for issue #1031213 is applied, so
221
226
# give up on trying to decode it and just read the file again
222
bytestr = linecache.getline(filename, lineno)
224
if lineno == 1 and bytestr.startswith("\xef\xbb\xbf"):
225
bytestr = bytestr[3:]
226
line = bytestr.decode(_get_source_encoding(filename), "replace")
227
del linecache.cache[filename]
229
line = line.decode("ascii", "replace")
231
filename = filename.decode(fs_enc, "replace")
232
evalue = eclass(evalue.args[0], (filename, lineno, offset, line))
233
list.extend(traceback.format_exception_only(eclass, evalue))
228
bytestr = linecache.getline(filename, lineno)
230
if lineno == 1 and bytestr.startswith("\xef\xbb\xbf"):
231
bytestr = bytestr[3:]
232
line = bytestr.decode(
233
_get_source_encoding(filename), "replace")
234
del linecache.cache[filename]
236
line = line.decode("ascii", "replace")
238
filename = filename.decode(fs_enc, "replace")
239
evalue = eclass(msg, (filename, lineno, offset, line))
240
list.extend(traceback.format_exception_only(eclass, evalue))
242
sclass = eclass.__name__
243
svalue = _exception_to_text(evalue)
245
list.append("%s: %s\n" % (sclass, svalue))
247
# GZ 2010-05-24: Not a great fallback message, but keep for the moment
248
list.append("%s: <unprintable %s object>\n" % (sclass, sclass))
235
sclass = eclass.__name__
236
svalue = _exception_to_text(evalue)
238
list.append("%s: %s\n" % (sclass, svalue))
240
# GZ 2010-05-24: Not a great fallback message, but keep for the
241
# the same for compatibility for the moment
242
list.append("%s: <unprintable %s object>\n" % (sclass, sclass))
244
list.append("%s\n" % sclass)
250
list.append("%s\n" % sclass)