mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 13:56:09 +02:00
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:
parent
02ab23fcb8
commit
955daab412
@ -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']
|
||||
|
||||
@ -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__)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user