Status: Accepted
Owner: ----
Labels: Type-Refactoring Priority-Medium Target-2.8
New issue 1167 by pekka.klarck: Consistent opening of files for reading and
writing
http://code.google.com/p/robotframework/issues/detail?id=1167
Currently we use three different approaches when opening text files for
reading and writing. Depending on the approach encoding content and
handling newlines differ:
1) "Normal" open e.g. `open(path, 'w')`
- Content must be encoded when read/written.
- Newlines are translated automatically regardless the OS.
2) Binary mode e.g. `open(path, 'wb')`
- Content must be encoded when read/written.
- Must use os.linesep instead of `\n` to get correct line endings on
Windows.
3) codecs.open e.g. `codecs.open(path, 'w', 'utf-8')`
- Content must not be encoded.
- Because codes.open implies binary mode, must use os.linesep instead of
`\n`.
This mixture means that all utilities accepting open file objects must
allow configuring encoding and handling newlines. This obviously makes them
more complex and can cause bugs like issue 1162.
I propose we change the code base so that we only use the option 1), plain
old open without binary mode. After that we don't need to think about
os.linesep anymore but can just use `\n` and we'll still get correct line
endings on Windows. We can keep encoding configurable, but the default
value must be UTF-8.