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 fixed_args, var_args, kws, kw_args = get_argspec(getattr(current_controller, method)) fixed_arg_length = len(fixed_args) if var_args: for i, item in enumerate(remainder): item = state.translate_path_piece(item) 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 = state.translate_path_piece(remainder[fixed_arg_length]) 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 :] )
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 fixed_args, var_args, kws, kw_args = get_argspec( getattr(current_controller, method)) fixed_arg_length = len(fixed_args) if var_args: for i, item in enumerate(remainder): item = state.translate_path_piece(item) 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 = state.translate_path_piece(remainder[fixed_arg_length]) 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:])
def _method_matches_args(self, method, params, remainder, lax_params=False): """ This method matches the params from the request along with the remainder to the method's function signiture. If the two jive, it returns true. """ argvars, ovar_args, argkws, argvals = get_argspec(method) required_vars = self._method_required_vars(method, params, argvars, argvals) params = params.copy() #remove the appropriate remainder quotient if len(remainder)<len(required_vars): #pull the first few off with the remainder required_vars = required_vars[len(remainder):] else: #there is more of a remainder than there is non optional vars required_vars = [] #remove vars found in the params list for var in required_vars[:]: if var in params: required_vars.pop(0) # remove the param from the params so when we see if # there are params that arent in the non-required vars we # can evaluate properly del params[var] else: break #remove params that have a default value vars_with_default = argvars[len(argvars)-len(argvals):] for var in vars_with_default: if var in params: del params[var] #make sure no params exist if keyword argumnts are missing if not lax_params and argkws is None and params: return False #make sure all of the non-optional-vars are there if not required_vars: #there are more args in the remainder than are available in the argspec if len(argvars)<len(remainder) and not ovar_args: return False return True return False