Well, assuming that it is NOT okay with \r\n in there, then read the whole blob in and use string.replace() on it.
I thought of that too, but quickly dismissed it. You may have a CRLF pair embedded in a triple-quoted string. Those should be left untouched.
Why? When Python compiles a module "normally", line-ends get normalized, and the CRLF pairs on Windows vanish anyway. For example, here's cr.py:
def f(): s = """a b c d """ for ch in s: print ord(ch), print
f() import dis dis.dis(f)
I'm running on Win98 as I type, and the source file has CRLF line ends.
C:\Python16>python misc/cr.py 97 10 98 10 99 10 100 10
That line shows that only the LFs survived. The rest shows why:
0 SET_LINENO 1
3 SET_LINENO 2 6 LOAD_CONST 1 ('a\012b\012c\012d\012') 9 STORE_FAST 0 (s) etc
That is, as far as the generated code is concerned, the CRs never existed.
60-years-of-computers-and-we-still-can't-agree-on-how-to-end-a-line-ly y'rs - tim