Switch how to call the API of Routes for every version

The parameter of the API of Routes differs between 1.13 and 1.10.
Routes 1.10 is provided by base repository of RHEL.

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-07 17:41:35 +09:00 committed by FUJITA Tomonori
parent 789fbb3a51
commit b9c1fdb0d8

View File

@ -74,10 +74,27 @@ class WSGIApplication(object):
self.mapper = Mapper()
self.registory = {}
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
@webob.dec.wsgify
def __call__(self, req):
match = self.mapper.match(environ=req.environ)
match = self._match(req)
if not match:
return webob.exc.HTTPNotFound()