Created
April 24, 2012 02:45
-
-
Save anonymous/2475710 to your computer and use it in GitHub Desktop.
TG215 Rest Dispatcher Questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RestDispatcher(ObjectDispatcher): | |
| .... | |
| .... | |
| def _check_for_sub_controllers(self, state, remainder): | |
| current_controller = state.controller | |
| method = None | |
| for find in ('get_one', 'get'): | |
| if hasattr(current_controller, find): | |
| method = find | |
| break | |
| if method is None: | |
| return | |
| args = self._get_argspec(getattr(current_controller, method)) | |
| fixed_args = args[0][1:] | |
| fixed_arg_length = len(fixed_args) | |
| var_args = args[1] | |
| if var_args: | |
| for i, item in enumerate(remainder): | |
| if hasattr(current_controller, item) and self._is_controller(current_controller, item): | |
| current_controller = getattr(current_controller, item) | |
| state.add_routing_args(item, remainder[:i], fixed_args, var_args) | |
| return self._dispatch_controller(item, current_controller, state, remainder[i+1:]) | |
| elif fixed_arg_length< len(remainder) and hasattr(current_controller, remainder[fixed_arg_length]): | |
| item = remainder[fixed_arg_length] | |
| # wyzard: item is a method of the leaf controller, it seems we are checking whether | |
| # it exists as a method in the current_controller, however, it seems, the | |
| # current_controller is not necessarily the leaf controller. | |
| if hasattr(current_controller, item): | |
| if self._is_controller(current_controller, item): | |
| state.add_routing_args(item, remainder, fixed_args, var_args) | |
| return self._dispatch_controller(item, getattr(current_controller, item), state, remainder[fixed_arg_length+1:]) | |
| else: | |
| # wyzard: if current_controller does not have method, i presume we | |
| # drill further down the url_path to locate the leaf controller | |
| else: | |
| # wyzard: implicit return None? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment