MCPcopy Index your code
hub / github.com/hugapi/hug / __call__

Method __call__

hug/routing.py:480–509  ·  view source on GitHub ↗
(self, api_function)

Source from the content-addressed store, hash-verified

478 self.route["prefixes"] = (prefixes,) if isinstance(prefixes, str) else prefixes
479
480 def __call__(self, api_function):
481 api = self.route.get("api", hug.api.from_object(api_function))
482 api.http.routes.setdefault(api.http.base_url, OrderedDict())
483 (interface, callable_method) = self._create_interface(api, api_function)
484
485 use_examples = self.route.get("examples", ())
486 if not interface.required and not use_examples:
487 use_examples = (True,)
488
489 for base_url in self.route.get("urls", ("/{0}".format(api_function.__name__),)):
490 expose = [base_url]
491 for suffix in self.route.get("suffixes", ()):
492 if suffix.startswith("/"):
493 expose.append(os.path.join(base_url, suffix.lstrip("/")))
494 else:
495 expose.append(base_url + suffix)
496 for prefix in self.route.get("prefixes", ()):
497 expose.append(prefix + base_url)
498 for url in expose:
499 handlers = api.http.routes[api.http.base_url].setdefault(url, {})
500 for method in self.route.get("accept", ()):
501 version_mapping = handlers.setdefault(method.upper(), {})
502 for version in self.route.get("versions", (None,)):
503 version_mapping[version] = interface
504 api.http.versioned.setdefault(version, {})[
505 callable_method.__name__
506 ] = callable_method
507
508 interface.examples = use_examples
509 return callable_method
510
511 def urls(self, *urls, **overrides):
512 """Sets the URLs that will map to this API call"""

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
_create_interfaceMethod · 0.45

Tested by

no test coverage detected