home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1770 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.5 KB  |  53 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import IPython.ipapi as IPython
  5. import pprint
  6. ip = IPython.ipapi.get()
  7. curdata = []
  8.  
  9. def line_edit_f(self, cmd):
  10.     global curdata
  11.     if not cmd:
  12.         print 'Magic line editor (for lists of strings)'
  13.         if curdata:
  14.             print 'current data is:'
  15.             pprint.pprint(curdata)
  16.         else:
  17.             print "No current data, you should set it by running '%led s'"
  18.             print 'When you have your data in _ (result of last computation).'
  19.         return None
  20.     if cmd == 's':
  21.         curdata = ip.ev('_')
  22.         print 'Data set from last result (_)'
  23.         newlines = curdata
  24.     elif cmd.isalpha():
  25.         cmd = 'l.' + cmd + '()'
  26.         print 'cmd translated =>', cmd
  27.     
  28.     newlines = []
  29.     for l in curdata:
  30.         
  31.         try:
  32.             l2 = eval(cmd)
  33.         except Exception:
  34.             cmd
  35.             e = cmd
  36.             print 'Dropping exception', e, 'on line:', l
  37.             continue
  38.         except:
  39.             cmd
  40.  
  41.         newlines.append(l2)
  42.     
  43.     return newlines
  44.  
  45.  
  46. def line_edit_complete_f(self, event):
  47.     if event.symbol.startswith('l.'):
  48.         return [ 'l.' + func for func in dir('') ]
  49.     return [] + [ 'l.' + func for func in dir('') ]
  50.  
  51. ip.set_hook('complete_command', line_edit_complete_f, str_key = '%led')
  52. ip.expose_magic('led', line_edit_f)
  53.