Esempio n. 1
0
    def pumpMethod(self, channel, klass, method, **fields):
        """Convenience for pumping a method frame.

        @param channel: The channel ID of the frame.
        @param klass: The class name of the method.
        @param method: The name of the method.
        @param fields: Fields for the method. Missing fields will be filled
            with None.
        """
        klass = self._classFromPyName(klass)
        method = self._methodFromPyName(klass, method)
        args = [None] * len(method.fields.items)
        for key, value in fields.items():
            field = method.fields.bypyname[key]
            args[method.fields.indexes[field]] = value
        self.pump(channel, Method(method, *args))
    def invoke(self, method, args, content=None):
        if self.closed:
            raise Closed(self.reason)
        frame = Frame(self.id, Method(method, *args))
        self.outgoing.put(frame)

        if method.content:
            if content == None:
                content = Content()
            self.writeContent(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 = self.responses.get()
                yield resp
                resp = resp.payload

                if resp.method.content:
                    content = readContent(self.responses)
                    yield content
                else:
                    content = None
                if resp.method in method.responses:
                    defer.returnValue(Message(resp.method, resp.args, content))
                else:
                    raise ValueError(resp)
        except QueueClosed, e:
            if self.closed:
                raise Closed(self.reason)
            else:
                raise e