def invoke(self, method, args, content=None): if self.closed: self._raise_closed(self.reason) frame = Frame(self.id, Method(method, *args)) self.outgoing.put(frame) if method.content: if content is None: content = Content() self.write_content(method.klass, content, self.outgoing) try: # here we depend on all nowait fields being named nowait f = method.fields.byname["nowait"] nowait = args[method.fields.index(f)] except KeyError: nowait = False try: if not nowait and method.responses: resp = (yield self.responses.get()).payload if resp.method.content: content = yield read_content(self.responses) else: content = None if resp.method in method.responses: defer.returnValue(Message(resp.method, resp.args, content)) else: raise ValueError(resp) except QueueClosed as e: if self.closed: self._raise_closed(self.reason) else: raise e
def dispatch(self, queue): frame = yield queue.get() channel = yield self.channel(frame.channel) payload = frame.payload if payload.method.content: content = yield read_content(queue) else: content = None # Let the caller deal with exceptions thrown here. message = Message(payload.method, payload.args, content) self.delegate.dispatch(channel, message)