]> granicus.if.org Git - python/commitdiff
Support \r in source files. Closes bug #101425.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 15 Sep 2000 06:57:26 +0000 (06:57 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 15 Sep 2000 06:57:26 +0000 (06:57 +0000)
Lib/py_compile.py

index c54d61b5f510aa394fadfc6f70ccc847b8b2c90f..b4531096d71965229970109bbf4d3c2a397ce26c 100644 (file)
@@ -48,6 +48,11 @@ def compile(file, cfile=None, dfile=None):
     except AttributeError:
         timestamp = long(os.stat(file)[8])
     codestring = f.read()
+    # If parsing from a string, line breaks are \n (see parsetok.c:tok_nextc)
+    # Replace will return original string if pattern is not found, so
+    # we don't need to check whether it is found first.
+    codestring = codestring.replace("\r\n","\n")
+    codestring = codestring.replace("\r","\n")
     f.close()
     if codestring and codestring[-1] != '\n':
         codestring = codestring + '\n'