Ejemplo n.º 1
0
    def send_long_response(self, response=None):
        """Send a response to a query which expects a "long" response."""
        if response is None:
            response = Response(value=ERROR_VALUE)
        assert response.value is not None
        if response.iterstate is None:
            response.iterstate = ('', 0)

        # This operation is obviously no longer blocking
        self.__blocking_state.clear()

        # Coerce the response to a Value
        if not isinstance(response.value, Value):
            response.value = str(response.value)
        if isinstance(response.value, str):
            response.value = Value(DIRECT_STRING, response.value)

        # Coerce the status to a 4-digit string
        response.status = coerce_status(response.status)

        # Send the metadata
        if self.__metadata_send:
            self.__send_dictionary(response.metadata)

        # Send the reply itself
        self.__reply_long_preamble(response)
        if response.value.is_large():
            if _DEBUG:
                log.msg("using long value protocol")
            producer = FileProducer(response.value, self.transport)
            self.transport.registerProducer(producer, None)
        else:
            self.transport.write(response.value.val())
Ejemplo n.º 2
0
 def send_error(self, reason, status=1, long_reply=False):
     """Utility to send an error reply."""
     metadata = {'nwsReason': reason}
     response = Response(metadata)
     response.status = status
     if long_reply:
         response.value = ERROR_VALUE
         self.send_long_response(response)
     else:
         self.send_short_response(response)