summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-07-11 12:31:38 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-07-11 12:31:38 -0400
commit334f2215f0533e8181d40cd086e927e7913739f2 (patch)
tree24e4f29b63fec14fd17fc05c2efa260b125c3952 /nova/api
parentb5ca0d793826ac10ee41be84f18d64b09113aa80 (diff)
downloadnova-334f2215f0533e8181d40cd086e927e7913739f2.tar.gz
nova-334f2215f0533e8181d40cd086e927e7913739f2.tar.xz
nova-334f2215f0533e8181d40cd086e927e7913739f2.zip
minor refactoring
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/wsgi.py52
1 files changed, 36 insertions, 16 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py
index 7a8376722..9a273bf6e 100644
--- a/nova/api/openstack/wsgi.py
+++ b/nova/api/openstack/wsgi.py
@@ -57,16 +57,26 @@ class Request(webob.Request):
return content_type
-class TextDeserializer(object):
- """Custom request body deserialization based on controller action name."""
+class ActionDispatcher(object):
+ """Maps method name to local methods through action name."""
- def deserialize(self, datastring, action='default'):
- """Find local deserialization method and parse request body."""
+ def dispatch(self, *args, **kwargs):
+ """Find and call local method."""
+ action = kwargs.pop('action', 'default')
action_method = getattr(self, str(action), self.default)
- return action_method(datastring)
+ return action_method(*args, **kwargs)
+
+ def default(self, data):
+ raise NotImplementedError()
+
+
+class TextDeserializer(ActionDispatcher):
+ """Default request body deserialization"""
+
+ def deserialize(self, datastring, action='default'):
+ return self.dispatch(datastring, action=action)
def default(self, datastring):
- """Default deserialization code should live here"""
return {}
@@ -128,8 +138,13 @@ class XMLDeserializer(TextDeserializer):
return {'body': self._from_xml(datastring)}
-class RequestHeadersDeserializer(object):
+class RequestHeadersDeserializer(ActionDispatcher):
+ """Default request headers deserializer"""
+
def deserialize(self, request, action):
+ return self.dispatch(request, action=action)
+
+ def default(self, request):
return {}
@@ -220,20 +235,18 @@ class RequestDeserializer(object):
return args
-class DictSerializer(object):
- """Custom response body serialization based on controller action name."""
+class DictSerializer(ActionDispatcher):
+ """Default request body serialization"""
def serialize(self, data, action='default'):
- """Find local serialization method and encode response body."""
- action_method = getattr(self, str(action), self.default)
- return action_method(data)
+ return self.dispatch(data, action=action)
def default(self, data):
- """Default serialization code should live here"""
- raise NotImplementedError()
+ return ""
class JSONDictSerializer(DictSerializer):
+ """Default JSON request body serialization"""
def default(self, data):
return utils.dumps(data)
@@ -320,8 +333,13 @@ class XMLDictSerializer(DictSerializer):
return result
-class ResponseHeadersSerializer(object):
+class ResponseHeadersSerializer(ActionDispatcher):
+ """Default response headers serialization"""
+
def serialize(self, response, data, action):
+ self.dispatch(response, data, action=action)
+
+ def default(self, response, data):
response.status_int = 200
@@ -410,7 +428,9 @@ class Resource(wsgi.Application):
#TODO(bcwaldon): find a more elegant way to pass through non-dict types
if type(action_result) is dict:
- response = self.serializer.serialize(action_result, accept, action)
+ response = self.serializer.serialize(action_result,
+ accept,
+ action=action)
else:
response = action_result