Merge trunk
This commit is contained in:
		
							
								
								
									
										36
									
								
								nova/wsgi.py
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								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', {})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user