summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
Diffstat (limited to 'paste')
-rw-r--r--paste/wareweb/dispatch.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/paste/wareweb/dispatch.py b/paste/wareweb/dispatch.py
index 3e5f78b..9b8b5c4 100644
--- a/paste/wareweb/dispatch.py
+++ b/paste/wareweb/dispatch.py
@@ -16,20 +16,24 @@ class MethodDispatch(object):
def respond_event(self, name, servlet, *args, **kw):
if name == 'end_awake':
- return self.find_method(servlet, *args, **kw)
+ result = self.find_method(servlet, *args, **kw)
+ if result is None:
+ return event.Continue
+ else:
+ return result
return event.Continue
def get_method(self, servlet, action):
- try:
- return action, getattr(servlet, action)
- except AttributeError:
- pass
if self.prefix:
try:
return (self.prefix + action,
getattr(servlet, self.prefix + action))
except AttributeError:
pass
+ try:
+ return action, getattr(servlet, action)
+ except AttributeError:
+ pass
return None, None
def valid_method(self, name, method):
@@ -43,10 +47,11 @@ class ActionDispatch(MethodDispatch):
prefix = 'action_'
- def __init__(self, action_name='_action_'):
+ def __init__(self, action_name='_action_', default_action=None):
self.action_name = action_name
+ self.default_action = default_action
- def find_method(self, servlet, ret_value):
+ def find_method(self, servlet, ret_value, **kw):
possible_actions = []
for name, value in servlet.fields.items():
if name == self.action_name:
@@ -54,7 +59,10 @@ class ActionDispatch(MethodDispatch):
elif name.startswith(self.action_name):
possible_actions.append(name[len(self.action_name):])
if not possible_actions:
- return event.Continue
+ if self.default_action:
+ possible_actions = [self.default_action]
+ else:
+ return event.Continue
if len(possible_actions) > 1:
raise httpexceptions.HTTPBadRequest(
"More than one action received: %s"
@@ -62,10 +70,10 @@ class ActionDispatch(MethodDispatch):
action = possible_actions[0]
name, method = self.get_method(servlet, action)
if name is None:
- raise httpexceptions.Forbidden(
+ raise httpexceptions.HTTPForbidden(
"Action method not found: %r" % action)
if not self.valid_method(name, method):
- raise httpexceptions.Forbidden(
+ raise httpexceptions.HTTPForbidden(
"Method not allowed: %r" % action)
return method()
@@ -73,7 +81,7 @@ class PathDispatch(MethodDispatch):
prefix = 'path_'
- def find_method(self, servlet, ret_value):
+ def find_method(self, servlet, ret_value, **kw):
parts = servlet.path_parts
if not parts:
action = 'index'
@@ -82,10 +90,10 @@ class PathDispatch(MethodDispatch):
servlet.path_parts = parts[1:]
name, method = self.get_method(servlet, action)
if name is None:
- raise httpexceptions.Forbidden(
+ raise httpexceptions.HTTPForbidden(
"Method not found: %r" % action)
if not self.valid_method(name, method):
- raise httpexceptions.Forbidden(
+ raise httpexceptions.HTTPForbidden(
"Method not allowed: %r" % action)
return method()