[IPython-user] auto-quote broke and fix

Jerry McRae qrs0xyc02 at sneakemail.com
Fri Apr 22 16:00:44 CDT 2005


Hi,

I just starting using IPython and somehow got 0.6.5.  When I went to
the home page I found and downloaded 0.6.13.  I then noticed the
auto-quote function ( ,ord a --> ord('a') ) no longer worked.  I liked
that!  Since it worked before, I figured I could see what changed.
And since I saw no messages or entries in the bug tracking for it,
maybe I could find a solution.

Well, that took a bit of searching for a newbie, but I found and fixed
the , and / prefix, and while I was in there mucking around, and added
a ; to quote the whole command, I.E
;runcommand this is a test  ==> runcommand("this is a test")

#####
Changes to fix , prefix:
1799> if pre == self.ESC_QUOTE:
         ^
         iFun[0]
and add [1:] to iFun two lines down

#####
Changes to fix / prefix:
before 1811> if theRest.endswith.....
added: if iFun[0] == self.ESC_PAREN: iFun = iFun[1:]

#####
additions for ; prefix:
just after the block at 1799 I added:
        elif iFun[0] == self.ESC_1QUOTE:
            # Auto-quote whole string
            newcmd = '%s("%s")\n' % (iFun[1:],theRest)

I then Defined and added ESC_1QUOTE to esc_handlers.  I hope this
helps others who missed that function.

Below is a WinMerge patch of the differences:
-- 
Jerry
Win XP, python 2.3.4
___________________________
Let the people know the truth and the country is safe.  --Abraham Lincoln

*** C:\Python23\Lib\site-packages\IPython\copy of iplib.py      Thu Apr 21 21:46:39 2005
--- C:\Python23\Lib\site-packages\IPython\iplib.py      Thu Apr 21 23:39:01 2005
***************
*** 558,559 ****
--- 558,560 ----
          self.ESC_PAREN = '/'
+         self.ESC_1QUOTE = ';'
  
***************
*** 562,563 ****
--- 563,565 ----
                               self.ESC_QUOTE:self.handle_auto,
+                              self.ESC_1QUOTE:self.handle_auto,
                               self.ESC_MAGIC:self.handle_magic,
***************
*** 1798,1802 ****
  
!         if pre == self.ESC_QUOTE:
!             # Auto-quote
!             newcmd = '%s("%s")\n' % (iFun,'", "'.join(theRest.split()) )
          else:
--- 1800,1807 ----
  
!         if iFun[0] == self.ESC_QUOTE:
!             # Auto-quote each word
!             newcmd = '%s("%s")\n' % (iFun[1:],'", "'.join(theRest.split()) )
!         elif iFun[0] == self.ESC_1QUOTE:
!             # Auto-quote whole string
!             newcmd = '%s("%s")\n' % (iFun[1:],theRest)
          else:
***************
*** 1809,1810 ****
--- 1814,1816 ----
                  return '%s %s\n' % (iFun,theRest)
+             if iFun[0] == self.ESC_PAREN: iFun = iFun[1:]
              if theRest.endswith(';'):




More information about the IPython-user mailing list