Exemplo n.º 1
0
    def show_request(self):
        # Delay before attempting to retrieve status messages.
        # We want to give the main thread a chance to compose and send the
        # original request before we send the status request.
        while self.waiting_for_request:
            sleep(.1)
        #print >>sys.stderr, "Attempting status connection..."
        # Ideally we would always make a noauth connection here, but we
        # only know the port that's been specified for this command -
        # so it's either the auth port or it's not.
        if self.authuser:
            sconn = KNCHTTPConnection(self.host, self.port, self.authuser)
        else:
            sconn = ChunkedHTTPConnection(self.host, self.port)
        parameters = ""
        if self.debug:
            parameters = "?debug=True"
        if self.auditid:
            uri = "/status/auditid/%s%s" % (self.auditid, parameters)
        else:
            uri = "/status/requestid/%s%s" % (self.requestid, parameters)
        RESTResource(sconn, uri).get()
        # handle failed requests
        res = sconn.getresponse()
        self.response_status = res.status
        if res.status == httplib.NOT_FOUND and not self.finished and \
           self.retry > 0:
            sconn.close()
            self.retry -= 1
            # Maybe the command has not gotten to the server yet... retry.
            sleep(.1)
            return self.show_request()

        if res.status != httplib.OK:
            if self.debug:
                print >>sys.stderr, "%s: %s" % (httplib.responses[res.status],
                                                res.read())
            if self.retry <= 0:
                print >>sys.stderr, \
                        "Client status messages disabled, retries exceeded."
            sconn.close()
            return

        while res.fp:
            pageData = res.read_chunk()
            if pageData:
                self.outstream.write(pageData)
        sconn.close()
        return