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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import IPython.ipapi as IPython
  5. from IPython.genutils import *
  6. ip = IPython.ipapi.get()
  7. import re
  8.  
  9. def hnd_magic(line, mo):
  10.     var = mo.group('varname')
  11.     cmd = mo.group('cmd')
  12.     expr = make_quoted_expr(cmd)
  13.     return itpl('$var = _ip.magic($expr)')
  14.  
  15.  
  16. def hnd_syscmd(line, mo):
  17.     var = mo.group('varname')
  18.     cmd = mo.group('cmd')
  19.     expr = make_quoted_expr(itpl('sc -l =$cmd'))
  20.     return itpl('$var = _ip.magic($expr)')
  21.  
  22.  
  23. def install_re_handler(pat, hnd):
  24.     ip.meta.re_prefilters.append((re.compile(pat), hnd))
  25.  
  26.  
  27. def init_handlers():
  28.     ip.meta.re_prefilters = []
  29.     install_re_handler('(?P<varname>[\\w\\.]+)\\s*=\\s*%(?P<cmd>.*)', hnd_magic)
  30.     install_re_handler('(?P<varname>[\\w\\.]+)\\s*=\\s*!(?P<cmd>.*)', hnd_syscmd)
  31.  
  32. init_handlers()
  33.  
  34. def regex_prefilter_f(self, line):
  35.     for pat, handler in ip.meta.re_prefilters:
  36.         mo = pat.match(line)
  37.         if mo:
  38.             return handler(line, mo)
  39.     
  40.     raise IPython.ipapi.TryNext
  41.  
  42. ip.set_hook('input_prefilter', regex_prefilter_f)
  43.