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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from IPython import ipapi
  5. import os
  6. import re
  7. import textwrap
  8. import ipy_defaults
  9.  
  10. def main():
  11.     ip = ipapi.get()
  12.     o = ip.options
  13.     o.autocall = 2
  14.     
  15.     try:
  16.         ip.ex('from IPython.external.path import path')
  17.     except ImportError:
  18.         pass
  19.  
  20.     import envpersist
  21.     import ipy_which
  22.     import ipy_app_completers
  23.     import ipy_rehashdir
  24.     ip.ex('import os')
  25.     ip.ex("def up(): os.chdir('..')")
  26.     ip.user_ns['LA'] = LastArgFinder()
  27.     ip.user_ns['_prompt_title'] = ''
  28.     o.prompt_in1 = '\\C_Green${_prompt_title}\\C_LightBlue[\\C_LightCyan\\Y2\\C_LightBlue]\\C_Green|\\#> '
  29.     o.prompt_in2 = '\\C_Green|\\C_LightGreen\\D\\C_Green> '
  30.     o.prompt_out = '<\\#> '
  31.     Release = Release
  32.     import IPython
  33.     import sys
  34.     o.banner = 'IPython %s   [on Py %s]\n' % (Release.version, sys.version.split(None, 1)[0])
  35.     ip.IP.default_option('cd', '-q')
  36.     ip.IP.default_option('macro', '-r')
  37.     o.prompts_pad_left = '1'
  38.     o.separate_in = '0'
  39.     o.separate_out = '0'
  40.     o.separate_out2 = '0'
  41.     db = ip.db
  42.     syscmds = db.get('syscmdlist', [])
  43.     if not syscmds:
  44.         print textwrap.dedent('\n        System command list not initialized, probably the first run...\n        running %rehashx to refresh the command list. Run %rehashx\n        again to refresh command list (after installing new software etc.)\n        ')
  45.         ip.magic('rehashx')
  46.         syscmds = db.get('syscmdlist')
  47.     
  48.     if os.name == 'posix':
  49.         
  50.         mapper = lambda s: s
  51.     else:
  52.         
  53.         def mapper(s):
  54.             return s.lower()
  55.  
  56.     for cmd in syscmds:
  57.         (noext, ext) = os.path.splitext(cmd)
  58.         if ext.lower() == '.exe':
  59.             cmd = noext
  60.         
  61.         key = mapper(cmd)
  62.         if key not in ip.IP.alias_table:
  63.             ip.defalias(key.replace('.', ''), cmd)
  64.             continue
  65.     
  66.     ip.load('IPython.external.mglob')
  67.     if sys.platform == 'win32':
  68.         if 'cygwin' in os.environ['PATH'].lower():
  69.             ip.defalias('d', 'ls -F --color=auto')
  70.         else:
  71.             ip.load('ipy_fsops')
  72.             ip.defalias('d', 'dir /w /og /on')
  73.     
  74.     ip.set_hook('input_prefilter', slash_prefilter_f)
  75.     extend_shell_behavior(ip)
  76.  
  77.  
  78. class LastArgFinder:
  79.     
  80.     def __call__(self, hist_idx = None):
  81.         ip = ipapi.get()
  82.         if hist_idx is None:
  83.             return str(self)
  84.         return ip.IP.input_hist_raw[hist_idx].strip().split()[-1]
  85.  
  86.     
  87.     def __str__(self):
  88.         ip = ipapi.get()
  89.         for cmd in reversed(ip.IP.input_hist_raw):
  90.             parts = cmd.strip().split()
  91.             if len(parts) < 2 or parts[-1] in ('$LA', 'LA()'):
  92.                 continue
  93.             
  94.             return parts[-1]
  95.         
  96.         return ''
  97.  
  98.  
  99.  
  100. def slash_prefilter_f(self, line):
  101.     import IPython.genutils as IPython
  102.     if re.match('(?:[.~]|/[a-zA-Z_0-9]+)/', line):
  103.         return '_ip.system(' + IPython.genutils.make_quoted_expr(line) + ')'
  104.     raise ipapi.TryNext
  105.  
  106.  
  107. def extend_shell_behavior(ip):
  108.     ip.IP.__sig__ = 40965
  109.     ip.IP.user_ns['__builtins__'].__dict__['__sig__'] = ip.IP.__sig__
  110.     ItplNS = ItplNS
  111.     import IPython.Itpl
  112.     shell = shell
  113.     import IPython.genutils
  114.     
  115.     ip.IP.var_expand = lambda cmd, lvars = None, depth = (None, None, 2): str(ItplNS(cmd, ip.IP.user_ns, get_locals()))
  116.     
  117.     def get_locals():
  118.         import sys
  119.         
  120.         getsig = lambda fno: sys._getframe(fno + 1).f_globals['__builtins__'].__dict__['__sig__']
  121.         
  122.         getlvars = lambda fno: sys._getframe(fno + 1).f_locals
  123.         frame_no = 1
  124.         sig = ip.IP.__sig__
  125.         fsig = ~sig
  126.         while fsig != sig:
  127.             
  128.             try:
  129.                 fsig = getsig(frame_no)
  130.             continue
  131.             except (AttributeError, KeyError):
  132.                 ((None,),)
  133.                 ((None,),)
  134.                 frame_no += 1
  135.                 continue
  136.                 except ValueError:
  137.                     return { }
  138.                 
  139.                 None<EXCEPTION MATCH>ValueError
  140.             first_frame = frame_no
  141.             try:
  142.                 while sig == getsig(frame_no + 1):
  143.                     frame_no += 1
  144.                     continue
  145.                     ((None,),)<EXCEPTION MATCH>(AttributeError, KeyError)
  146.             except (AttributeError, KeyError, ValueError):
  147.                 ((None,),)<EXCEPTION MATCH>(AttributeError, KeyError)
  148.                 ((None,),)<EXCEPTION MATCH>(AttributeError, KeyError)
  149.                 ((None,),)
  150.             except:
  151.                 ((None,),)
  152.  
  153.             lvars = { }
  154.             for fno in range(frame_no, first_frame - 1, -1):
  155.                 lvars.update(getlvars(fno))
  156.             
  157.         return lvars
  158.  
  159.     
  160.     def _runlines(lines):
  161.         ip.IP.resetbuffer()
  162.         lines = lines.split('\n')
  163.         more = 0
  164.         command = ''
  165.         for line in lines:
  166.             if command != '':
  167.                 line = line.strip()
  168.             
  169.             if line and line[-1] == '\\':
  170.                 command += line[0:-1] + ' '
  171.                 more = True
  172.                 continue
  173.                 continue
  174.             command += line
  175.             if command or more:
  176.                 ip.IP.input_hist_raw.append('# ' + command + '\n')
  177.                 more = ip.IP.push(ip.IP.prefilter(command, more))
  178.                 command = ''
  179.                 if more is None:
  180.                     break
  181.                 
  182.             more is None
  183.         
  184.         if more:
  185.             ip.IP.push('\n')
  186.         
  187.  
  188.     ip.IP.runlines = _runlines
  189.  
  190. main()
  191.