diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-02-27 11:26:58 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-02-27 11:26:58 (GMT) |
commit | c92fc8261dd89cfc1d11a5aee28ed28df4579346 (patch) | |
tree | f4e95bb7adaef961db7a04a54f15280fd7ae41a4 /Lib/codecs.py | |
parent | 9ea3bbafaa7a7e8e1b98dcf993b4aadad85bdf5a (diff) | |
download | cpython-c92fc8261dd89cfc1d11a5aee28ed28df4579346.zip cpython-c92fc8261dd89cfc1d11a5aee28ed28df4579346.tar.gz cpython-c92fc8261dd89cfc1d11a5aee28ed28df4579346.tar.bz2 |
Merged revisions 78461,78482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78461 | florent.xicluna | 2010-02-26 11:40:58 +0100 (ven, 26 fév 2010) | 2 lines
#691291: codecs.open() should not convert end of lines on reading and writing.
........
r78482 | florent.xicluna | 2010-02-27 12:19:18 +0100 (sam, 27 fév 2010) | 2 lines
Add entry for issue #691291.
........
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r-- | Lib/codecs.py | 13 |
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 |