home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- import sys
- import pydoc
- import os
- import re
- import __builtin__
- from IPython.ipmaker import make_IPython
- from IPython.ipapi import IPApi
- from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap
- from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap
- from IPython.genutils import Term
- from linefrontendbase import LineFrontEndBase, common_prefix
-
- def mk_system_call(system_call_function, command):
-
- def my_system_call(args):
- system_call_function('%s %s' % (command, args))
-
- my_system_call.__doc__ = 'Calls %s' % command
- return my_system_call
-
-
- class PrefilterFrontEnd(LineFrontEndBase):
- debug = False
-
- def __init__(self, ipython0 = None, argv = None, *args, **kwargs):
- if argv is None:
- argv = []
-
- iplib = iplib
- import IPython
- iplib.InteractiveShell.isthreaded = True
- LineFrontEndBase.__init__(self, *args, **kwargs)
- self.shell.output_trap = RedirectorOutputTrap(out_callback = self.write, err_callback = self.write)
- self.shell.traceback_trap = SyncTracebackTrap(formatters = self.shell.traceback_trap.formatters)
- self.save_output_hooks()
- if ipython0 is None:
-
- def my_rawinput(x = None):
- return '\n'
-
- old_rawinput = __builtin__.raw_input
- __builtin__.raw_input = my_rawinput
- ipython0 = make_IPython(argv = argv, user_ns = self.shell.user_ns, user_global_ns = self.shell.user_global_ns)
- __builtin__.raw_input = old_rawinput
-
- self.ipython0 = ipython0
- self.ipython0.set_hook(('show_in_pager',), (lambda s, string: self.write('\n' + string)))
- self.ipython0.write = self.write
- self._ip = _ip = IPApi(self.ipython0)
- self._ip.system = self.system_call
- if not sys.platform.startswith('win'):
- self.ipython0.magic_ls = mk_system_call(self.system_call, 'ls -CF')
-
- self.release_output()
- if 'banner' not in kwargs and self.banner is None:
- self.banner = self.ipython0.BANNER
-
- self.start()
-
-
- def show_traceback(self):
- self.ipython0.showtraceback(tb_offset = -1)
- self.release_output()
-
-
- def execute(self, python_string, raw_string = None):
- if self.debug:
- print 'Executing Python code:', repr(python_string)
-
- self.capture_output()
- LineFrontEndBase.execute(self, python_string, raw_string = raw_string)
- self.release_output()
-
-
- def save_output_hooks(self):
- self._PrefilterFrontEnd__old_cout_write = Term.cout.write
- self._PrefilterFrontEnd__old_cerr_write = Term.cerr.write
- self._PrefilterFrontEnd__old_stdout = sys.stdout
- self._PrefilterFrontEnd__old_stderr = sys.stderr
- self._PrefilterFrontEnd__old_help_output = pydoc.help.output
- self._PrefilterFrontEnd__old_display_hook = sys.displayhook
-
-
- def capture_output(self):
- self.save_output_hooks()
- Term.cout.write = self.write
- Term.cerr.write = self.write
- sys.stdout = Term.cout
- sys.stderr = Term.cerr
- pydoc.help.output = self.shell.output_trap.out
-
-
- def release_output(self):
- Term.cout.write = self._PrefilterFrontEnd__old_cout_write
- Term.cerr.write = self._PrefilterFrontEnd__old_cerr_write
- sys.stdout = self._PrefilterFrontEnd__old_stdout
- sys.stderr = self._PrefilterFrontEnd__old_stderr
- pydoc.help.output = self._PrefilterFrontEnd__old_help_output
- sys.displayhook = self._PrefilterFrontEnd__old_display_hook
-
-
- def complete(self, line):
- word = self._get_completion_text(line)
- completions = self.ipython0.complete(word)
-
- key = lambda x: x.replace('_', '')
- completions.sort(key = key)
- if completions:
- prefix = common_prefix(completions)
- line = line[:-len(word)] + prefix
-
- return (line, completions)
-
-
- def prefilter_input(self, input_string):
- input_string = LineFrontEndBase.prefilter_input(self, input_string)
- filtered_lines = []
- self.capture_output()
- self.last_result = dict(number = self.prompt_number)
-
- try:
- for line in input_string.split('\n'):
- filtered_lines.append(self.ipython0.prefilter(line, False).rstrip())
- except:
- self.ipython0.showsyntaxerror()
- self.after_execute()
- finally:
- self.release_output()
-
- filtered_string = '\n'.join(filtered_lines)
- return filtered_string
-
-
- def system_call(self, command_string):
- return os.system(command_string)
-
-
- def do_exit(self):
- self.ipython0.atexit_operations()
-
-
- def _get_completion_text(self, line):
- expression = '\\s|=|,|:|\\((?!.*\\))|\\[(?!.*\\])|\\{(?!.*\\})'
- complete_sep = re.compile(expression)
- text = complete_sep.split(line)[-1]
- return text
-
-
-