Exemplo n.º 1
0
    def success(self, response):
        LOG_MSG(
            'Got command poll response from the server for device {0}.'.format(
                self.owner.info))
        if response.code in [200, 201]:

            def err(reason):
                LOG_ERR(
                    'Failed to parse command request response. Reason: <{0}>.'.
                    format(reason))
                self.failure(reason)

            result = Deferred()
            result.addCallbacks(self.command_received, err)
            response.deliverBody(JsonDataConsumer(result))
        else:

            def on_get_response_text(error_text):
                LOG_ERR(
                    'Invalid response has been received during command polling. Reason: {0}.'
                    .format(error_text))
                self.failure(DhError(error_text))

            d = Deferred()
            d.addBoth(on_get_response_text)
            response.deliverBody(TextDataConsumer(d))
Exemplo n.º 2
0
    def get_response_text(self, response, func):
        def on_get_response_text(txt):
            func(txt)

        d = Deferred()
        d.addBoth(on_get_response_text)
        response.deliverBody(TextDataConsumer(defer))
    def api_received(self, response):
        if response.code == 200:
            result_proto = Deferred()
            result_proto.addCallbacks(self.api_succeed, self.api_failed)
            response.deliverBody(JsonDataConsumer(result_proto))
        else:

            def get_response_text(reason):
                self.api_failed(reason)

            response_defer = Deferred()
            response_defer.addBoth(get_response_text)
            response.deliverBody(TextDataConsumer(response_defer))