summaryrefslogtreecommitdiffstats
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-02-26 10:40:58 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-02-26 10:40:58 (GMT)
commitf4b6186d9c3677f96183d4c9e7267c0b960c9132 (patch)
treeef30da79386105985047553daf257cfee5dedda8 /Lib/codecs.py
parentc994186dad39eee832112318d63f96189d8f2b57 (diff)
downloadcpython-f4b6186d9c3677f96183d4c9e7267c0b960c9132.zip
cpython-f4b6186d9c3677f96183d4c9e7267c0b960c9132.tar.gz
cpython-f4b6186d9c3677f96183d4c9e7267c0b960c9132.tar.bz2
#691291: codecs.open() should not convert end of lines on reading and writing.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 557ccf7..a67240a 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -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