Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7262] codecs.open() + eol (windows)

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 4, 2009, 6:13 AM

Post #1 of 3 (64 views)
Permalink
[issue7262] codecs.open() + eol (windows)

New submission from shamilbi <shamilbi[at]gmail.com>:

different eol when writing to fp = codecs.open(.., 'w', 'cp866')
(windows, python-2.6.4)

def write(fp):
fp.write("""\
a
""")

# eol=0d0a (windows, python-2.6.4)
with open('0d0a.tmp', 'w') as fp:
write(fp)

# eol=0d0a (windows, python-2.6.4)
with codecs.open('0d0a-codecs.tmp', 'w') as fp:
write(fp)

# --- BUG ---
# eol=0a (windows, python-2.6.4)
with codecs.open('0a-codecs.tmp', 'w', 'cp866') as fp:
write(fp)

----------
components: Library (Lib)
files: eol-bug.py
messages: 94888
nosy: shamilbi
severity: normal
status: open
title: codecs.open() + eol (windows)
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file15256/eol-bug.py

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue7262>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 4, 2009, 10:02 AM

Post #2 of 3 (48 views)
Permalink
[issue7262] codecs.open() + eol (windows) [In reply to]

Amaury Forgeot d'Arc <amauryfa[at]gmail.com> added the comment:

The docs say::
Files are always opened in binary mode, even if no binary mode was
specified. This is done to avoid data loss due to encodings using
8-bit values. This means that no automatic conversion of '\n' is done
on reading and writing.

But this does not match the code of codecs.open()::
if encoding is not None and \
'b' not in mode:
# Force opening of the file in binary mode
mode = mode + 'b'

When the encoding is None, the file is opened in text mode.
Marc-Andre, what do you think? is it a documentation bug instead?

----------
assignee: -> lemburg
nosy: +amaury.forgeotdarc, lemburg

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue7262>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 4, 2009, 10:18 AM

Post #3 of 3 (47 views)
Permalink
[issue7262] codecs.open() + eol (windows) [In reply to]

Marc-Andre Lemburg <mal[at]egenix.com> added the comment:

Amaury Forgeot d'Arc wrote:
>
> Amaury Forgeot d'Arc <amauryfa[at]gmail.com> added the comment:
>
> The docs say::
> Files are always opened in binary mode, even if no binary mode was
> specified. This is done to avoid data loss due to encodings using
> 8-bit values. This means that no automatic conversion of '\n' is done
> on reading and writing.
>
> But this does not match the code of codecs.open()::
> if encoding is not None and \
> 'b' not in mode:
> # Force opening of the file in binary mode
> mode = mode + 'b'
>
> When the encoding is None, the file is opened in text mode.
> Marc-Andre, what do you think? is it a documentation bug instead?

Agreed, it's a documentation bug. If no encoding is specified,
codecs.open() works just like the standard open() (except for
the default value of mode, but that's documented).

The idea was to provide a drop-in replacement for open() - with
the added encoding parameter support.

Perhaps the default mode should have been 'r' to match the
regular open() - I guess it's too late to change that, though.

----------

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue7262>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.