Commit 77b88a7a authored by Christian Heimes's avatar Christian Heimes

Fixed #1403 where compileall and py_compile choked on an encoding header in a...

Fixed #1403 where compileall and py_compile choked on an encoding header in a py file. Both modules need more unit tests.
parent 29521ce2
...@@ -1063,6 +1063,9 @@ class TextIOWrapper(TextIOBase): ...@@ -1063,6 +1063,9 @@ class TextIOWrapper(TextIOBase):
else: else:
encoding = locale.getpreferredencoding() encoding = locale.getpreferredencoding()
if not isinstance(encoding, str):
raise ValueError("invalid encoding: %r" % encoding)
self.buffer = buffer self.buffer = buffer
self._encoding = encoding self._encoding = encoding
self._readuniversal = not newline self._readuniversal = not newline
......
...@@ -88,7 +88,7 @@ def read_encoding(file, default): ...@@ -88,7 +88,7 @@ def read_encoding(file, default):
break break
m = re.match(r".*\bcoding:\s*(\S+)\b", line) m = re.match(r".*\bcoding:\s*(\S+)\b", line)
if m: if m:
return str(m.group(1)) return m.group(1).decode("ascii")
return default return default
finally: finally:
f.close() f.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment