Stuart> I don't think it is possible for plpythonu to fix this by simply
Stuart> translating the line endings, as this would require significant
Stuart> knowledge of Python syntax to do correctly (triple quoted
Stuart> strings and character escaping I think).
I don't see why not. If you treat the string as a file in text mode, I
think you'd replace all [\r\n]+ with \n, even if it was embedded in a
string:
>>> s
'from math import pi\r\n"""triple-quoted string embedding CR:\rrest of
string"""\r\nprint 2*pi*7\r'
>>> open("foo", "w").write(s)
>>> open("foo", "rU").read()
'from math import pi\n"""triple-quoted string embedding CR:\nrest of
string"""\nprint 2*pi*7\n'
Just re.sub("[\r\n]+", "\n", s) and I think you're good to go.
Skip
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com