MCPcopy
hub / github.com/hugapi/hug / __call__

Method __call__

hug/route.py:45–70  ·  view source on GitHub ↗
(self, method_or_class=None, **kwargs)

Source from the content-addressed store, hash-verified

43 super().__init__(urls=urls, accept=accept, output=output, **kwargs)
44
45 def __call__(self, method_or_class=None, **kwargs):
46 if not method_or_class and kwargs:
47 return self.where(**kwargs)
48
49 if isinstance(method_or_class, (MethodType, FunctionType)):
50 routes = getattr(method_or_class, "_hug_http_routes", [])
51 routes.append(self.route)
52 method_or_class._hug_http_routes = routes
53 return method_or_class
54
55 instance = method_or_class
56 if isinstance(method_or_class, type):
57 instance = method_or_class()
58
59 for argument in dir(instance):
60 argument = getattr(instance, argument, None)
61
62 http_routes = getattr(argument, "_hug_http_routes", ())
63 for route in http_routes:
64 http(**self.where(**route).route)(argument)
65
66 cli_routes = getattr(argument, "_hug_cli_routes", ())
67 for route in cli_routes:
68 cli(**self.where(**route).route)(argument)
69
70 return method_or_class
71
72 def http_methods(self, urls=None, **route_data):
73 """Creates routes from a class, where the class method names should line up to HTTP METHOD types"""

Callers

nothing calls this directly

Calls 2

cliFunction · 0.70
whereMethod · 0.45

Tested by

no test coverage detected