home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from IPython import ipapi
- import os
- import bisect
- import sys
- from genutils import Term, shell
- from pprint import PrettyPrinter
- __all__ = [
- 'editor',
- 'fix_error_editor',
- 'synchronize_with_editor',
- 'result_display',
- 'input_prefilter',
- 'shutdown_hook',
- 'late_startup_hook',
- 'generate_prompt',
- 'generate_output_prompt',
- 'shell_hook',
- 'show_in_pager',
- 'pre_prompt_hook',
- 'pre_runcode_hook',
- 'clipboard_get']
- pformat = PrettyPrinter().pformat
-
- def editor(self, filename, linenum = None):
- editor = self.rc.editor
- if linenum is None or editor == 'notepad':
- linemark = ''
- else:
- linemark = '+%d' % int(linenum)
- if ' ' in editor and os.path.isfile(editor) and editor[0] != '"':
- editor = '"%s"' % editor
-
- if os.system('%s %s %s' % (editor, linemark, filename)) != 0:
- raise ipapi.TryNext()
- os.system('%s %s %s' % (editor, linemark, filename)) != 0
-
- import tempfile
-
- def fix_error_editor(self, filename, linenum, column, msg):
-
- def vim_quickfix_file():
- t = tempfile.NamedTemporaryFile()
- t.write('%s:%d:%d:%s\n' % (filename, linenum, column, msg))
- t.flush()
- return t
-
- if os.path.basename(self.rc.editor) != 'vim':
- self.hooks.editor(filename, linenum)
- return None
- t = vim_quickfix_file()
-
- try:
- if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name):
- raise ipapi.TryNext()
- os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name)
- finally:
- t.close()
-
-
-
- def synchronize_with_editor(self, filename, linenum, column):
- pass
-
-
- class CommandChainDispatcher:
-
- def __init__(self, commands = None):
- if commands is None:
- self.chain = []
- else:
- self.chain = commands
-
-
- def __call__(self, *args, **kw):
- for prio, cmd in self.chain:
-
- try:
- ret = cmd(*args, **kw)
- return ret
- continue
- except ipapi.TryNext:
- exc = None
- if exc.args or exc.kwargs:
- args = exc.args
- kw = exc.kwargs
-
- exc.kwargs
-
-
-
- raise ipapi.TryNext
-
-
- def __str__(self):
- return str(self.chain)
-
-
- def add(self, func, priority = 0):
- bisect.insort(self.chain, (priority, func))
-
-
- def __iter__(self):
- return iter(self.chain)
-
-
-
- def result_display(self, arg):
- if self.rc.pprint:
- out = pformat(arg)
- if '\n' in out:
- Term.cout.write('\n')
-
- print >>Term.cout, out
- else:
- print >>Term.cout, repr(arg)
-
-
- def input_prefilter(self, line):
- return line
-
-
- def shutdown_hook(self):
- pass
-
-
- def late_startup_hook(self):
- pass
-
-
- def generate_prompt(self, is_continuation):
- ip = self.api
- if is_continuation:
- return str(ip.IP.outputcache.prompt2)
- return str(ip.IP.outputcache.prompt1)
-
-
- def generate_output_prompt(self):
- ip = self.api
- return str(ip.IP.outputcache.prompt_out)
-
-
- def shell_hook(self, cmd):
- shell(cmd, header = self.rc.system_header, verbose = self.rc.system_verbose)
-
-
- def show_in_pager(self, s):
- raise ipapi.TryNext
-
-
- def pre_prompt_hook(self):
- pass
-
-
- def pre_runcode_hook(self):
- pass
-
-
- def clipboard_get(self):
- osx_clipboard_get = osx_clipboard_get
- tkinter_clipboard_get = tkinter_clipboard_get
- win32_clipboard_get = win32_clipboard_get
- import IPython.clipboard
- if sys.platform == 'win32':
- chain = [
- win32_clipboard_get,
- tkinter_clipboard_get]
- elif sys.platform == 'darwin':
- chain = [
- osx_clipboard_get,
- tkinter_clipboard_get]
- else:
- chain = [
- tkinter_clipboard_get]
- dispatcher = CommandChainDispatcher()
- for func in chain:
- dispatcher.add(func)
-
- text = dispatcher()
- return text
-
-