|
From: Nicola L. <ni...@te...> - 2008-01-21 05:25:09
|
> Nicola Larosa wrote:
>> I've been sitting on a bug report about newlines on Windows for some time
>> (sorry). It's in Italian, I'll translate it and send it here soon.
Michael Foord wrote:
> Ok - cool. But how many problems with newlines can there *be*? :-)
That one, I'm not qualified to answer. ;-) Bug report follows.
---
When creating a ConfigObj, there's some code that tries to detect what
kind of newline is used in the input file, in order to use the same kind
when the ConfigObj is saved.
Now, in the "write" method the output file is open as binary, for
encoding reasons:
Lines from 1848 to 1050:
h = open(self.filename, 'wb')
h.write(output)
h.close()
and the lines are added to the output buffer appending to each one the
self.newlines character, the one detected in the constructor (one among
"\n", "\r" and "\r\n").
The problem is that in all systems the output newline character in
self.newlines will always be "\n", because the input file "infile",
passed in the constructor, is open in text mode, therefore the newline
characters it contains will already have been converted to "\n":
Lines 1022 and 1023:
if os.path.isfile(infile):
infile = open(infile).read() or []
So, I changed those two lines to:
if os.path.isfile(infile):
infile = open(infile,"rb").read() or []
That way, the input file too is open in binary mode, and the newline
character put into self.newlines is the actually used one.
All of that because on windows [lowercased in the original ;-) ], when a
ConfigObj is written to file, the newline characters were shown as "\n",
that in notepad are seen as annoying little boxes. :-)
---
I hope it's useful.
--
Nicola Larosa - http://www.tekNico.net/
I was a pilgrim, dedicated to the service of something larger than
myself, something that transcended the mundane material world,
something that could still fill me with awe. Music was my Christ on
the cross, my Wailing Wall, my Mecca. A universe in which music
existed could not be evil. -- Joe Jackson, A Cure for Gravity, 1999
|