home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- from new import instancemethod
- from types import FunctionType
- from twisted.application import service
- from twisted.internet import defer, reactor
- from twisted.python import log, components, failure
- from zope.interface import Interface, implements, Attribute
- from IPython.tools import growl
- from IPython.kernel.util import printer
- from IPython.kernel.twistedutil import gatherBoth
- from IPython.kernel import map as Map
- from IPython.kernel import error
- from IPython.kernel.pendingdeferred import PendingDeferredManager, two_phase
- from IPython.kernel.controllerservice import ControllerAdapterBase, ControllerService, IControllerBase
-
- class IEngineMultiplexer(Interface):
-
- def execute(lines, targets = 'all'):
- pass
-
-
- def push(namespace, targets = 'all'):
- pass
-
-
- def pull(keys, targets = 'all'):
- pass
-
-
- def push_function(namespace, targets = 'all'):
- pass
-
-
- def pull_function(keys, targets = 'all'):
- pass
-
-
- def get_result(i = None, targets = 'all'):
- pass
-
-
- def reset(targets = 'all'):
- pass
-
-
- def keys(targets = 'all'):
- pass
-
-
- def kill(controller = False, targets = 'all'):
- pass
-
-
- def push_serialized(namespace, targets = 'all'):
- pass
-
-
- def pull_serialized(keys, targets = 'all'):
- pass
-
-
- def clear_queue(targets = 'all'):
- pass
-
-
- def queue_status(targets = 'all'):
- pass
-
-
- def set_properties(properties, targets = 'all'):
- pass
-
-
- def get_properties(keys = None, targets = 'all'):
- pass
-
-
- def del_properties(keys, targets = 'all'):
- pass
-
-
- def has_properties(keys, targets = 'all'):
- pass
-
-
- def clear_properties(targets = 'all'):
- pass
-
-
-
- class IMultiEngine(IEngineMultiplexer):
-
- def get_ids():
- pass
-
-
-
- class MultiEngine(ControllerAdapterBase):
- implements(IMultiEngine)
-
- def __init(self, controller):
- ControllerAdapterBase.__init__(self, controller)
-
-
- def engineList(self, targets):
- if isinstance(targets, int):
- if targets not in self.engines.keys():
- log.msg('Engine with id %i is not registered' % targets)
- raise error.InvalidEngineID('Engine with id %i is not registered' % targets)
- targets not in self.engines.keys()
- return [
- self.engines[targets]]
- isinstance(targets, int)
- if isinstance(targets, (list, tuple)):
- for id in targets:
- if id not in self.engines.keys():
- log.msg('Engine with id %r is not registered' % id)
- raise error.InvalidEngineID('Engine with id %r is not registered' % id)
- id not in self.engines.keys()
-
- return map(self.engines.get, targets)
- if targets == 'all':
- eList = self.engines.values()
- if len(eList) == 0:
- msg = 'There are no engines registered.\n Check the logs in ~/.ipython/log if you think there should have been.'
- raise error.NoEnginesRegistered(msg)
- len(eList) == 0
- return eList
- targets == 'all'
- raise error.InvalidEngineID("targets argument is not an int, list of ints or 'all': %r" % targets)
-
-
- def _performOnEngines(self, methodName, *args, **kwargs):
- targets = kwargs.pop('targets')
- log.msg('Performing %s on %r' % (methodName, targets))
- engines = self.engineList(targets)
- dList = []
- for e in engines:
- meth = getattr(e, methodName, None)
- if meth is not None:
- dList.append(meth(*args, **kwargs))
- continue
- raise AttributeError('Engine %i does not have method %s' % (e.id, methodName))
-
- return dList
-
-
- def _performOnEnginesAndGatherBoth(self, methodName, *args, **kwargs):
-
- try:
- dList = self._performOnEngines(methodName, *args, **kwargs)
- except (error.InvalidEngineID, AttributeError, KeyError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, methodName)
- return d
-
-
- def get_ids(self):
- return defer.succeed(self.engines.keys())
-
-
- def execute(self, lines, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('execute', lines, targets = targets)
-
-
- def push(self, ns, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('push', ns, targets = targets)
-
-
- def pull(self, keys, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('pull', keys, targets = targets)
-
-
- def push_function(self, ns, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('push_function', ns, targets = targets)
-
-
- def pull_function(self, keys, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('pull_function', keys, targets = targets)
-
-
- def get_result(self, i = None, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('get_result', i, targets = targets)
-
-
- def reset(self, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('reset', targets = targets)
-
-
- def keys(self, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('keys', targets = targets)
-
-
- def kill(self, controller = False, targets = 'all'):
- if controller:
- targets = 'all'
-
- d = self._performOnEnginesAndGatherBoth('kill', targets = targets)
- if controller:
- log.msg('Killing controller')
- d.addCallback((lambda _: reactor.callLater(2, reactor.stop)))
- d.addBoth((lambda _: pass))
-
- return d
-
-
- def push_serialized(self, namespace, targets = 'all'):
- for k, v in namespace.iteritems():
- log.msg('Pushed object %s is %f MB' % (k, v.getDataSize()))
-
- d = self._performOnEnginesAndGatherBoth('push_serialized', namespace, targets = targets)
- return d
-
-
- def pull_serialized(self, keys, targets = 'all'):
-
- try:
- dList = self._performOnEngines('pull_serialized', keys, targets = targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- for d in dList:
- d.addCallback(self._logSizes)
-
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'pull_serialized')
- return d
-
-
- def _logSizes(self, listOfSerialized):
- if isinstance(listOfSerialized, (list, tuple)):
- for s in listOfSerialized:
- log.msg('Pulled object is %f MB' % s.getDataSize())
-
- else:
- log.msg('Pulled object is %f MB' % listOfSerialized.getDataSize())
- return listOfSerialized
-
-
- def clear_queue(self, targets = 'all'):
- return self._performOnEnginesAndGatherBoth('clear_queue', targets = targets)
-
-
- def queue_status(self, targets = 'all'):
- log.msg('Getting queue status on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = []
- for None in engines:
- e = None
-
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'queue_status')
- return d
-
-
- def get_properties(self, keys = None, targets = 'all'):
- log.msg('Getting properties on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = [ e.get_properties(keys) for e in engines ]
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'get_properties')
- return d
-
-
- def set_properties(self, properties, targets = 'all'):
- log.msg('Setting properties on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = [ e.set_properties(properties) for e in engines ]
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'set_properties')
- return d
-
-
- def has_properties(self, keys, targets = 'all'):
- log.msg('Checking properties on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = [ e.has_properties(keys) for e in engines ]
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'has_properties')
- return d
-
-
- def del_properties(self, keys, targets = 'all'):
- log.msg('Deleting properties on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = [ e.del_properties(keys) for e in engines ]
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'del_properties')
- return d
-
-
- def clear_properties(self, targets = 'all'):
- log.msg('Clearing properties on %r' % targets)
-
- try:
- engines = self.engineList(targets)
- except (error.InvalidEngineID, AttributeError, error.NoEnginesRegistered):
- return defer.fail(failure.Failure())
-
- dList = [ e.clear_properties() for e in engines ]
- d = gatherBoth(dList, fireOnOneErrback = 0, consumeErrors = 1, logErrors = 0)
- d.addCallback(error.collect_exceptions, 'clear_properties')
- return d
-
-
- components.registerAdapter(MultiEngine, IControllerBase, IMultiEngine)
-
- class ISynchronousEngineMultiplexer(Interface):
- pass
-
-
- class ISynchronousMultiEngine(ISynchronousEngineMultiplexer):
-
- def get_pending_deferred(deferredID, block = True):
- pass
-
-
- def clear_pending_deferreds():
- pass
-
-
-
- class SynchronousMultiEngine(PendingDeferredManager):
- implements(ISynchronousMultiEngine)
-
- def __init__(self, multiengine):
- self.multiengine = multiengine
- PendingDeferredManager.__init__(self)
-
-
- def execute(self, lines, targets = 'all'):
- d = self.multiengine.execute(lines, targets)
- return d
-
- execute = two_phase(execute)
-
- def push(self, namespace, targets = 'all'):
- return self.multiengine.push(namespace, targets)
-
- push = two_phase(push)
-
- def pull(self, keys, targets = 'all'):
- d = self.multiengine.pull(keys, targets)
- return d
-
- pull = two_phase(pull)
-
- def push_function(self, namespace, targets = 'all'):
- return self.multiengine.push_function(namespace, targets)
-
- push_function = two_phase(push_function)
-
- def pull_function(self, keys, targets = 'all'):
- d = self.multiengine.pull_function(keys, targets)
- return d
-
- pull_function = two_phase(pull_function)
-
- def get_result(self, i = None, targets = 'all'):
- return self.multiengine.get_result(i, targets = 'all')
-
- get_result = two_phase(get_result)
-
- def reset(self, targets = 'all'):
- return self.multiengine.reset(targets)
-
- reset = two_phase(reset)
-
- def keys(self, targets = 'all'):
- return self.multiengine.keys(targets)
-
- keys = two_phase(keys)
-
- def kill(self, controller = False, targets = 'all'):
- return self.multiengine.kill(controller, targets)
-
- kill = two_phase(kill)
-
- def push_serialized(self, namespace, targets = 'all'):
- return self.multiengine.push_serialized(namespace, targets)
-
- push_serialized = two_phase(push_serialized)
-
- def pull_serialized(self, keys, targets = 'all'):
- return self.multiengine.pull_serialized(keys, targets)
-
- pull_serialized = two_phase(pull_serialized)
-
- def clear_queue(self, targets = 'all'):
- return self.multiengine.clear_queue(targets)
-
- clear_queue = two_phase(clear_queue)
-
- def queue_status(self, targets = 'all'):
- return self.multiengine.queue_status(targets)
-
- queue_status = two_phase(queue_status)
-
- def set_properties(self, properties, targets = 'all'):
- return self.multiengine.set_properties(properties, targets)
-
- set_properties = two_phase(set_properties)
-
- def get_properties(self, keys = None, targets = 'all'):
- return self.multiengine.get_properties(keys, targets)
-
- get_properties = two_phase(get_properties)
-
- def has_properties(self, keys, targets = 'all'):
- return self.multiengine.has_properties(keys, targets)
-
- has_properties = two_phase(has_properties)
-
- def del_properties(self, keys, targets = 'all'):
- return self.multiengine.del_properties(keys, targets)
-
- del_properties = two_phase(del_properties)
-
- def clear_properties(self, targets = 'all'):
- return self.multiengine.clear_properties(targets)
-
- clear_properties = two_phase(clear_properties)
-
- def get_ids(self):
- return self.multiengine.get_ids()
-
-
- components.registerAdapter(SynchronousMultiEngine, IMultiEngine, ISynchronousMultiEngine)
-
- class IMultiEngineCoordinator(Interface):
-
- def scatter(key, seq, dist = 'b', flatten = False, targets = 'all'):
- pass
-
-
- def gather(key, dist = 'b', targets = 'all'):
- pass
-
-
- def raw_map(func, seqs, dist = 'b', targets = 'all'):
- pass
-
-
-
- class ISynchronousMultiEngineCoordinator(IMultiEngineCoordinator):
-
- def scatter(key, seq, dist = 'b', flatten = False, targets = 'all', block = True):
- pass
-
-
- def gather(key, dist = 'b', targets = 'all', block = True):
- pass
-
-
- def raw_map(func, seqs, dist = 'b', targets = 'all', block = True):
- pass
-
-
-
- class IMultiEngineExtras(Interface):
-
- def zip_pull(targets, keys):
- pass
-
-
- def run(targets, fname):
- pass
-
-
-
- class ISynchronousMultiEngineExtras(IMultiEngineExtras):
-
- def zip_pull(targets, keys, block = True):
- pass
-
-
- def run(targets, fname, block = True):
- pass
-
-
-
- class IFullMultiEngine(IMultiEngine, IMultiEngineCoordinator, IMultiEngineExtras):
- pass
-
-
- class IFullSynchronousMultiEngine(ISynchronousMultiEngine, ISynchronousMultiEngineCoordinator, ISynchronousMultiEngineExtras):
- pass
-
-