New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_pyio checks that os.name == 'win32'
instead of 'nt'
#69069
Comments
the
However, the string returned by os.name is 'nt' and not 'win32' (the latter is returned by Thank you. Cosimo |
To make _pyio correspond to the C version I've added sys.platform in {'win32', 'cygwin'} condition. See the attached pyio_setmode.diff It is not clear why the absence of _setmode(fd, os.O_BINARY) is not detected by tests. (a) a corresponding test should be added |
It's only a problem when an existing text-mode file descriptor is passed in. For example, in text mode the CRT handles b'\x1a' as an EOF marker: Python 3.5.0b4 (v3.5.0b4:c0d641054635, Jul 26 2015, 07:11:12)
[MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, _pyio
>>> _ = open('testfile', 'wb').write(b'abc\x1adef')
>>> fd = os.open('testfile', os.O_RDONLY|os.O_TEXT)
>>> f = _pyio.open(fd, 'rb')
>>> f.read()
b'abc'
>>> f.close()
>>> f = _pyio.open('testfile', 'rb')
>>> f.read()
b'abc\x1adef' The setmode call ensures a file descriptor is in the expected binary mode: >>> import msvcrt
>>> fd = os.open('testfile', os.O_RDONLY|os.O_TEXT)
>>> old_mode = msvcrt.setmode(fd, os.O_BINARY)
>>> old_mode == os.O_TEXT
True
>>> f = _pyio.open(fd, 'rb')
>>> f.read()
b'abc\x1adef' |
New changeset 687da8760a58 by Serhiy Storchaka in branch '3.5': New changeset 2dd9294f679d by Serhiy Storchaka in branch 'default': |
Good catch. Thank you for your report Cosimo. Thank you for your patch Akira. |
FWIW this patch broke the _pyio module on Cygwin, as the msvcrt module is not built on Cygwin. AFAICT this is only a problem for Python built with MSVCRT, which Cygwin does not use. When test case works as expected on Cygwin without this. |
"FWIW this patch broke the _pyio module on Cygwin," Please open a new issue, this one is closed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: