Skip to content

Commit

Permalink
Add utilty function to get the handler method for a request.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromakode committed Nov 4, 2011
1 parent b57dff7 commit 0ebeda5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion r2/r2/controllers/reddit_base.py
Expand Up @@ -669,7 +669,7 @@ def check_cors(self):

action = request.environ["pylons.routes_dict"]["action_name"]

handler = getattr(self, method + "_" + action, None)
handler = self._get_action_handler(action, method)
cors = handler and getattr(handler, "cors_perms", None)

if cors and cors["origin_check"](origin):
Expand Down
5 changes: 5 additions & 0 deletions r2/r2/lib/base.py
Expand Up @@ -118,6 +118,11 @@ def __call__(self, environ, start_response):
def pre(self): pass
def post(self): pass

def _get_action_handler(self, name=None, method=None):
name = name or request.environ["pylons.routes_dict"]["action_name"]
method = method or request.method
action = method + "_" + name
return getattr(self, action, None)

@classmethod
def format_output_url(cls, url, **kw):
Expand Down

0 comments on commit 0ebeda5

Please sign in to comment.