]> granicus.if.org Git - python/commitdiff
Fixed #1403 where compileall and py_compile choked on an encoding header in a py...
authorChristian Heimes <christian@cheimes.de>
Thu, 8 Nov 2007 16:34:32 +0000 (16:34 +0000)
committerChristian Heimes <christian@cheimes.de>
Thu, 8 Nov 2007 16:34:32 +0000 (16:34 +0000)
Lib/io.py
Lib/py_compile.py

index b305b53bb0bc7b825aa9e7db52d2bbec83206347..c2f5d3ebfaa4ed5e3750188f18064b6c8fbe9d6e 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -1063,6 +1063,9 @@ class TextIOWrapper(TextIOBase):
                 else:
                     encoding = locale.getpreferredencoding()
 
+        if not isinstance(encoding, str):
+            raise ValueError("invalid encoding: %r" % encoding)
+
         self.buffer = buffer
         self._encoding = encoding
         self._readuniversal = not newline
index f7a200204cad1259c3c78a01600ff85279750982..912972bcac263f021bb3418500493eb90ebc16e1 100644 (file)
@@ -88,7 +88,7 @@ def read_encoding(file, default):
                 break
             m = re.match(r".*\bcoding:\s*(\S+)\b", line)
             if m:
-                return str(m.group(1))
+                return m.group(1).decode("ascii")
         return default
     finally:
         f.close()