Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
10654c19
Commit
10654c19
authored
Apr 01, 2019
by
Inada Naoki
Committed by
GitHub
Apr 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-20844: open script file with "rb" mode (GH-12616)
parent
62f95886
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
1 deletion
+24
-1
Doc/c-api/veryhigh.rst
Doc/c-api/veryhigh.rst
+4
-0
Lib/test/test_cmd_line_script.py
Lib/test/test_cmd_line_script.py
+17
-0
Misc/NEWS.d/next/Core and Builtins/2019-03-29-18-47-50.bpo-20844.ge-7SM.rst
...ore and Builtins/2019-03-29-18-47-50.bpo-20844.ge-7SM.rst
+2
-0
Modules/main.c
Modules/main.c
+1
-1
No files found.
Doc/c-api/veryhigh.rst
View file @
10654c19
...
...
@@ -109,6 +109,10 @@ the same library that the Python runtime is using.
(:func:`sys.getfilesystemencoding`). If *closeit* is true, the file is
closed before PyRun_SimpleFileExFlags returns.
.. note::
On Windows, *fp* should be opened as binary mode (e.g. ``fopen(filename, "rb")``.
Otherwise, Python may not handle script file with LF line ending correctly.
.. c:function:: int PyRun_InteractiveOne(FILE *fp, const char *filename)
...
...
Lib/test/test_cmd_line_script.py
View file @
10654c19
...
...
@@ -409,6 +409,23 @@ class CmdLineTest(unittest.TestCase):
script_name
,
script_name
,
script_dir
,
''
,
importlib
.
machinery
.
SourceFileLoader
)
def
test_issue20884
(
self
):
# On Windows, script with encoding cookie and LF line ending
# will be failed.
with
support
.
temp_dir
()
as
script_dir
:
script_name
=
os
.
path
.
join
(
script_dir
,
"issue20884.py"
)
with
open
(
script_name
,
"w"
,
newline
=
'
\
n
'
)
as
f
:
f
.
write
(
"#coding: iso-8859-1
\
n
"
)
f
.
write
(
'"""
\
n
'
)
for
_
in
range
(
30
):
f
.
write
(
'x'
*
80
+
'
\
n
'
)
f
.
write
(
'"""
\
n
'
)
with
support
.
change_cwd
(
path
=
script_dir
):
rc
,
out
,
err
=
assert_python_ok
(
script_name
)
self
.
assertEqual
(
b""
,
out
)
self
.
assertEqual
(
b""
,
err
)
@
contextlib
.
contextmanager
def
setup_test_pkg
(
self
,
*
args
):
with
support
.
temp_dir
()
as
script_dir
,
\
...
...
Misc/NEWS.d/next/Core and Builtins/2019-03-29-18-47-50.bpo-20844.ge-7SM.rst
0 → 100644
View file @
10654c19
Fix running script with encoding cookie and LF line ending
may fail on Windows.
Modules/main.c
View file @
10654c19
...
...
@@ -283,7 +283,7 @@ static int
pymain_run_file
(
_PyCoreConfig
*
config
,
PyCompilerFlags
*
cf
)
{
const
wchar_t
*
filename
=
config
->
run_filename
;
FILE
*
fp
=
_Py_wfopen
(
filename
,
L"r"
);
FILE
*
fp
=
_Py_wfopen
(
filename
,
L"r
b
"
);
if
(
fp
==
NULL
)
{
char
*
cfilename_buffer
;
const
char
*
cfilename
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment