/usr/share/pyshared/cherrypy/filters/logdebuginfofilter.py is in python-cherrypy 2.3.0-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import time
try:
import cPickle as pickle
except ImportError:
import pickle
import cherrypy
from basefilter import BaseFilter
class LogDebugInfoFilter(BaseFilter):
"""Filter that adds debug information to the page"""
def on_start_resource(self):
cherrypy.request.startBuilTime = time.time()
def before_finalize(self):
if not cherrypy.config.get('log_debug_info_filter.on', False):
return
mimelist = cherrypy.config.get('log_debug_info_filter.mime_types', ['text/html'])
ct = cherrypy.response.headers.get('Content-Type').split(';')[0]
if ct in mimelist:
body = cherrypy.response.collapse_body()
debuginfo = '\n'
logAsComment = cherrypy.config.get('log_debug_info_filter.log_as_comment', False)
if logAsComment:
debuginfo += '<!-- '
else:
debuginfo += "<br/><br/>"
logList = []
if cherrypy.config.get('log_debug_info_filter.log_build_time', True):
logList.append("Build time: %.03fs" % (
time.time() - cherrypy.request.startBuilTime))
if cherrypy.config.get('log_debug_info_filter.log_page_size', True):
logList.append("Page size: %.02fKB" % (
len(body)/float(1024)))
'''
# this is not compatible with the session filter
if (cherrypy.config.get('log_debug_info_filter.log_session_size', True)
and cherrypy.config.get('session.storageType')):
# Pickle session data to get its size
try:
dumpStr = pickle.dumps(cherrypy.request.sessionMap, 1)
logList.append("Session data size: %.02fKB" %
(len(dumpStr) / float(1024)))
except:
logList.append("Session data size: Unable to pickle session")
'''
debuginfo += ', '.join(logList)
if logAsComment:
debuginfo += '-->'
cherrypy.response.body = [body, debuginfo]
# Delete Content-Length header so finalize() recalcs it.
cherrypy.response.headers.pop("Content-Length", None)
|