Comment 2 for bug 482215

Revision history for this message
Jan Thor (jan-janthor) wrote :

When I run scour from the command line (or call it from another Python script) under Windows, the line endings become \r\r\n (that is, CR-CR-LF), which appear as additional blank lines in some text editors and is obviously wrong.

I think the cause is this:

Scour produces a giant string with os.linesep as line separator, which happens to be '\r\n' under Windows, but Python internally uses \n as line separator, and, when writing a file to disk in text mode, magically replaces \n with \r\n, which turns \r\n into \r\r\n. A simple fix would be to use '\n' instead of os.linesep within the function scourString (os.linesep appears three times within this function, and another three times within serializeXML, each occurrence should simply be replaced with '\n').

Another possibility would be to prevent Python from doing its magic replacement by replacing the line

    outfile = maybe_gziped_file(options.outfilename, "w")

in parse_args with

    outfile = maybe_gziped_file(options.outfilename, "wb")

Personally, I prefer SVG files with just \n (=LF, the Unix convention) as the line ending, even under Windows, since its shorter and my text editor handles it well, so I applied *both* changes to my own copy of scour. As far as I'm aware, the current version of Inkscape also saves (non-scoured) SVG files with just \n under Windows.