from secrets import token_urlsafe
from subprocess import run
from traceback import print_exception
+from typing import Generator
from urllib.parse import urlunsplit
from falcon.asgi import App as FalconApp
class App(TemplateTreeFileApp, FalconApp):
@classmethod
- def scan_files(cls, base_dir):
+ def scan_files(cls, base_dir: Path) -> Generator[Path]:
for path in base_dir.iterdir():
if not path.is_dir() and not cls.is_ignored_filename(path):
yield path
- def scramble(self, value):
+ def scramble(self, value: str | bytes) -> str:
if isinstance(value, str):
value = value.encode()
secret = self.secret
def uri_tail(self, path: Path) -> str:
return self.scramble(super().uri_tail(path))
- def __init__(self, base_dir, secret, **kwargs):
+ def __init__(self, base_dir: Path, secret: str, **kwargs):
from .utils import get_redis_pass
self.secret = secret or token_urlsafe(64)
)
self.add_error_handler(Exception, self.print_exception)
- async def print_exception(self, req, resp, ex, params):
+ async def print_exception(self, req, resp, ex, params) -> None:
print_exception(*sys.exc_info())