From 335ac9a5ef313eb48ee98ab53cbb7031327cab36 Mon Sep 17 00:00:00 2001 From: Mark Jones Date: Sat, 14 May 2011 15:52:25 -0500 Subject: [PATCH 1/2] Fixes I needed while replacing webapp with webapp2 on AppEngine --- webapp2/__init__.py | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/webapp2/__init__.py b/webapp2/__init__.py index 1555f17..032bc7b 100644 --- a/webapp2/__init__.py +++ b/webapp2/__init__.py @@ -143,27 +143,8 @@ def __init__(self, request=None, response=None): self.request = request self.response = response self.app = request.app - self.dispatch() - - def initialize(self, request, response): - """Initializes this request handler with the given WSGI application, - Request and Response. - - .. warning:: - This is deprecated. It is here for compatibility with webapp only. - Use __init__() instead. - - :param request: - A :class:`Request` instance. - :param response: - A :class:`Response` instance. - """ - from warnings import warn - warn(DeprecationWarning('RequestHandler.initialize() is deprecated. ' - 'Use __init__() instead.')) - self.request = request - self.response = response - self.app = WSGIApplication.active_instance + if hasattr(self, 'initialize') and callable(self.initialize): + self.initialize(request, response) def dispatch(self): """Dispatches the request. @@ -770,8 +751,14 @@ def dispatch(self, request, response): except Exception, e: handler.handle_exception(e, request.app.debug) else: - # A function or webapp2.RequestHandler: just call it. - handler_spec(request, response) + if isinstance(handler_spec, RequestHandler): + # Initialize the Handler object (so that derived Handler classes work properly) + handler_spec(request, response) + # then call it + handler_spec.dispatch() + else: + # A function just call it. + handler_spec(request, response) def set_builder(self, func): """Sets a the function called for building URLs. From 6087a88ff1bbd93d77e43cadc1385a15a040b45d Mon Sep 17 00:00:00 2001 From: Mark Jones Date: Sat, 14 May 2011 21:32:08 -0500 Subject: [PATCH 2/2] Found bug in patch using isinstance vs issubclass --- webapp2/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp2/__init__.py b/webapp2/__init__.py index 032bc7b..9e3e4fa 100644 --- a/webapp2/__init__.py +++ b/webapp2/__init__.py @@ -751,11 +751,11 @@ def dispatch(self, request, response): except Exception, e: handler.handle_exception(e, request.app.debug) else: - if isinstance(handler_spec, RequestHandler): + if issubclass(handler_spec, RequestHandler): # Initialize the Handler object (so that derived Handler classes work properly) - handler_spec(request, response) + handler = handler_spec(request, response) # then call it - handler_spec.dispatch() + handler.dispatch() else: # A function just call it. handler_spec(request, response)