Fixed #1403 where compileall and py_compile choked on an encoding header in a py file. Both modules need more unit tests.
diff --git a/Lib/io.py b/Lib/io.py
index b305b53..c2f5d3e 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -1063,6 +1063,9 @@
                 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