Пример #1
0
    def processDelayedRequests(self):
        """
        Processes the delayed requests that did not have
        any data to return last time around.
        """
        # run through delayed requests
        for request in self.delayed_requests:
            try:

                user_seen(request, False)

                # attempt to get data again
                action = get_action(request)
                if action:
                    data = action.get_data()
                    # write response and remove request from list if data is found
                    if len(data) > 0:
                        try:
                            request.write(self.__format_response(
                                request, data))
                            request.finish()
                        except:
                            # Connection was lost
                            print 'connection lost before complete.'
                        finally:
                            # Remove request from list
                            self.delayed_requests.remove(request)
            except Exception, e:
                print 'exception while handling request - removing request'
                print str(e)
                self.delayed_requests.remove(request)
Пример #2
0
    def processDelayedRequests(self):
        """
        Processes the delayed requests that did not have
        any data to return last time around.
        """
        # run through delayed requests
        for request in self.delayed_requests:
            try:

                user_seen(request, False)

                # attempt to get data again
                action = get_action(request)
                if action:
                    data = action.get_data()
                    # write response and remove request from list if data is found
                    if len(data) > 0:
                        try:
                            request.write(self.__format_response(request, data))
                            request.finish()
                        except:
                            # Connection was lost
                            print "connection lost before complete."
                        finally:
                            # Remove request from list
                            self.delayed_requests.remove(request)
            except Exception, e:
                print "exception while handling request - removing request"
                print str(e)
                self.delayed_requests.remove(request)
Пример #3
0
    def render(self, request):
        """
        Handle a new request
        """
        print "accepting request"
        # set the request content type
        request.setHeader('Content-Type', 'application/json')
        # set args
        args = request.args

        # set jsonp callback handler name if it exists
        if 'callback' in args:
            request.jsonpcallback = args['callback'][0]

        # get action and data
        action = get_action(request)
        data = action.get_data()
        if len(data) > 0:
            user_seen(request, True)
            return self.__format_response(request, data)

        # otherwise, put it in the delayed request list
        user_seen(request, True)
        self.delayed_requests.append(request)

        # tell the client we're not done yet
        return server.NOT_DONE_YET
Пример #4
0
    def render(self, request):
        """
        Handle a new request
        """
        print "accepting request"
        # set the request content type
        request.setHeader("Content-Type", "application/json")
        # set args
        args = request.args

        # set jsonp callback handler name if it exists
        if "callback" in args:
            request.jsonpcallback = args["callback"][0]

        # get action and data
        action = get_action(request)
        data = action.get_data()
        if len(data) > 0:
            user_seen(request, True)
            return self.__format_response(request, data)

        # otherwise, put it in the delayed request list
        user_seen(request, True)
        self.delayed_requests.append(request)

        # tell the client we're not done yet
        return server.NOT_DONE_YET