def req_args(): info = introspect.callable_info(self.leaf) args = [] for k,v in info['args']: if v is Undefined: args.append(k) return ', '.join(args)
def leaf_reflection(leaf): """Structured info for leaf. Returns a dict or None if leaf is not exposed or not on the controller tree. """ if not isinstance(leaf, (MethodType, FunctionType, ClassType, TypeType)): return None if path_to(leaf) is None: return None info = introspect.callable_info(leaf) params = {} for k, v in info["args"]: param_info = {"description": None, "required": v is Undefined} params[k] = param_info try: formats = leaf.formats except AttributeError: # Any serializer formats = [serializer.extensions[0] for serializer in smisk.serialization.serializers] try: http_methods = leaf.methods # Some special rules: if "OPTIONS" not in http_methods: # Need to make a copy here, or we'll change the actual setting on the leaf. # Note: We set OPTIONS implicitly, because we want flexibility. See note in # decorators.expose for more information. http_methods = http_methods + ["OPTIONS"] if "HEAD" not in http_methods and "GET" in http_methods: # HEAD is a GET but without the actual body http_methods = http_methods + ["HEAD"] except AttributeError: http_methods = ["OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"] if leaf.__doc__: descr = _doc_intro(leaf) else: descr = "" return {"params": params, "description": descr, "formats": formats, "methods": http_methods}