core: Message.reply() helper function

wip-fakessh-exit-status
David Wilson 7 years ago
parent 6fc8fa5b22
commit 10230f62dd

@ -255,6 +255,12 @@ class Message(object):
self.data = cPickle.dumps(CallError(e), protocol=2)
return self
def reply(self, data, **kwargs):
kwargs.setdefault('handle', self.reply_to)
self.router.route(
self.pickled(data, dst_id=self.src_id, **kwargs)
)
def unpickle(self, throw=True):
"""Deserialize `data` into an object."""
IOLOG.debug('%r.unpickle()', self)
@ -1249,16 +1255,10 @@ class ExternalContext(object):
kwargs.setdefault('econtext', self)
if getattr(fn, 'mitogen_takes_router', None):
kwargs.setdefault('router', self.router)
ret = fn(*args, **kwargs)
self.router.route(
Message.pickled(ret, dst_id=msg.src_id, handle=msg.reply_to)
)
msg.reply(fn(*args, **kwargs))
except Exception, e:
LOG.debug('_dispatch_calls: %s', e)
e = CallError(e)
self.router.route(
Message.pickled(e, dst_id=msg.src_id, handle=msg.reply_to)
)
msg.reply(CallError(e))
self.dispatch_stopped = True
def main(self, parent_ids, context_id, debug, profiling, log_level,

@ -489,13 +489,8 @@ class ModuleResponder(object):
def _send_load_module(self, stream, msg, fullname):
LOG.debug('_send_load_module(%r, %r)', stream, fullname)
self._router.route(
mitogen.core.Message.pickled(
self._build_tuple(fullname),
dst_id=msg.src_id,
handle=mitogen.core.LOAD_MODULE,
)
)
msg.reply(self._build_tuple(fullname),
handle=mitogen.core.LOAD_MODULE)
stream.sent_modules.add(fullname)
def _on_get_module(self, msg):
@ -526,13 +521,8 @@ class ModuleResponder(object):
except Exception:
LOG.debug('While importing %r', fullname, exc_info=True)
self._router.route(
mitogen.core.Message.pickled(
(fullname, None, None, None, []),
dst_id=msg.src_id,
handle=msg.reply_to,
)
)
msg.reply((fullname, None, None, None, []),
handle=mitogen.core.LOAD_MODULE)
class Broker(mitogen.core.Broker):
@ -651,13 +641,7 @@ class IdAllocator(object):
allocated = self.router.context_by_id(id_, msg.src_id)
LOG.debug('%r: allocating %r to %r', self, allocated, requestee)
self.router.route(
mitogen.core.Message.pickled(
id_,
dst_id=msg.src_id,
handle=msg.reply_to,
)
)
msg.reply(id_)
LOG.debug('%r: publishing route to %r via %r', self,
allocated, requestee)

Loading…
Cancel
Save