client_demo.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:guernsey 作者: ingnil 项目源码 文件源码
def getJson(self, request):
        deferred = self.getProcessList()

        def cb(processes):
            self.logger.debug("getJson() cb(%r)", processes)
            request.write(json.dumps({"processes": processes}))
            request.finish()

        def eb(failure):
            self.logger.debug("getJson() eb(%r)", failure)
            if isinstance(failure.type, Exception):
                util.logTwistedFailure(self.logger, failure,
                                       "Exception thrown while getting process list")
            self.serverError(request)
            request.write(json.dumps({"error": "500 Internal Server Error"}))
            request.finish()

        deferred.addCallbacks(cb, eb)
        return server.NOT_DONE_YET

#
# Create a resource class for processes owned by the user root. Since
# this class is now a child of ProcessesResource, we can call the
# getProcessList() method of that class by using getParent().
#
# The data returned is processed in the callback by filtering the
# process list on the ProcessModel 'user' attribute, so that the
# filtered list only contains processes owned by root. The filtered
# list is then passed to the template system just like in example 4.
#
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号