diff options
author | Julien Danjou <julien@danjou.info> | 2015-02-02 16:06:52 +0100 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2015-03-02 20:43:45 -0500 |
commit | a98e5f4547a1403a1242a5a498cb9ae2eefaf46e (patch) | |
tree | da5bf11a3df58a0203094676f5c8564b714cacbd | |
parent | f4d923dca610da1ee208f403afdb63b1e69f0657 (diff) | |
download | pecan-a98e5f4547a1403a1242a5a498cb9ae2eefaf46e.tar.gz |
core: do not assume controller is a method
If a controller is not a method (e.g. a staticmethod or a function),
there's no need to pop up the self argument. That actually make the
signature to mismatch, so let's fix that.
Change-Id: Ia96b7d19b2b664381e422b7182d0437b841914dd
-rw-r--r-- | pecan/core.py | 4 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/pecan/core.py b/pecan/core.py index 1c1da68..ad32525 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -343,7 +343,9 @@ class PecanBase(object): args = [] varargs = [] kwargs = dict() - valid_args = argspec.args[1:] # pop off `self` + valid_args = argspec.args[:] + if ismethod(state.controller) or im_self: + valid_args.pop(0) # pop off `self` pecan_state = state.request.pecan def _decode(x): diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 6cc0f3c..a886a94 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -395,6 +395,11 @@ class TestControllerArguments(PecanTestCase): ', '.join(list(args) + data) ) + @staticmethod + @expose() + def static(id): + return "id is %s" % id + @expose() def _route(self, args, request): if hasattr(self, args[0]): @@ -918,6 +923,11 @@ class TestControllerArguments(PecanTestCase): assert r.status_int == 200 assert r.body == b_('variable_kwargs: list=%s' % l) + def test_staticmethod(self): + r = self.app_.get('/static/foobar') + assert r.status_int == 200 + assert r.body == b_('id is foobar') + def test_no_remainder(self): try: r = self.app_.get('/eater') |