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 <imain@redhat.com>
This commit is contained in:
Ian Main 2012-06-22 09:55:17 -07:00
parent f87fb58e01
commit 38d382ad07

View File

@ -481,14 +481,17 @@ class Resource(object):
may raise a webob.exc exception or return a dict, which will be may raise a webob.exc exception or return a dict, which will be
serialized by requested content type. 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 controller: object that implement methods created by routes lib
:param deserializer: object that supports webob request deserialization :param deserializer: object that supports webob request deserialization
through controller-like actions through controller-like actions
:param serializer: object that supports webob response serialization
through controller-like actions
""" """
self.controller = controller self.controller = controller
self.deserializer = deserializer self.deserializer = deserializer
self.serializer = serializer
@webob.dec.wsgify(RequestClass=Request) @webob.dec.wsgify(RequestClass=Request)
def __call__(self, request): def __call__(self, request):
@ -511,14 +514,19 @@ class Resource(object):
action_result = self.dispatch(self.controller, action, action_result = self.dispatch(self.controller, action,
request, **action_args) request, **action_args)
# Here we support either passing in a serializer or detecting it
# based on the content type.
try: try:
serializer = self.serializer
if serializer is None:
if content_type == "JSON":
serializer = JSONResponseSerializer()
else:
serializer = XMLResponseSerializer()
response = webob.Response(request=request) response = webob.Response(request=request)
if content_type == "JSON": self.dispatch(serializer, action, response, action_result)
self.dispatch(JSONResponseSerializer(),
action, response, action_result)
else:
self.dispatch(XMLResponseSerializer(), action,
response, action_result)
return response return response
# return unserializable result (typically a webob exc) # return unserializable result (typically a webob exc)