diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-09-13 22:36:02 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-09-13 22:36:02 -0400 |
commit | 97a5b9591916e680c0d9e7da8c3d44eef4d3433c (patch) | |
tree | ecd0ba2ce754ec9b720f52945ec4a9556ce5e240 | |
parent | ef3265ef3387e119cf3caf5d76ace3056dae2c39 (diff) | |
download | cherrypy-97a5b9591916e680c0d9e7da8c3d44eef4d3433c.tar.gz |
Extract message to perform debug messages
-rw-r--r-- | cherrypy/lib/cptools.py | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py index 4cba8b16..f376282c 100644 --- a/cherrypy/lib/cptools.py +++ b/cherrypy/lib/cptools.py @@ -354,58 +354,51 @@ Message: %(error_msg)s username = sess.get(self.session_key) if not username: sess[self.session_key] = username = self.anonymous() - if self.debug: - cherrypy.log( - 'No session[username], trying anonymous', 'TOOLS.SESSAUTH') + self._debug_message('No session[username], trying anonymous') if not username: url = cherrypy.url(qs=request.query_string) - if self.debug: - cherrypy.log('No username, routing to login_screen with ' - 'from_page %r' % url, 'TOOLS.SESSAUTH') + self._debug_message( + 'No username, routing to login_screen with from_page %(url)r', + locals(), + ) response.body = self.login_screen(url) if "Content-Length" in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers["Content-Length"] return True - if self.debug: - cherrypy.log('Setting request.login to %r' % - username, 'TOOLS.SESSAUTH') + self._debug_message('Setting request.login to %(username)r', locals()) request.login = username self.on_check(username) + def _debug_message(self, template, context={}): + if not self.debug: + return + cherrypy.log(template % context, 'TOOLS.SESSAUTH') + def run(self): request = cherrypy.serving.request response = cherrypy.serving.response path = request.path_info if path.endswith('login_screen'): - if self.debug: - msg = 'routing %(path)r to login_screen' % locals() - cherrypy.log(msg, 'TOOLS.SESSAUTH') + self._debug_message('routing %(path)r to login_screen', locals()) response.body = self.login_screen() return True elif path.endswith('do_login'): if request.method != 'POST': response.headers['Allow'] = "POST" - if self.debug: - cherrypy.log('do_login requires POST', 'TOOLS.SESSAUTH') + self._debug_message('do_login requires POST') raise cherrypy.HTTPError(405) - if self.debug: - msg = 'routing %(path)r to do_login' % locals() - cherrypy.log(msg, 'TOOLS.SESSAUTH') + self._debug_message('routing %(path)r to do_login', locals()) return self.do_login(**request.params) elif path.endswith('do_logout'): if request.method != 'POST': response.headers['Allow'] = "POST" raise cherrypy.HTTPError(405) - if self.debug: - msg = 'routing %(path)r to do_logout' % locals() - cherrypy.log(msg, 'TOOLS.SESSAUTH') + self._debug_message('routing %(path)r to do_logout', locals()) return self.do_logout(**request.params) else: - if self.debug: - msg = 'No special path, running do_check' - cherrypy.log(msg, 'TOOLS.SESSAUTH') + self._debug_message('No special path, running do_check') return self.do_check() |