Add factories into the wsgi classes.
This commit is contained in:
28
nova/wsgi.py
28
nova/wsgi.py
@@ -63,10 +63,20 @@ class Server(object):
|
||||
|
||||
|
||||
class Application(object):
|
||||
# TODO(gundlach): I think we should toss this class, now that it has no
|
||||
# purpose.
|
||||
"""Base WSGI application wrapper. Subclasses need to implement __call__."""
|
||||
|
||||
@classmethod
|
||||
def factory(cls, global_config, **local_config):
|
||||
"""Used for paste app factories in paste.deploy config fles."""
|
||||
rv = cls()
|
||||
for k,v in local_config.iteritems():
|
||||
if hasattr(rv, k):
|
||||
setattr(rv, k, v)
|
||||
else:
|
||||
logging.debug(_("Unknown local config option %s for %s"),
|
||||
k, cls)
|
||||
return rv
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
r"""Subclasses will probably want to implement __call__ like this:
|
||||
|
||||
@@ -111,6 +121,20 @@ class Middleware(Application):
|
||||
behavior.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def factory(cls, global_config, **local_config):
|
||||
"""Used for paste app factories in paste.deploy config fles."""
|
||||
def _factory(app):
|
||||
rv = cls(app)
|
||||
for k,v in local_config.iteritems():
|
||||
if hasattr(rv, k):
|
||||
setattr(rv, k, v)
|
||||
else:
|
||||
logging.debug(_("Unknown local config option %s for %s"),
|
||||
k, cls)
|
||||
return rv
|
||||
return _factory
|
||||
|
||||
def __init__(self, application): # pylint: disable-msg=W0231
|
||||
self.application = application
|
||||
|
||||
|
||||
Reference in New Issue
Block a user