[IPython-dev] IPython bug?
gb at cs.unc.edu
Sat May 24 15:46:04 EDT 2003
On Sat, 24 May 2003 13:08:15 -0600 "Fernando Perez"
<fperez at colorado.edu> wrote:
> Could you try instead the following, and see what happens? I prefer it
> b/c it breaks less situations where the user may be honestly trying to
> use escapes to handle special characters in his filenames. I simply
> pad the input string around the edges with whitespace to prevent the
> \'s from screwing the quotes up. It seems to work ok for me in most
> cases, and it actually simplifies the code with 2 less ifs/function
> calls per user input.
> [IPython]> diff -Naur iplib.py~ iplib.py
> --- iplib.py~ 2003-05-16 21:55:33.000000000 -0600
> +++ iplib.py 2003-05-24 13:05:05.000000000 -0600
> @@ -1078,11 +1078,8 @@
> parameter_s = ''
> scommand = line
> if hasattr(self, scommand):
> - if parameter_s.startswith('"'):
> - parameter_s = ' ' + parameter_s
> - if parameter_s.endswith('"'):
> - parameter_s += ' '
> - return shell+scommand+'(parameter_s="""%s""")' % (parameter_s,)
> + parameter_s = " %s " % parameter_s
> + return shell+scommand+'(parameter_s="""%s""")' % parameter_s
> return shell+line+'()'
That won't do the job. Consider a line like:
In cd foo\next
A perfectly legal thing for a Windows user to type, or for completion
to return. When you convert that into a string, you'll have a newline
character in the middle! Ack!
I see what you're saying about my fix though. If a magic command took a
string argument, and the user wanted to escape something in the string.
It would be bad. Combined with automatic quoting this seems to really
produce a dilemma. Can you think of a case where this happens?
Maybe we should avoid \ as much as possible. I can make file name
completion return /. We can encourage users to type / and warn them
they better type \\ if they want to use it. I'd like to, one day, make
a version of the commands that deal with paths that use / instead of \.
They pretty much all accept / but they produce \.
Oh, but consider a ! escape. Sometimes the windows shell insists on \.
It is pretty rare though.
The complicated rule would be outside quotation marks (of any kind)
characters stand for themselves. There are no escapes. Inside quotation
marks the usual escape conventions apply.
This would require users to quote strings they wanted to use escapes
in, which seems reasonable to me. And it would allow us to change \ to
\\ everywhere in unquoted strings (like file names).
Getting the quotes right probably requires character by character
processing of the line.
What do you think?
More information about the IPython-dev