Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 2948:deda13909085
factor out get_action_class so it may be called from other places
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 23 Nov 2004 22:44:43 +0000 |
| parents | e611be5ee6c4 |
| children | 1535b4b5d746 |
comparison
equal
deleted
inserted
replaced
| 2947:e611be5ee6c4 | 2948:deda13909085 |
|---|---|
| 1 # $Id: client.py,v 1.208 2004-11-22 10:46:18 a1s Exp $ | 1 # $Id: client.py,v 1.209 2004-11-23 22:44:43 richard Exp $ |
| 2 | 2 |
| 3 """WWW request handler (also used in the stand-alone server). | 3 """WWW request handler (also used in the stand-alone server). |
| 4 """ | 4 """ |
| 5 __docformat__ = 'restructuredtext' | 5 __docformat__ = 'restructuredtext' |
| 6 | 6 |
| 156 # parse cookies (used in charset and session lookups) | 156 # parse cookies (used in charset and session lookups) |
| 157 self.cookie = Cookie.SimpleCookie(self.env.get('HTTP_COOKIE', '')) | 157 self.cookie = Cookie.SimpleCookie(self.env.get('HTTP_COOKIE', '')) |
| 158 | 158 |
| 159 self.user = None | 159 self.user = None |
| 160 self.userid = None | 160 self.userid = None |
| 161 self.nodeid = None | |
| 162 self.classname = None | |
| 163 self.template = None | |
| 161 | 164 |
| 162 def setTranslator(self, translator=None): | 165 def setTranslator(self, translator=None): |
| 163 """Replace the translation engine | 166 """Replace the translation engine |
| 164 | 167 |
| 165 'translator' | 168 'translator' |
| 399 except TypeError: | 402 except TypeError: |
| 400 # invalid challenge | 403 # invalid challenge |
| 401 pass | 404 pass |
| 402 username, password = decoded.split(':') | 405 username, password = decoded.split(':') |
| 403 try: | 406 try: |
| 404 LoginAction(self).verifyLogin(username, password) | 407 self.get_action_class('login')(self).verifyLogin(username, password) |
| 405 except LoginError, err: | 408 except LoginError, err: |
| 406 self.make_user_anonymous() | 409 self.make_user_anonymous() |
| 407 self.response_code = 403 | 410 self.response_code = 403 |
| 408 raise Unauthorised, err | 411 raise Unauthorised, err |
| 409 | 412 |
| 730 action = self.form['@action'].value.lower() | 733 action = self.form['@action'].value.lower() |
| 731 else: | 734 else: |
| 732 return None | 735 return None |
| 733 | 736 |
| 734 try: | 737 try: |
| 735 if (hasattr(self.instance, 'cgi_actions') and | 738 action_klass = self.get_action_class(action) |
| 736 self.instance.cgi_actions.has_key(action)): | |
| 737 # tracker-defined action | |
| 738 action_klass = self.instance.cgi_actions[action] | |
| 739 else: | |
| 740 # go with a default | |
| 741 for name, action_klass in self.actions: | |
| 742 if name == action: | |
| 743 break | |
| 744 else: | |
| 745 raise ValueError, 'No such action "%s"'%action | |
| 746 | 739 |
| 747 # call the mapped action | 740 # call the mapped action |
| 748 if isinstance(action_klass, type('')): | 741 if isinstance(action_klass, type('')): |
| 749 # old way of specifying actions | 742 # old way of specifying actions |
| 750 return getattr(self, action_klass)() | 743 return getattr(self, action_klass)() |
| 751 else: | 744 else: |
| 752 return action_klass(self).execute() | 745 return action_klass(self).execute() |
| 753 | 746 |
| 754 except ValueError, err: | 747 except ValueError, err: |
| 755 self.error_message.append(str(err)) | 748 self.error_message.append(str(err)) |
| 749 | |
| 750 def get_action_class(self, action_name): | |
| 751 if (hasattr(self.instance, 'cgi_actions') and | |
| 752 self.instance.cgi_actions.has_key(action_name)): | |
| 753 # tracker-defined action | |
| 754 action_klass = self.instance.cgi_actions[action_name] | |
| 755 else: | |
| 756 # go with a default | |
| 757 for name, action_klass in self.actions: | |
| 758 if name == action_name: | |
| 759 break | |
| 760 else: | |
| 761 raise ValueError, 'No such action "%s"'%action_name | |
| 762 return action_klass | |
| 756 | 763 |
| 757 def write(self, content): | 764 def write(self, content): |
| 758 if not self.headers_done: | 765 if not self.headers_done: |
| 759 self.header() | 766 self.header() |
| 760 if self.env['REQUEST_METHOD'] != 'HEAD': | 767 if self.env['REQUEST_METHOD'] != 'HEAD': |
