[issue5559] IDLE Output Window 's goto fails when path has spaces
Claudio Canepa
report at bugs.python.org
Mon Apr 6 21:01:42 CEST 2009
Claudio Canepa <ccanepacc at gmail.com> added the comment:
On a second look:
1. the code in OutputWindow.py for the 'goto' action looks for a match
with the first regex in
file_line_pats = [
r'file "([^"]*)", line (\d+)',
r'([^\s]+)\((\d+)\)',
r'([^\s]+):\s*(\d+):',
]
and it assumes the first group gives a valid filename, the second a
line number.
2. the potential target lines produced by GrepDialog.py are writen by:
sys.stdout.write("%s: %s: %s\n" % (fn, lineno, line))
where:
fn :a valid filename ( because an open(fn) was issued before), not
guaranted an abspath
lineno : unsigned int
line: a text line in an arbitrary file, but mostly an *.py
Clearly the 3rd regex is the only one that can hit the line produced by
GrepDialog, and clearly will fail in any OS that allows spaces in a
valid path: the regex breaks the first group at the first whitespace.
The tentative fix propossed in the initial post was a minimal change
that allow spaces in the path, but was very ugly and not comunicates a
clear intention.
I like more:
r'(?:\s*)(.+):\s+(\d+):'
wich discards leading whitespace ( feature unused by GrepDialog but
probably handy in pyShell, wich subclasses OutputWindow )
It is a better regex that the original in IDLE, meaning it would hit
more positives, but can fail sometimes:
Supose the GrepDialog found a hit at line 111 in the file c:\foo.py ,
with the text
a = 1 # see 24: 32: 1
The line sent to OutputWindow would be
c:\foo.py: 111: a = 1 # see 24: 32: 1
and the regex will capture the groups:
filename = "c:\foo.py: 111: a = 1 # see 24"
linenum = "32"
The first group fails to capture the filename.
I can live with such special case failures, but anyway:
In windows, changing the regex to break the first group at the
first ': ' would fix the thing ( ': ' cant happen in a fn that pass open
(fn) )
How about other OSes ?
------
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5559>
_______________________________________
More information about the Python-bugs-list
mailing list