def formatwarning(self, message, category, filename, lineno, line = None):
return 'CherryPy Checker:\n%s\n\n' % message
global_config_contained_paths = False
def check_skipped_app_config(self):
for sn, app in cherrypy.tree.apps.iteritems():
if not isinstance(app, cherrypy.Application):
continue
if not app.config:
msg = 'The Application mounted at %r has an empty config.' % sn
if self.global_config_contained_paths:
msg += ' It looks like the config you passed to cherrypy.config.update() contains application-specific sections. You must explicitly pass application config via cherrypy.tree.mount(..., config=app_config)'
warnings.warn(msg)
return None
def check_static_paths(self):
request = cherrypy.request
for sn, app in cherrypy.tree.apps.iteritems():
if not isinstance(app, cherrypy.Application):
continue
request.app = app
for section in app.config:
request.get_resource(section + '/dummy.html')
conf = request.config.get
if conf('tools.staticdir.on', False):
msg = ''
root = conf('tools.staticdir.root')
dir = conf('tools.staticdir.dir')
if dir is None:
msg = 'tools.staticdir.dir is not set.'
else:
fulldir = ''
if os.path.isabs(dir):
fulldir = dir
if root:
msg = 'dir is an absolute path, even though a root is provided.'
testdir = os.path.join(root, dir[1:])
if os.path.exists(testdir):
msg += '\nIf you meant to serve the filesystem folder at %r, remove the leading slash from dir.' % testdir
elif not root:
msg = 'dir is a relative path and no root provided.'
else:
fulldir = os.path.join(root, dir)
if not os.path.isabs(fulldir):
msg = '%r is not an absolute path.' % fulldir
if fulldir and not os.path.exists(fulldir):
if msg:
msg += '\n'
msg += '%r (root + dir) is not an existing filesystem path.' % fulldir
if k == 'server.socket_host' and v == 'localhost':
warnings.warn("The use of 'localhost' as a socket host can cause problems on newer systems, since 'localhost' can map to either an IPv4 or an IPv6 address. You should use '127.0.0.1' or '[::1]' instead.")