diff options
author | Todd Willey <todd@ansolabs.com> | 2011-01-17 13:05:26 -0500 |
---|---|---|
committer | Todd Willey <todd@ansolabs.com> | 2011-01-17 13:05:26 -0500 |
commit | 58c647501254fe6274d348cf768280e3773fe1ec (patch) | |
tree | 9b69bcbf04af0164de6cd05ae88bfaf9f8c9dcf9 /nova/wsgi.py | |
parent | 500b268d0ef83b4770f9883690564e458cf94247 (diff) | |
parent | 825652456ac826a2108956ba8a9cbdc8221520dc (diff) | |
download | nova-58c647501254fe6274d348cf768280e3773fe1ec.tar.gz nova-58c647501254fe6274d348cf768280e3773fe1ec.tar.xz nova-58c647501254fe6274d348cf768280e3773fe1ec.zip |
merge trunk.
Diffstat (limited to 'nova/wsgi.py')
-rw-r--r-- | nova/wsgi.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/nova/wsgi.py b/nova/wsgi.py index b4cca9138..f31618547 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 @@ -124,20 +124,38 @@ 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. """ - 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): @@ -323,7 +341,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 @@ -356,7 +374,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', {}) |