PEP 302 source loaders already decode appropriately
This commit is contained in:
parent
71734dfa72
commit
3629a159f9
|
@ -354,15 +354,19 @@ class ExceptionReporter(object):
|
|||
if source is None:
|
||||
return None, [], None, []
|
||||
|
||||
encoding = 'ascii'
|
||||
for line in source[:2]:
|
||||
# File coding may be specified. Match pattern from PEP-263
|
||||
# (http://www.python.org/dev/peps/pep-0263/)
|
||||
match = re.search(br'coding[:=]\s*([-\w.]+)', line)
|
||||
if match:
|
||||
encoding = match.group(1).decode('ascii')
|
||||
break
|
||||
source = [six.text_type(sline, encoding, 'replace') for sline in source]
|
||||
# If we just read the source from a file, or if the loader did not
|
||||
# apply tokenize.detect_encoding to decode the source into a Unicode
|
||||
# string, then we should do that ourselves.
|
||||
if isinstance(source[0], six.binary_type):
|
||||
encoding = 'ascii'
|
||||
for line in source[:2]:
|
||||
# File coding may be specified. Match pattern from PEP-263
|
||||
# (http://www.python.org/dev/peps/pep-0263/)
|
||||
match = re.search(br'coding[:=]\s*([-\w.]+)', line)
|
||||
if match:
|
||||
encoding = match.group(1).decode('ascii')
|
||||
break
|
||||
source = [six.text_type(sline, encoding, 'replace') for sline in source]
|
||||
|
||||
lower_bound = max(0, lineno - context_lines)
|
||||
upper_bound = lineno + context_lines
|
||||
|
|
Loading…
Reference in New Issue