summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-08-23 12:55:57 -0400
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-08-23 12:55:57 -0400
commita50a200bc2547439a3da17e695224d3d434e14dd (patch)
treee03015def47109b934f2bd640bd83bd80be7b0fc
parent776e34c572e6b74c54994905573c1540b6e3a9ba (diff)
Move serialize() to wsgi.Controller so __call__ can serialize() action return values if they are dicts.
-rw-r--r--nova/api/rackspace/base.py10
-rw-r--r--nova/wsgi.py16
2 files changed, 14 insertions, 12 deletions
diff --git a/nova/api/rackspace/base.py b/nova/api/rackspace/base.py
index b995d9acc..51841925e 100644
--- a/nova/api/rackspace/base.py
+++ b/nova/api/rackspace/base.py
@@ -28,13 +28,3 @@ class Controller(wsgi.Controller):
return {cls.entity_name: cls.render(instance)}
else:
return { "TODO": "TODO" }
-
- def serialize(self, data, request):
- """
- Serialize the given dict to the response type requested in request.
- Uses self._serialization_metadata if it exists, which is a dict mapping
- MIME types to information needed to serialize to that type.
- """
- _metadata = getattr(type(self), "_serialization_metadata", {})
- serializer = wsgi.Serializer(request.environ, _metadata)
- return serializer.to_content_type(data)
diff --git a/nova/wsgi.py b/nova/wsgi.py
index baf6cccd9..d52bf855d 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -196,7 +196,8 @@ class Controller(object):
WSGI app that reads routing information supplied by RoutesMiddleware
and calls the requested action method upon itself. All action methods
must, in addition to their normal parameters, accept a 'req' argument
- which is the incoming webob.Request.
+ which is the incoming webob.Request. They raise a webob.exc exception,
+ or return a dict which will be serialized by requested content type.
"""
@webob.dec.wsgify
@@ -210,7 +211,18 @@ class Controller(object):
del arg_dict['controller']
del arg_dict['action']
arg_dict['req'] = req
- return method(**arg_dict)
+ result = method(**arg_dict)
+ return self._serialize(result, req) if type(result) is dict else result
+
+ def _serialize(self, data, request):
+ """
+ Serialize the given dict to the response type requested in request.
+ Uses self._serialization_metadata if it exists, which is a dict mapping
+ MIME types to information needed to serialize to that type.
+ """
+ _metadata = getattr(type(self), "_serialization_metadata", {})
+ serializer = wsgi.Serializer(request.environ, _metadata)
+ return serializer.to_content_type(data)
class Serializer(object):