summaryrefslogtreecommitdiffstats
path: root/nova/wsgi.py
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2011-01-17 13:51:00 -0500
committerTodd Willey <todd@ansolabs.com>2011-01-17 13:51:00 -0500
commitb156f7d9593135a0ab3de83c25643bb0201e2747 (patch)
treecaa5fde89f8aeddc2b2e307dc946dd91d2cb37eb /nova/wsgi.py
parente88bd8cd04b32818f693910fac772016a542e1da (diff)
parent6906137b99181925f091ca547d019499c3bc1701 (diff)
downloadnova-b156f7d9593135a0ab3de83c25643bb0201e2747.tar.gz
nova-b156f7d9593135a0ab3de83c25643bb0201e2747.tar.xz
nova-b156f7d9593135a0ab3de83c25643bb0201e2747.zip
Merge trunk
Diffstat (limited to 'nova/wsgi.py')
-rw-r--r--nova/wsgi.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/nova/wsgi.py b/nova/wsgi.py
index 40019aa43..4f5307d80 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -21,7 +21,6 @@
Utility methods for working with WSGI servers
"""
-import json
import os
import sys
from xml.dom import minidom
@@ -39,6 +38,7 @@ from paste import deploy
from nova import flags
from nova import log as logging
+from nova import utils
FLAGS = flags.FLAGS
@@ -147,8 +147,9 @@ class Application(object):
class Middleware(Application):
- """
- Base WSGI middleware wrapper. These classes require an application to be
+ """Base WSGI middleware.
+
+ These classes require an application to be
initialized that will be called next. By default the middleware will
simply call its wrapped app, or you can override __call__ to customize its
behavior.
@@ -181,13 +182,30 @@ class Middleware(Application):
return cls(app, **local_config)
return _factory
- def __init__(self, application): # pylint: disable-msg=W0231
+ def __init__(self, application):
self.application = application
+ def process_request(self, req):
+ """Called on each request.
+
+ If this returns None, the next application down the stack will be
+ executed. If it returns a response then that response will be returned
+ and execution will stop here.
+
+ """
+ return None
+
+ def process_response(self, response):
+ """Do whatever you'd like to the response."""
+ return response
+
@webob.dec.wsgify
- def __call__(self, req): # pylint: disable-msg=W0221
- """Override to implement middleware behavior."""
- return self.application
+ def __call__(self, req):
+ response = self.process_request(req)
+ if response:
+ return response
+ response = req.get_response(self.application)
+ return self.process_response(response)
class Debug(Middleware):
@@ -373,7 +391,7 @@ class Serializer(object):
try:
is_xml = (datastring[0] == '<')
if not is_xml:
- return json.loads(datastring)
+ return utils.loads(datastring)
return self._from_xml(datastring)
except:
return None
@@ -406,7 +424,7 @@ class Serializer(object):
return result
def _to_json(self, data):
- return json.dumps(data)
+ return utils.dumps(data)
def _to_xml(self, data):
metadata = self.metadata.get('application/xml', {})