From 38d382ad07168ff7e521b574b46a13b9f67bf941 Mon Sep 17 00:00:00 2001 From: Ian Main Date: Fri, 22 Jun 2012 09:55:17 -0700 Subject: [PATCH] Fix metadata startup. A previous change to wsgi init caused the metadata to break. This makes the 4th argument to init optional allowing other wsgi apps to continue to work as normal. Change-Id: Ib0e7042f656a9319013dba4e30c7ffa35cb85f92 Signed-off-by: Ian Main --- heat/common/wsgi.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index dd92718a4b..992870a72d 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -481,14 +481,17 @@ class Resource(object): may raise a webob.exc exception or return a dict, which will be serialized by requested content type. """ - def __init__(self, controller, deserializer): + def __init__(self, controller, deserializer, serializer=None): """ :param controller: object that implement methods created by routes lib :param deserializer: object that supports webob request deserialization through controller-like actions + :param serializer: object that supports webob response serialization + through controller-like actions """ self.controller = controller self.deserializer = deserializer + self.serializer = serializer @webob.dec.wsgify(RequestClass=Request) def __call__(self, request): @@ -511,14 +514,19 @@ class Resource(object): action_result = self.dispatch(self.controller, action, request, **action_args) + + # Here we support either passing in a serializer or detecting it + # based on the content type. try: + serializer = self.serializer + if serializer is None: + if content_type == "JSON": + serializer = JSONResponseSerializer() + else: + serializer = XMLResponseSerializer() + response = webob.Response(request=request) - if content_type == "JSON": - self.dispatch(JSONResponseSerializer(), - action, response, action_result) - else: - self.dispatch(XMLResponseSerializer(), action, - response, action_result) + self.dispatch(serializer, action, response, action_result) return response # return unserializable result (typically a webob exc)