To specify a context of a controller from WSGIApplication#register()

Before:
        wsgi.register(FooController)
        wsgi.registory[FooController.__name__] = controller_args

After:
        wsgi.register(FooController, controller_args)

Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Satoshi Kobayashi 2013-10-02 13:36:45 +09:00 committed by FUJITA Tomonori
parent 8df8cca872
commit 789fbb3a51
2 changed files with 11 additions and 2 deletions

View File

@ -93,7 +93,7 @@ class WSGIApplication(object):
controller = match['controller'](req, link, data, **self.config)
return controller(req)
def register(self, controller):
def register(self, controller, data=None):
methods = inspect.getmembers(controller,
lambda v: inspect.ismethod(v) and
hasattr(v, 'routing_info'))
@ -111,6 +111,8 @@ class WSGIApplication(object):
requirements=requirements,
action=method_name,
conditions=conditions)
if data:
self.registory[controller.__name__] = data
class WSGIServer(hub.WSGIServer):

View File

@ -28,6 +28,10 @@ LOG = logging.getLogger('test_wsgi')
class _TestController(ControllerBase):
def __init__(self, req, link, data, **config):
super(_TestController, self).__init__(req, link, data, **config)
eq_(data['test_param'], 'foo')
@route('test', '/test/{dpid}',
methods=['GET'], requirements={'dpid': dpidlib.DPID_PATTERN})
def test_get_dpid(self, req, dpid, **_kwargs):
@ -44,8 +48,11 @@ class Test_wsgi(unittest.TestCase):
"""
def setUp(self):
controller_data = {
'test_param': 'foo'
}
self.wsgi_app = WSGIApplication()
self.wsgi_app.register(_TestController)
self.wsgi_app.register(_TestController, controller_data)
def tearDown(self):
pass