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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import IPython.ipapi as IPython
  5. import gc
  6. ip = IPython.ipapi.get()
  7.  
  8. def clear_f(self, arg):
  9.     api = self.getapi()
  10.     user_ns = self.user_ns
  11.     for target in arg.split():
  12.         if target == 'out':
  13.             print 'Flushing output cache (%d entries)' % len(user_ns['_oh'])
  14.             self.outputcache.flush()
  15.             continue
  16.         if target == 'in':
  17.             print 'Flushing input history'
  18.             pc = self.outputcache.prompt_count + 1
  19.             for n in range(1, pc):
  20.                 key = '_i' + `n`
  21.                 user_ns.pop(key, None)
  22.                 
  23.                 try:
  24.                     del user_ns[key]
  25.                 continue
  26.                 continue
  27.  
  28.             
  29.             self.input_hist[:] = [
  30.                 '\n'] * pc
  31.             self.input_hist_raw[:] = [
  32.                 '\n'] * pc
  33.             continue
  34.         if target == 'array':
  35.             
  36.             try:
  37.                 ndarray = ndarray
  38.                 import numpy
  39.                 for x, val in user_ns.items():
  40.                     if isinstance(val, ndarray):
  41.                         del user_ns[x]
  42.                         continue
  43.             except AttributeError:
  44.                 print 'Clear array only works if Numpy is available.'
  45.             except:
  46.                 None<EXCEPTION MATCH>AttributeError
  47.             
  48.  
  49.         None<EXCEPTION MATCH>AttributeError
  50.         if target == 'shadow_compress':
  51.             print 'Compressing shadow history'
  52.             api.db.hcompress('shadowhist')
  53.             continue
  54.         if target == 'shadow_nuke':
  55.             print 'Erased all keys from shadow history '
  56.             for k in ip.db.keys('shadowhist/*'):
  57.                 del ip.db[k]
  58.             
  59.         if target == 'dhist':
  60.             print 'Clearing directory history'
  61.             del user_ns['_dh'][:]
  62.             continue
  63.     
  64.     gc.collect()
  65.  
  66. ip.expose_magic('clear', clear_f)
  67. import ipy_completers
  68. ipy_completers.quick_completer('%clear', 'in out shadow_nuke shadow_compress dhist')
  69.