diff options
author | Satoshi KOBAYASHI <satoshi-k@iij.ad.jp> | 2015-06-25 19:11:21 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-25 20:14:00 +0900 |
commit | 955daab412051ccce11fc43f2e54ec2ca05c8916 (patch) | |
tree | 87a8547768e5017477ea989b456fabd6bbcbfd01 | |
parent | 02ab23fcb81433e7e50292dc6a6ebf3a80353416 (diff) |
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>
-rw-r--r-- | ryu/app/wsgi.py | 10 | ||||
-rw-r--r-- | ryu/tests/unit/app/test_wsgi.py | 16 |
2 files changed, 19 insertions, 7 deletions
diff --git a/ryu/app/wsgi.py b/ryu/app/wsgi.py index 24baf053..6687dc2f 100644 --- a/ryu/app/wsgi.py +++ b/ryu/app/wsgi.py @@ -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'] diff --git a/ryu/tests/unit/app/test_wsgi.py b/ryu/tests/unit/app/test_wsgi.py index a1da1221..9da2057b 100644 --- a/ryu/tests/unit/app/test_wsgi.py +++ b/ryu/tests/unit/app/test_wsgi.py @@ -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__) |