def _get_tuple_from_route(route): """Return (pattern, handler_class, methods) tuple from ``route`` :type route: tuple|tornado.web.URLSpec :rtype: tuple :raises TypeError: If ``route`` is not a tuple or URLSpec """ if isinstance(route, tuple): assert len(route) >= 2 pattern, handler_class = route[:2] elif isinstance(route, tornado.web.URLSpec): pattern, handler_class = route.regex.pattern, route.handler_class else: raise TypeError("Unknown route type '{}'" .format(type(route).__name__)) methods = [] route_re = re.compile(pattern) route_params = set(list(route_re.groupindex.keys()) + ['self']) for http_method in HTTP_METHODS: method = getattr(handler_class, http_method, None) if method: method = extract_method(method) method_params = set(getattr(method, "__argspec_args", inspect.getargspec(method).args)) if route_params.issubset(method_params) and \ method_params.issubset(route_params): methods.append(http_method) return pattern, handler_class, methods
def yield_args(module, cls_name, method_name): """Get signature of ``module.cls_name.method_name`` Confession: This function doesn't actually ``yield`` the arguments, just returns a list. Trust me, it's better that way. :returns: List of arg names from method_name except ``self`` :rtype: list """ wrapped_method = reduce(getattr, [module, cls_name, method_name]) method = extract_method(wrapped_method) return [a for a in inspect.getargspec(method).args if a not in ["self"]]
def yield_args(module, cls_name, method_name): """Get signature of ``module.cls_name.method_name`` Confession: This function doesn't actually ``yield`` the arguments, just returns a list. Trust me, it's better that way. :returns: List of arg names from method_name except ``self`` :rtype: list """ wrapped_method = reduce(getattr, [module, cls_name, method_name]) method = extract_method(wrapped_method) argspec_args = getattr(method, "__argspec_args", inspect.getargspec(method).args) return [a for a in argspec_args if a not in ["self"]]
def yield_args(module, cls_name, method_name): """Get signature of ``module.cls_name.method_name`` Confession: This function doesn't actually ``yield`` the arguments, just returns a list. Trust me, it's better that way. :returns: List of arg names from method_name except ``self`` :rtype: list """ wrapped_method = reduce(getattr, [module, cls_name, method_name]) method = extract_method(wrapped_method) # If using tornado_json.gen.coroutine, original args are annotated... argspec_args = getattr(method, "__argspec_args", # otherwise just grab them from the method inspect.getargspec(method).args) return [a for a in argspec_args if a not in ["self"]]