PEP 302 source loaders already decode appropriately

This commit is contained in:
Ian Clelland 2012-09-26 12:41:47 -07:00 committed by Luke Plant
parent 71734dfa72
commit 3629a159f9
1 changed files with 13 additions and 9 deletions

View File

@ -354,6 +354,10 @@ class ExceptionReporter(object):
if source is None: if source is None:
return None, [], None, [] return None, [], None, []
# 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' encoding = 'ascii'
for line in source[:2]: for line in source[:2]:
# File coding may be specified. Match pattern from PEP-263 # File coding may be specified. Match pattern from PEP-263