This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Cosimo Lupo, akira, eryksun, paul.moore, serhiy.storchaka, steve.dower, tim.golden, vstinner, zach.ware
Date 2015-08-22.03:01:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> It is not clear why the absence of _setmode(fd, os.O_BINARY)
> is not detected by tests.

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 ='testfile', os.O_RDONLY|os.O_TEXT)
    >>> f =, 'rb')
    >>> f.close()

    >>> f ='testfile', 'rb')

The setmode call ensures a file descriptor is in the expected binary mode:

    >>> import msvcrt
    >>> fd ='testfile', os.O_RDONLY|os.O_TEXT)
    >>> old_mode = msvcrt.setmode(fd, os.O_BINARY)
    >>> old_mode == os.O_TEXT
    >>> f =, 'rb')
Date User Action Args
2015-08-22 03:01:07eryksunsetrecipients: + eryksun, paul.moore, vstinner, tim.golden, akira, zach.ware, serhiy.storchaka, steve.dower, Cosimo Lupo
2015-08-22 03:01:07eryksunsetmessageid: <>
2015-08-22 03:01:07eryksunlinkissue24881 messages
2015-08-22 03:01:04eryksuncreate