[Python-bugs-list] Fwd: Debian Bug#46993: py_compile.compile() won't compile files with CR+LF line endings (PR#101)
flight@mathi.uni-heidelberg.de
flight@mathi.uni-heidelberg.de
Mon, 11 Oct 1999 09:10:34 -0400 (EDT)
Full_Name: Gregor Hoffleit
Version: 1.5.2
OS: Debian GNU/Linux potato
[This was recorded as Debian bug#46993, cf.
http://www.debian.org/Bugs/db/46/46993.html]
Package: python-base
Version: 1.5.2-6
Severity: normal
On Unix systems, py_compile.compile() (and therefore compileall.py) won't
compile files with DOS/Windows lineendings (CR+LF). Commands like "import"
or "exec" will work, though.
The problem seems to be that py_compile.compile read()'s the whole file at
once and passes it as a string to __builtin__.compile(), while "import"
calls __builtin__.compile() for a file, so that __builtin__.compile seems to
do some magic while reading the file.
For a quick testcase:
import __builtin__
f=open("test.py","w")
f.write('print "Hello"\015\012')
f.close()
f=open("test.py")
c=f.read()
f.close()
__builtin__.compile(c,"test.py","exec")
results in:
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "<stdin>", line 9, in x
File "<string>", line 1
print "Hello"
^
SyntaxError: invalid syntax
while "import test" works fine and results in test.pyc.
Certainly the file.read() in py_compile.compile() isn't good enough for this
case.
Gregor