home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- import linecache
- import sys
- from twisted.internet.error import ConnectionRefusedError
- from IPython.ultraTB import _fixed_getinnerframes, findsource
- from IPython import ipapi
- from IPython.kernel import error
-
- def remote():
- m = 'Special exception to stop local execution of parallel code.'
- raise error.StopLocalExecution(m)
-
-
- def strip_whitespace(source, require_remote = True):
- remote_mark = 'remote()'
- wsource = [ l.expandtabs(4) for l in source ]
- done = False
- for line in wsource:
- for col, char in enumerate(line):
- if char != ' ':
- done = True
- break
- continue
- None if line.isspace() else []
-
- if done:
- break
- continue
-
- for lno, line in enumerate(wsource):
- lead = line[:col]
- if lead.isspace():
- continue
- continue
- if not lead.lstrip().startswith('#'):
- break
- continue
-
- src_lines = [ l[col:] for l in wsource[:lno + 1] ]
- return ''.join(out_lines)
-
-
- class RemoteContextBase(object):
-
- def __init__(self):
- self.ip = ipapi.get()
-
-
- def _findsource_file(self, f):
- linecache.checkcache()
- s = findsource(f.f_code)
- lnum = f.f_lineno
- wsource = s[0][f.f_lineno:]
- return strip_whitespace(wsource)
-
-
- def _findsource_ipython(self, f):
- ipapi = ipapi
- import IPython
- self.ip = ipapi.get()
- buf = self.ip.IP.input_hist_raw[-1].splitlines()[1:]
- wsource = [ l + '\n' for l in buf ]
- return strip_whitespace(wsource)
-
-
- def findsource(self, frame):
- local_ns = frame.f_locals
- global_ns = frame.f_globals
- if frame.f_code.co_filename == '<ipython console>':
- src = self._findsource_ipython(frame)
- else:
- src = self._findsource_file(frame)
- return src
-
-
- def __enter__(self):
- raise NotImplementedError
-
-
- def __exit__(self, etype, value, tb):
- if issubclass(etype, error.StopLocalExecution):
- return True
-
-
-
- class RemoteMultiEngine(RemoteContextBase):
-
- def __init__(self, mec):
- self.mec = mec
- RemoteContextBase.__init__(self)
-
-
- def __enter__(self):
- src = self.findsource(sys._getframe(1))
- return self.mec.execute(src)
-
-
-