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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. from copy import copy
  6. from util import InputList
  7.  
  8. class History(object):
  9.     
  10.     def __init__(self, input_cache = None, output_cache = None):
  11.         self.namespace_additions = dict(_ = None, __ = None, ___ = None)
  12.         if input_cache is None:
  13.             input_cache = InputList([])
  14.         
  15.         self.input_cache = input_cache
  16.         if output_cache is None:
  17.             output_cache = { }
  18.         
  19.         self.output_cache = output_cache
  20.  
  21.     
  22.     def get_history_item(self, index):
  23.         if index >= 0 and index < len(self.input_cache):
  24.             return self.input_cache[index]
  25.  
  26.  
  27.  
  28. class InterpreterHistory(History):
  29.     
  30.     def setup_namespace(self, namespace):
  31.         namespace['In'] = self.input_cache
  32.         namespace['_ih'] = self.input_cache
  33.         namespace['Out'] = self.output_cache
  34.         namespace['_oh'] = self.output_cache
  35.  
  36.     
  37.     def update_history(self, interpreter, python):
  38.         number = interpreter.current_cell_number
  39.         new_obj = interpreter.display_trap.obj
  40.         if new_obj is not None:
  41.             self.namespace_additions['___'] = self.namespace_additions['__']
  42.             self.namespace_additions['__'] = self.namespace_additions['_']
  43.             self.namespace_additions['_'] = new_obj
  44.             self.output_cache[number] = new_obj
  45.         
  46.         interpreter.user_ns.update(self.namespace_additions)
  47.         self.input_cache.add(number, python)
  48.  
  49.     
  50.     def get_history_item(self, index):
  51.         if index > 0 and index < len(self.input_cache) - 1:
  52.             return self.input_cache[-index]
  53.  
  54.     
  55.     def get_input_cache(self):
  56.         return copy(self.input_cache)
  57.  
  58.     
  59.     def get_input_after(self, index):
  60.         return list.__getslice__(self.input_cache, index, len(self.input_cache))
  61.  
  62.  
  63.  
  64. class FrontEndHistory(History):
  65.     
  66.     def add_items(self, item_list):
  67.         self.input_cache.extend(item_list)
  68.  
  69.  
  70.