7
7
import sys
8
8
import typing
9
9
10
- from starlette .responses import FileResponse
10
+ from starlette .responses import Response
11
11
from starlette .staticfiles import StaticFiles
12
12
from typing_extensions import override
13
13
@@ -17,7 +17,7 @@ def compile_static_files(*, destination: pathlib.Path, sources: typing.Sequence[
17
17
# This function is designed to write the static files, could be useful for serving static
18
18
# files via apache/nginx/etc.
19
19
manifest = generate_manifest (sources )
20
- file_map = {'file-map' : {}}
20
+ file_map : dict [ str , dict [ str , str ]] = {'file-map' : {}}
21
21
22
22
for input_filename , (hashed_relpath , source_path ) in manifest .items ():
23
23
target = destination / hashed_relpath
@@ -33,8 +33,8 @@ def generate_manifest(sources: typing.Sequence[pathlib.Path]) -> dict[str, tuple
33
33
"""
34
34
Generate a manifest which maps template_rel_path to a (hashed_relpath, full_path) tuple.
35
35
"""
36
- manifest : dict [str , tuple [str , str ]] = {}
37
- files_to_compile = {}
36
+ manifest : dict [str , tuple [str , pathlib . Path ]] = {}
37
+ files_to_compile : dict [ pathlib . Path , pathlib . Path ] = {}
38
38
for source in sources :
39
39
assert source .exists ()
40
40
for path in sorted (source .glob ('**/*' )):
@@ -63,18 +63,18 @@ def __init__(self, *, manifest, **kwargs):
63
63
def lookup_path (self , path : str ) -> tuple [str , os .stat_result | None ]:
64
64
actual_path = self ._inverted_manifest .get (path )
65
65
if actual_path is None :
66
- super .lookup_path (path )
66
+ return super () .lookup_path (path )
67
67
return actual_path , os .stat (actual_path )
68
68
69
69
@override
70
- async def get_response (self , path : str , scope ):
71
- response : FileResponse = await super ().get_response (path , scope )
70
+ async def get_response (self , path : str , scope ) -> Response :
71
+ response = await super ().get_response (path , scope )
72
72
if response .status_code in [200 , 304 ]:
73
73
response .headers ["Cache-Control" ] = "public, max-age=31536000, immutable"
74
74
return response
75
75
76
76
77
- def main (argv : typing .Sequence [str ]) -> int :
77
+ def main (argv : typing .Sequence [str ]) -> None :
78
78
parser = argparse .ArgumentParser (prog = 'simple_repository_browser.static' )
79
79
80
80
subparsers = parser .add_subparsers ()
0 commit comments