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

Method __call__

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

Source from the content-addressed store, hash-verified

386 self.cache(**cache)
387
388 def __call__(self, api_function):
389 directories = []
390 for directory in api_function():
391 path = os.path.abspath(directory)
392 directories.append(path)
393
394 api = self.route.get("api", hug.api.from_object(api_function))
395 for base_url in self.route.get("urls", ("/{0}".format(api_function.__name__),)):
396
397 def read_file(request=None, path=""):
398 filename = path.lstrip("/")
399 for directory in directories:
400 path = os.path.abspath(os.path.join(directory, filename))
401 if not path.startswith(directory):
402 hug.redirect.not_found()
403 if os.path.isdir(path):
404 new_path = os.path.join(path, "index.html")
405 if os.path.exists(new_path) and os.path.isfile(new_path):
406 path = new_path
407 if os.path.exists(path) and os.path.isfile(path):
408 return path
409
410 hug.redirect.not_found()
411
412 api.http.add_sink(self._create_interface(api, read_file)[0], base_url)
413 return api_function
414
415
416class ExceptionRouter(HTTPRouter):

Callers

nothing calls this directly

Calls 3

add_sinkMethod · 0.80
getMethod · 0.45
_create_interfaceMethod · 0.45

Tested by

no test coverage detected