Making it so that generic controller handlers cannot be accessed

directly.
This commit is contained in:
Jonathan LaCour
2010-11-18 11:17:39 -05:00
parent 17df37c09a
commit 307bb514c6
3 changed files with 8 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ def _cfg(f):
def when_for(controller):
def when(method):
def decorate(f):
_cfg(f)['generic_handler'] = True
controller.pecan['generic_handlers'][method.upper()] = f
return f
return decorate

View File

@@ -137,6 +137,9 @@ class Pecan(object):
content_type = self.get_content_type(format)
controller, remainder = self.route(self.root, path)
if controller.pecan.get('generic_handler'):
raise exc.HTTPNotFound
# handle generic controllers
im_self = None
if controller.pecan.get('generic'):

View File

@@ -26,7 +26,9 @@ class TestGeneric(object):
assert r.status_int == 200
assert r.body == 'GET'
app = TestApp(Pecan(RootController()))
r = app.post('/')
assert r.status_int == 200
assert r.body == dumps(dict(result='POST'))
assert r.body == dumps(dict(result='POST'))
r = app.get('/do_get', status=404)
assert r.status_int == 404