[IPython-dev] IPython bug?

Fernando Perez fperez at colorado.edu
Sat May 24 14:08:15 CDT 2003


Gary Bishop wrote:
> It *has* to happen on Linux. Try:
> 
> In [1]: @cd foo\<RET>

AH!  Ok, I see it now.  I was using <tab> instead of <ret>, and it all looked 
fine there.

> 
> I bet you'll get the never ending prompt. The problem starts in 
> iplib.py line 1085 where you convert the input into a parameter:
> 
>             return shell+scommand+'(parameter_s="""%s""")' % (parameter_s,)
> 
> If parameter_s ends with a \ then it escapes one of the triple quotes! 
> So the string doesn't end... Pretty twisted. Reverse slash is a sick, 
> sick character.

Indeed, having \ as part of day-to-day objects like paths makes many things 
unnecessarily, stupidly hard and annoying.

> Seems to me that at the point you go from a typed line to a string 
> parameter you have to take care to escape \ and possibly other characters.
> 
> This patch appears to fix the immediate problem:

[snip]

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
          else:
              return shell+line+'()'

Cheers,

f.




More information about the IPython-dev mailing list