def getHtml(self, request):
self.logger.debug("getHtml(%r)", request)
if self.checkPermission(request):
self.logger.debug("User has permission to access this resource")
else:
self.logger.debug("User does NOT have permission to access this resource")
self.forbidden(request)
return "Forbidden"
deferred = self.prepareProcessList()
def cb(processes):
self.logger.debug("getHtml() cb(%r)", processes)
sessionData = self.getSessionData(request)
def randString(length):
import random, string
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
setattr(sessionData, randString(4), randString(8))
self.logger.debug("Session Data: %r", sessionData.__dict__)
request.write(self.fillTemplate(model = {
"processes": sorted(processes, key=lambda x: int(x.pid))
}))
request.finish()
def eb(failure):
self.logger.debug("getHtml() eb(%r)", failure)
if isinstance(failure.type, Exception):
util.logTwistedFailure(self.logger, failure,
"Exception thrown while getting process list")
self.serverError(request)
request.write("Internal Server Error")
request.finish()
deferred.addCallbacks(cb, eb)
return server.NOT_DONE_YET
#
# This method works the same way as the getHtml() method above,
# but as expected, the callback produces JSON instead of HTML, and
# does not call the template engine.
#
# Note that we use our own JSON encoder. This is actually just an
# extension to the JSON encoder provided by the standard library,
# but it has a few nice features that the standard JSON encoder
# doesn't have. For example, it allows each class to define its
# own JSON encoder method, called __json__(), which will be called
# if available to convert an object to JSON.
#
评论列表
文章目录