classification
Title: work around to compile \r\n file
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, quiver
Priority: normal Keywords: patch

Created on 2004-03-28 06:40 by quiver, last changed 2007-08-23 20:15 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
compile.patch quiver, 2004-03-28 06:40
Messages (2)
msg45687 - (view) Author: George Yoshida (quiver) (Python committer) Date: 2004-03-28 06:40
On Unix-like systems, built-in function compile cannot 
compile files that don't use linefeed as an EOL. But there 
are several codes in the library which assume that input 
files use valid EOL characters.
So when they come across \r\n(or \r) on Unix 
environments, compile causes the parser to raise a 
SyntaxError.

For example:

>>> list(file('a.py'))
['\r\n']
>>> import trace
>>> trace.find_executable_linenos('a.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/trace.py", line 389, in 
find_executable_linenos
    code = compile(prog, filename, "exec")
  File "a.py", line 1

    ^
SyntaxError: invalid syntax

Lib/py_compile.py opens files with 'U' option to handle 
file format differences and I think this is the way to go.

There is one drawback.
When Python is configured without universal newline 
support, this approach doesn't work :-(
msg55198 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-23 20:15
The offending open() call in trace.py is fixed, so closing this.
History
Date User Action Args
2007-08-23 20:15:47georg.brandlsetstatus: open -> closed
resolution: out of date
messages: + msg55198
nosy: + georg.brandl
2004-03-28 06:40:13quivercreate