cpython: cd1759711357 (original) (raw)
Mercurial > cpython
changeset 71164:cd1759711357 3.2
Issue #12451: runpy: run_path() now opens the Python script in binary mode, instead of text mode using the locale encoding, to support other encodings than UTF-8 (scripts using the coding cookie). [#12451]
Victor Stinner victor.stinner@haypocalc.com | |
---|---|
date | Mon, 04 Jul 2011 01:45:39 +0200 |
parents | 81424281ee59 |
children | e240af1f0ae1 a1b4f1716b73 |
files | Lib/runpy.py Lib/test/test_runpy.py Misc/NEWS |
diffstat | 3 files changed, 15 insertions(+), 1 deletions(-)[+] [-] Lib/runpy.py 2 Lib/test/test_runpy.py 10 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -226,7 +226,7 @@ def _get_code_from_file(fname): code = read_code(f) if code is None: # That didn't work, so try it as normal source code
with open(fname, "rU") as f:[](#l1.7)
--- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -405,6 +405,16 @@ argv0 = sys.argv[0] msg = "recursion depth exceeded" self.assertRaisesRegex(RuntimeError, msg, run_path, zip_name)
- def test_encoding(self):
with temp_dir() as script_dir:[](#l2.8)
filename = os.path.join(script_dir, 'script.py')[](#l2.9)
with open(filename, 'w', encoding='latin1') as f:[](#l2.10)
f.write("""[](#l2.11)
+#coding:latin1 +"non-ASCII: h\xe9" +""")
result = run_path(filename)[](#l2.15)
self.assertEqual(result['__doc__'], "non-ASCII: h\xe9")[](#l2.16)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,10 @@ Core and Builtins Library ------- +- Issue #12451: runpy: run_path() now opens the Python script in binary mode,