From 9f0461245972f15138bbe074fa836a8eb6662f37 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Wed, 9 Nov 2016 14:17:15 +0900 Subject: [PATCH] wsgi: Avoid using inspect.getargspec Officially, "inspect.getargspec" is obsoleted in Python 3.0, this patch fixes to avoid using this function. Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- ryu/app/wsgi.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/ryu/app/wsgi.py b/ryu/app/wsgi.py index 1e19fed0..7d7f1306 100644 --- a/ryu/app/wsgi.py +++ b/ryu/app/wsgi.py @@ -225,23 +225,15 @@ class WSGIApplication(object): self.registory = {} self._wsmanager = WebSocketManager() super(WSGIApplication, self).__init__() - # XXX: Switch how to call the API of Routes for every version - match_argspec = inspect.getargspec(self.mapper.match) - if 'environ' in match_argspec.args: - # New API - self._match = self._match_with_environ - else: - # Old API - self._match = self._match_with_path_info - def _match_with_environ(self, req): - match = self.mapper.match(environ=req.environ) - return match - - def _match_with_path_info(self, req): - self.mapper.environ = req.environ - match = self.mapper.match(req.path_info) - return match + def _match(self, req): + # Note: Invoke the new API, first. If the arguments unmatched, + # invoke the old API. + try: + return self.mapper.match(environ=req.environ) + except TypeError: + self.mapper.environ = req.environ + return self.mapper.match(req.path_info) @wsgify_hack def __call__(self, req, start_response):