python3: adapt @wsgi.route()

- Method in Python3 is obtained as a mere function from class attributes

Signed-off-by: Satoshi KOBAYASHI <satoshi-k@iij.ad.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Satoshi KOBAYASHI 2015-06-25 19:11:21 +09:00 committed by FUJITA Tomonori
parent 02ab23fcb8
commit 955daab412
2 changed files with 19 additions and 7 deletions

View File

@ -263,9 +263,13 @@ class WSGIApplication(object):
return controller(req)
def register(self, controller, data=None):
methods = inspect.getmembers(controller,
lambda v: inspect.ismethod(v) and
hasattr(v, 'routing_info'))
def _target_filter(attr):
if not inspect.ismethod(attr) and not inspect.isfunction(attr):
return False
if not hasattr(attr, 'routing_info'):
return False
return True
methods = inspect.getmembers(controller, _target_filter)
for method_name, method in methods:
routing_info = getattr(method, 'routing_info')
name = routing_info['name']

View File

@ -17,10 +17,14 @@
import unittest
import logging
from nose.tools import *
from ryu.app.wsgi import ControllerBase, WSGIApplication, route
import nose
from nose.tools import eq_
from webob.response import Response
from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import WSGIApplication
from ryu.app.wsgi import route
from ryu.lib import dpid as dpidlib
LOG = logging.getLogger('test_wsgi')
@ -61,7 +65,7 @@ class Test_wsgi(unittest.TestCase):
r = self.wsgi_app({'REQUEST_METHOD': 'GET',
'PATH_INFO': '/test/0123456789abcdef'},
lambda s, _: eq_(s, '200 OK'))
eq_(r[0], ('0123456789abcdef'))
eq_(r[0], (b'0123456789abcdef'))
def test_wsgi_decorator_ng_path(self):
self.wsgi_app({'REQUEST_METHOD': 'GET',
@ -93,4 +97,8 @@ class Test_wsgi(unittest.TestCase):
r = self.wsgi_app({'REQUEST_METHOD': 'DELETE',
'PATH_INFO': '/test'},
lambda s, _: eq_(s, '200 OK'))
eq_(r[0], 'root')
eq_(r[0], b'root')
if __name__ == '__main__':
nose.main(argv=['nosetests', '-s', '-v'], defaultTest=__file__)