Merge pull request #23740 from jfindlay/binary_write

Binary write
This commit is contained in:
Thomas S Hatch 2015-05-15 12:10:44 -06:00
commit 916b1c4f7c

View file

@ -1015,7 +1015,7 @@ def fopen(*args, **kwargs):
NB! We still have small race condition between open and fcntl.
'''
# Remove lock, uid, gid and mode from kwargs if present
# Remove lock from kwargs if present
lock = kwargs.pop('lock', False)
if lock is True:
@ -1028,6 +1028,19 @@ def fopen(*args, **kwargs):
)
return flopen(*args, **kwargs)
# ensure 'binary' mode is always used on windows
if is_windows():
if len(args) > 1:
args = list(args)
if 'b' not in args[1]:
args[1] += 'b'
elif kwargs.get('mode', None):
if 'b' not in kwargs['mode']:
kwargs['mode'] += 'b'
else:
# the default is to read
kwargs['mode'] = 'rb'
fhandle = open(*args, **kwargs)
if is_fcntl_available():
# modify the file descriptor on systems with fcntl