mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
#691291: codecs.open() should not convert end of lines on reading and writing.
This commit is contained in:
parent
c994186dad
commit
f4b6186d9c
2 changed files with 24 additions and 4 deletions
|
@ -858,10 +858,15 @@ def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
|
|||
parameter.
|
||||
|
||||
"""
|
||||
if encoding is not None and \
|
||||
'b' not in mode:
|
||||
# Force opening of the file in binary mode
|
||||
mode = mode + 'b'
|
||||
if encoding is not None:
|
||||
if 'U' in mode:
|
||||
# No automatic conversion of '\n' is done on reading and writing
|
||||
mode = mode.strip().replace('U', '')
|
||||
if mode[:1] not in set('rwa'):
|
||||
mode = 'r' + mode
|
||||
if 'b' not in mode:
|
||||
# Force opening of the file in binary mode
|
||||
mode = mode + 'b'
|
||||
file = __builtin__.open(filename, mode, buffering)
|
||||
if encoding is None:
|
||||
return file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue