On Thu, Mar 17, 2005 at 10:49:24AM -0500, Tom Lane wrote:
> Seems like we have to upgrade that thing to have a complete
> understanding of Python lexical rules --- at least enough to know where
> the line boundaries are. Which is pretty much exactly the same as
> knowing which CRs to strip out. So I guess we have a candidate place
> for a solution.
>
> Anyone want to code it up? I don't know enough Python to do it ...
[Sound of crickets]
More pabulum for pondering:
% cat -v foo.py
print '''line 1^M
line^M2^M
line 3^M
'''^M
% python foo.py | cat -v
line 1
line
2
line 3
% cat -v bar.py
print 'line 1^M'
% python bar.py
File "bar.py", line 1
print 'line 1
^
SyntaxError: EOL while scanning single-quoted string
Line-ending CRs stripped, even inside quotes; mid-line CRs converted
to LF. Tests done with Python 2.4 on FreeBSD 4.11-STABLE; I wonder
what Python on Windows would do. If it behaves the same way, then
a munging algorithm might be CRLF => LF, otherwise CR => LF. Or
we could take Marco's suggestion and do nothing, putting the burden
on the client to send the right thing.
That doesn't address the indentation munging, though. That appears
to be a matter of knowing whether you're inside a quote or not when
a LF appears.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/