Making it so that generic controller handlers cannot be accessed
directly.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'):
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user