MCPcopy
hub / github.com/sanic-org/sanic / static

Method static

sanic/mixins/static.py:32–178  ·  view source on GitHub ↗

Register a root to serve files from. The input can either be a file or a directory. This method provides an easy and simple way to set up the route necessary to serve static files. Args: uri (str): URL path to be used for serving static content. file_or_dire

(
        self,
        uri: str,
        file_or_directory: PathLike | str,
        pattern: str = r"/?.+",
        use_modified_since: bool = True,
        use_content_range: bool = False,
        stream_large_files: bool | int = False,
        name: str = "static",
        host: str | None = None,
        strict_slashes: bool | None = None,
        content_type: str | None = None,
        apply: bool = True,
        resource_type: str | None = None,
        index: str | Sequence[str] | None = None,
        directory_view: bool = False,
        directory_handler: DirectoryHandler | None = None,
        follow_external_symlink_files: bool = False,
        follow_external_symlink_dirs: bool = False,
    )

Source from the content-addressed store, hash-verified

30 raise NotImplementedError # noqa
31
32 def static(
33 self,
34 uri: str,
35 file_or_directory: PathLike | str,
36 pattern: str = r"/?.+",
37 use_modified_since: bool = True,
38 use_content_range: bool = False,
39 stream_large_files: bool | int = False,
40 name: str = "static",
41 host: str | None = None,
42 strict_slashes: bool | None = None,
43 content_type: str | None = None,
44 apply: bool = True,
45 resource_type: str | None = None,
46 index: str | Sequence[str] | None = None,
47 directory_view: bool = False,
48 directory_handler: DirectoryHandler | None = None,
49 follow_external_symlink_files: bool = False,
50 follow_external_symlink_dirs: bool = False,
51 ):
52 """Register a root to serve files from. The input can either be a file or a directory.
53
54 This method provides an easy and simple way to set up the route necessary to serve static files.
55
56 Args:
57 uri (str): URL path to be used for serving static content.
58 file_or_directory (Union[PathLike, str]): Path to the static file
59 or directory with static files.
60 pattern (str, optional): Regex pattern identifying the valid
61 static files. Defaults to `r"/?.+"`.
62 use_modified_since (bool, optional): If true, send file modified
63 time, and return not modified if the browser's matches the
64 server's. Defaults to `True`.
65 use_content_range (bool, optional): If true, process header for
66 range requests and sends the file part that is requested.
67 Defaults to `False`.
68 stream_large_files (Union[bool, int], optional): If `True`, use
69 the `StreamingHTTPResponse.file_stream` handler rather than
70 the `HTTPResponse.file handler` to send the file. If this
71 is an integer, it represents the threshold size to switch
72 to `StreamingHTTPResponse.file_stream`. Defaults to `False`,
73 which means that the response will not be streamed.
74 name (str, optional): User-defined name used for url_for.
75 Defaults to `"static"`.
76 host (Optional[str], optional): Host IP or FQDN for the
77 service to use.
78 strict_slashes (Optional[bool], optional): Instruct Sanic to
79 check if the request URLs need to terminate with a slash.
80 content_type (Optional[str], optional): User-defined content type
81 for header.
82 apply (bool, optional): If true, will register the route
83 immediately. Defaults to `True`.
84 resource_type (Optional[str], optional): Explicitly declare a
85 resource to be a `"file"` or a `"dir"`.
86 index (Optional[Union[str, Sequence[str]]], optional): When
87 exposing against a directory, index is the name that will
88 be served as the default file. When multiple file names are
89 passed, then they will be tried in order.

Callers 15

create_simple_serverFunction · 0.80
create_appFunction · 0.80
__init__Method · 0.80
test_bp_staticFunction · 0.80
test_static_fileFunction · 0.80
test_static_directoryFunction · 0.80
test_static_head_requestFunction · 0.80

Calls 5

_apply_staticMethod · 0.95
DirectoryHandlerClass · 0.90
FutureStaticClass · 0.90
generate_nameMethod · 0.45
addMethod · 0.45

Tested by 15

test_bp_staticFunction · 0.64
test_static_fileFunction · 0.64
test_static_directoryFunction · 0.64
test_static_head_requestFunction · 0.64