with self.assertRaises(py_compile.PyCompileError):
py_compile.compile(bad_coding, self.pyc_path, doraise=True, quiet=1)
+ def test_utf7_decoded_cr_compiles(self):
+ with open(self.source_path, 'wb') as file:
+ file.write(b"#coding=U7+AA0''\n")
+
+ pyc_path = py_compile.compile(self.source_path, self.pyc_path, doraise=True)
+ self.assertEqual(pyc_path, self.pyc_path)
+ self.assertTrue(os.path.exists(self.pyc_path))
+
class PyCompileTestsWithSourceEpoch(PyCompileTestsBase,
unittest.TestCase,
--- /dev/null
+Fixed a ``SystemError`` in the parser when an encoding cookie (for example,
+UTF-7) decodes to carriage returns (``\r``). Newlines are now normalized after
+decoding in the string tokenizer.
+
+Patch by Pablo Galindo.
else if (!_PyTokenizer_ensure_utf8(str, tok, 1)) {
return _PyTokenizer_error_ret(tok);
}
+ if (utf8 != NULL) {
+ char *translated = _PyTokenizer_translate_newlines(
+ str, single, preserve_crlf, tok);
+ if (translated == NULL) {
+ Py_DECREF(utf8);
+ return _PyTokenizer_error_ret(tok);
+ }
+ PyMem_Free(tok->input);
+ tok->input = translated;
+ str = translated;
+ Py_CLEAR(utf8);
+ }
+ tok->str = str;
assert(tok->decoding_buffer == NULL);
tok->decoding_buffer = utf8; /* CAUTION */
return str;