tigrcorn-static 0.3.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tigrcorn_static/__init__.py +3 -0
- tigrcorn_static/py.typed +1 -0
- tigrcorn_static/static.py +557 -0
- tigrcorn_static-0.3.16.dist-info/METADATA +292 -0
- tigrcorn_static-0.3.16.dist-info/RECORD +8 -0
- tigrcorn_static-0.3.16.dist-info/WHEEL +5 -0
- tigrcorn_static-0.3.16.dist-info/licenses/LICENSE +163 -0
- tigrcorn_static-0.3.16.dist-info/top_level.txt +1 -0
tigrcorn_static/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import mimetypes
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from email.utils import formatdate
|
|
9
|
+
from pathlib import Path, PurePosixPath
|
|
10
|
+
from typing import Iterable
|
|
11
|
+
from urllib.parse import unquote
|
|
12
|
+
|
|
13
|
+
from tigrcorn_asgi.send import FileBodySegment, MemoryBodySegment, materialize_response_body_segments, iter_response_body_segments
|
|
14
|
+
from tigrcorn_http.conditional import apply_conditional_request
|
|
15
|
+
from tigrcorn_http.entity import apply_response_entity_semantics, finalize_response_content_length
|
|
16
|
+
from tigrcorn_http.range import ByteRange, FileRangePlan, plan_file_byte_ranges
|
|
17
|
+
from tigrcorn_protocols.http1.serializer import response_allows_body
|
|
18
|
+
from tigrcorn_core.types import ASGIApp
|
|
19
|
+
from tigrcorn_core.utils.headers import append_if_missing, get_header
|
|
20
|
+
from tigrcorn_core.utils.proxy import strip_root_path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
HeaderList = list[tuple[bytes, bytes]]
|
|
24
|
+
_PRECOMPRESSED_SIDECAR_SUFFIXES: dict[str, str] = {'br': '.br', 'gzip': '.gz'}
|
|
25
|
+
_BUFFERED_DYNAMIC_CODING_MAX_BYTES = 256 * 1024
|
|
26
|
+
_MAX_ETAG_CACHE_ENTRIES = 1024
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(slots=True)
|
|
30
|
+
class StaticFileResponse:
|
|
31
|
+
status: int
|
|
32
|
+
headers: HeaderList
|
|
33
|
+
body: bytes = b''
|
|
34
|
+
segments: tuple[MemoryBodySegment | FileBodySegment, ...] = ()
|
|
35
|
+
preprocessed: bool = False
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(slots=True)
|
|
39
|
+
class _SelectedRepresentation:
|
|
40
|
+
path: Path
|
|
41
|
+
content_encoding: str | None
|
|
42
|
+
mtime: float
|
|
43
|
+
size: int
|
|
44
|
+
mtime_ns: int
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class StaticFilesApp:
|
|
48
|
+
def __init__(
|
|
49
|
+
self,
|
|
50
|
+
directory: str | Path,
|
|
51
|
+
*,
|
|
52
|
+
index_file: str | None = 'index.html',
|
|
53
|
+
dir_to_file: bool = True,
|
|
54
|
+
expires: int | None = None,
|
|
55
|
+
default_headers: Iterable[tuple[bytes, bytes] | tuple[str, str]] = (),
|
|
56
|
+
apply_content_coding: bool = True,
|
|
57
|
+
content_coding_policy: str = 'allowlist',
|
|
58
|
+
content_codings: Iterable[str] = ('br', 'gzip', 'deflate'),
|
|
59
|
+
use_precompressed_sidecars: bool = True,
|
|
60
|
+
precompressed_codings: Iterable[str] = ('br', 'gzip'),
|
|
61
|
+
) -> None:
|
|
62
|
+
self.directory = Path(directory).resolve()
|
|
63
|
+
self.index_file = index_file
|
|
64
|
+
self.dir_to_file = bool(dir_to_file)
|
|
65
|
+
self.expires = None if expires is None else int(expires)
|
|
66
|
+
self.default_headers = [
|
|
67
|
+
(
|
|
68
|
+
name if isinstance(name, bytes) else str(name).encode('latin1'),
|
|
69
|
+
value if isinstance(value, bytes) else str(value).encode('latin1'),
|
|
70
|
+
)
|
|
71
|
+
for name, value in default_headers
|
|
72
|
+
]
|
|
73
|
+
self.apply_content_coding = apply_content_coding
|
|
74
|
+
self.content_coding_policy = str(content_coding_policy)
|
|
75
|
+
self.content_codings = tuple(str(coding) for coding in content_codings)
|
|
76
|
+
self.use_precompressed_sidecars = bool(use_precompressed_sidecars)
|
|
77
|
+
self.precompressed_codings = tuple(str(coding).lower() for coding in precompressed_codings)
|
|
78
|
+
self._etag_cache: dict[tuple[str, int, int], bytes] = {}
|
|
79
|
+
|
|
80
|
+
def _resolve_candidate(self, path: str) -> Path | None:
|
|
81
|
+
decoded = unquote(path or '/')
|
|
82
|
+
if '\x00' in decoded:
|
|
83
|
+
return None
|
|
84
|
+
parts: list[str] = []
|
|
85
|
+
for part in PurePosixPath(decoded).parts:
|
|
86
|
+
if part in {'', '/', '.'}:
|
|
87
|
+
continue
|
|
88
|
+
if part == '..':
|
|
89
|
+
return None
|
|
90
|
+
if '\\' in part:
|
|
91
|
+
return None
|
|
92
|
+
parts.append(part)
|
|
93
|
+
candidate = self.directory.joinpath(*parts).resolve()
|
|
94
|
+
try:
|
|
95
|
+
candidate.relative_to(self.directory)
|
|
96
|
+
except ValueError:
|
|
97
|
+
return None
|
|
98
|
+
if candidate.is_dir():
|
|
99
|
+
if not self.dir_to_file or not self.index_file:
|
|
100
|
+
return None
|
|
101
|
+
candidate = candidate / self.index_file
|
|
102
|
+
try:
|
|
103
|
+
candidate.relative_to(self.directory)
|
|
104
|
+
except ValueError:
|
|
105
|
+
return None
|
|
106
|
+
return candidate
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def _parse_qvalue(raw: str) -> float:
|
|
110
|
+
try:
|
|
111
|
+
value = float(raw)
|
|
112
|
+
except ValueError:
|
|
113
|
+
return 0.0
|
|
114
|
+
if value < 0.0:
|
|
115
|
+
return 0.0
|
|
116
|
+
if value > 1.0:
|
|
117
|
+
return 1.0
|
|
118
|
+
return value
|
|
119
|
+
|
|
120
|
+
def _preferred_precompressed_codings(self, request_headers: list[tuple[bytes, bytes]]) -> list[str]:
|
|
121
|
+
header_value = get_header(request_headers, b'accept-encoding')
|
|
122
|
+
if header_value is None:
|
|
123
|
+
return []
|
|
124
|
+
wildcard_q: float | None = None
|
|
125
|
+
coding_q: dict[str, float] = {}
|
|
126
|
+
order: dict[str, int] = {}
|
|
127
|
+
for index, part in enumerate(header_value.decode('ascii', 'ignore').split(',')):
|
|
128
|
+
token = part.strip()
|
|
129
|
+
if not token:
|
|
130
|
+
continue
|
|
131
|
+
name, *params = [piece.strip() for piece in token.split(';')]
|
|
132
|
+
lower = name.lower()
|
|
133
|
+
q = 1.0
|
|
134
|
+
for param in params:
|
|
135
|
+
if '=' not in param:
|
|
136
|
+
continue
|
|
137
|
+
key, value = param.split('=', 1)
|
|
138
|
+
if key.strip().lower() == 'q':
|
|
139
|
+
q = self._parse_qvalue(value.strip())
|
|
140
|
+
if lower == '*':
|
|
141
|
+
wildcard_q = q
|
|
142
|
+
else:
|
|
143
|
+
coding_q[lower] = q
|
|
144
|
+
order.setdefault(lower, index)
|
|
145
|
+
|
|
146
|
+
ranked: list[tuple[float, int, str]] = []
|
|
147
|
+
for index, coding in enumerate(self.precompressed_codings):
|
|
148
|
+
q = coding_q.get(coding)
|
|
149
|
+
if q is None:
|
|
150
|
+
q = wildcard_q if wildcard_q is not None else 0.0
|
|
151
|
+
if q <= 0.0:
|
|
152
|
+
continue
|
|
153
|
+
ranked.append((-q, order.get(coding, 1000 + index), coding))
|
|
154
|
+
ranked.sort()
|
|
155
|
+
return [coding for _neg_q, _order, coding in ranked]
|
|
156
|
+
|
|
157
|
+
def _select_representation(self, candidate: Path, request_headers: list[tuple[bytes, bytes]]) -> _SelectedRepresentation:
|
|
158
|
+
origin_stat = candidate.stat()
|
|
159
|
+
if not self.apply_content_coding or not self.use_precompressed_sidecars:
|
|
160
|
+
return _SelectedRepresentation(
|
|
161
|
+
path=candidate,
|
|
162
|
+
content_encoding=None,
|
|
163
|
+
mtime=origin_stat.st_mtime,
|
|
164
|
+
size=origin_stat.st_size,
|
|
165
|
+
mtime_ns=origin_stat.st_mtime_ns,
|
|
166
|
+
)
|
|
167
|
+
if get_header(request_headers, b'range') is not None:
|
|
168
|
+
return _SelectedRepresentation(
|
|
169
|
+
path=candidate,
|
|
170
|
+
content_encoding=None,
|
|
171
|
+
mtime=origin_stat.st_mtime,
|
|
172
|
+
size=origin_stat.st_size,
|
|
173
|
+
mtime_ns=origin_stat.st_mtime_ns,
|
|
174
|
+
)
|
|
175
|
+
for coding in self._preferred_precompressed_codings(request_headers):
|
|
176
|
+
suffix = _PRECOMPRESSED_SIDECAR_SUFFIXES.get(coding)
|
|
177
|
+
if suffix is None:
|
|
178
|
+
continue
|
|
179
|
+
sidecar = candidate.with_name(candidate.name + suffix)
|
|
180
|
+
if not sidecar.exists() or not sidecar.is_file():
|
|
181
|
+
continue
|
|
182
|
+
sidecar_stat = sidecar.stat()
|
|
183
|
+
return _SelectedRepresentation(
|
|
184
|
+
path=sidecar,
|
|
185
|
+
content_encoding=coding,
|
|
186
|
+
mtime=max(origin_stat.st_mtime, sidecar_stat.st_mtime),
|
|
187
|
+
size=sidecar_stat.st_size,
|
|
188
|
+
mtime_ns=max(origin_stat.st_mtime_ns, sidecar_stat.st_mtime_ns),
|
|
189
|
+
)
|
|
190
|
+
return _SelectedRepresentation(
|
|
191
|
+
path=candidate,
|
|
192
|
+
content_encoding=None,
|
|
193
|
+
mtime=origin_stat.st_mtime,
|
|
194
|
+
size=origin_stat.st_size,
|
|
195
|
+
mtime_ns=origin_stat.st_mtime_ns,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
async def _representation_etag(self, representation: _SelectedRepresentation) -> bytes:
|
|
199
|
+
cache_key = (str(representation.path), representation.size, representation.mtime_ns)
|
|
200
|
+
cached = self._etag_cache.get(cache_key)
|
|
201
|
+
if cached is not None:
|
|
202
|
+
return cached
|
|
203
|
+
digest = hashlib.blake2s(digest_size=16)
|
|
204
|
+
async for chunk in iter_response_body_segments((FileBodySegment(str(representation.path), 0, representation.size),)):
|
|
205
|
+
digest.update(chunk)
|
|
206
|
+
value = b'"' + digest.hexdigest().encode('ascii') + b'"'
|
|
207
|
+
self._etag_cache[cache_key] = value
|
|
208
|
+
if len(self._etag_cache) > _MAX_ETAG_CACHE_ENTRIES:
|
|
209
|
+
self._etag_cache.pop(next(iter(self._etag_cache)))
|
|
210
|
+
return value
|
|
211
|
+
|
|
212
|
+
def _base_headers(self, candidate: Path, representation: _SelectedRepresentation, *, etag: bytes) -> HeaderList:
|
|
213
|
+
content_type = mimetypes.guess_type(str(candidate))[0] or 'application/octet-stream'
|
|
214
|
+
headers: HeaderList = [
|
|
215
|
+
(b'content-type', content_type.encode('latin1')),
|
|
216
|
+
(b'last-modified', formatdate(representation.mtime, usegmt=True).encode('ascii')),
|
|
217
|
+
(b'etag', etag),
|
|
218
|
+
*self.default_headers,
|
|
219
|
+
]
|
|
220
|
+
if representation.content_encoding is not None:
|
|
221
|
+
headers.append((b'content-encoding', representation.content_encoding.encode('ascii')))
|
|
222
|
+
append_if_missing(headers, b'vary', b'accept-encoding')
|
|
223
|
+
if self.expires is not None:
|
|
224
|
+
if self.expires <= 0:
|
|
225
|
+
headers.append((b'cache-control', b'no-store'))
|
|
226
|
+
else:
|
|
227
|
+
headers.append((b'cache-control', f'public, max-age={self.expires}'.encode('ascii')))
|
|
228
|
+
headers.append((b'expires', formatdate(time.time() + self.expires, usegmt=True).encode('ascii')))
|
|
229
|
+
return headers
|
|
230
|
+
|
|
231
|
+
async def _buffered_dynamic_coding_response(
|
|
232
|
+
self,
|
|
233
|
+
*,
|
|
234
|
+
method: str,
|
|
235
|
+
request_headers: list[tuple[bytes, bytes]],
|
|
236
|
+
candidate: Path,
|
|
237
|
+
representation: _SelectedRepresentation,
|
|
238
|
+
) -> StaticFileResponse:
|
|
239
|
+
body = await materialize_response_body_segments((FileBodySegment(str(representation.path), 0, representation.size),))
|
|
240
|
+
headers = self._base_headers(candidate, representation, etag=await self._representation_etag(representation))
|
|
241
|
+
processed = apply_response_entity_semantics(
|
|
242
|
+
method=method,
|
|
243
|
+
request_headers=request_headers,
|
|
244
|
+
response_headers=headers,
|
|
245
|
+
body=body,
|
|
246
|
+
status=200,
|
|
247
|
+
apply_content_coding=True,
|
|
248
|
+
content_coding_policy=self.content_coding_policy,
|
|
249
|
+
supported_codings=self.content_codings,
|
|
250
|
+
generate_etag=False,
|
|
251
|
+
)
|
|
252
|
+
segments = (MemoryBodySegment(processed.body),) if processed.body else ()
|
|
253
|
+
return StaticFileResponse(
|
|
254
|
+
status=processed.status,
|
|
255
|
+
headers=processed.headers,
|
|
256
|
+
body=processed.body,
|
|
257
|
+
segments=segments,
|
|
258
|
+
preprocessed=True,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
@staticmethod
|
|
262
|
+
def _multipart_segments(
|
|
263
|
+
*,
|
|
264
|
+
path: Path,
|
|
265
|
+
plan: FileRangePlan,
|
|
266
|
+
total_length: int,
|
|
267
|
+
source_content_type: bytes | None,
|
|
268
|
+
) -> tuple[MemoryBodySegment | FileBodySegment, ...]:
|
|
269
|
+
assert plan.boundary is not None
|
|
270
|
+
segments: list[MemoryBodySegment | FileBodySegment] = []
|
|
271
|
+
for item in plan.parts:
|
|
272
|
+
lines = [b'--' + plan.boundary]
|
|
273
|
+
if source_content_type is not None:
|
|
274
|
+
lines.append(b'Content-Type: ' + source_content_type)
|
|
275
|
+
lines.append(b'Content-Range: bytes ' + f'{item.start}-{item.end}/{total_length}'.encode('ascii'))
|
|
276
|
+
segments.append(MemoryBodySegment(b'\r\n'.join(lines) + b'\r\n\r\n'))
|
|
277
|
+
segments.append(FileBodySegment(str(path), item.start, item.end - item.start + 1))
|
|
278
|
+
segments.append(MemoryBodySegment(b'\r\n'))
|
|
279
|
+
segments.append(MemoryBodySegment(b'--' + plan.boundary + b'--\r\n'))
|
|
280
|
+
return tuple(segments)
|
|
281
|
+
|
|
282
|
+
async def _static_file_plan(
|
|
283
|
+
self,
|
|
284
|
+
*,
|
|
285
|
+
method: str,
|
|
286
|
+
request_headers: list[tuple[bytes, bytes]],
|
|
287
|
+
candidate: Path,
|
|
288
|
+
representation: _SelectedRepresentation,
|
|
289
|
+
supports_file_response: bool,
|
|
290
|
+
) -> StaticFileResponse:
|
|
291
|
+
etag = await self._representation_etag(representation)
|
|
292
|
+
headers = self._base_headers(candidate, representation, etag=etag)
|
|
293
|
+
conditional = apply_conditional_request(
|
|
294
|
+
method=method.upper(),
|
|
295
|
+
request_headers=request_headers,
|
|
296
|
+
response_headers=headers,
|
|
297
|
+
body=b'',
|
|
298
|
+
status=200,
|
|
299
|
+
)
|
|
300
|
+
if conditional.not_modified or conditional.precondition_failed:
|
|
301
|
+
processed = apply_response_entity_semantics(
|
|
302
|
+
method=method,
|
|
303
|
+
request_headers=request_headers,
|
|
304
|
+
response_headers=conditional.headers,
|
|
305
|
+
body=conditional.body,
|
|
306
|
+
status=conditional.status,
|
|
307
|
+
apply_content_coding=False,
|
|
308
|
+
generate_etag=False,
|
|
309
|
+
)
|
|
310
|
+
segments = (MemoryBodySegment(processed.body),) if processed.body else ()
|
|
311
|
+
return StaticFileResponse(
|
|
312
|
+
status=processed.status,
|
|
313
|
+
headers=processed.headers,
|
|
314
|
+
body=processed.body,
|
|
315
|
+
segments=segments,
|
|
316
|
+
preprocessed=True,
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
plan = plan_file_byte_ranges(
|
|
320
|
+
method=method,
|
|
321
|
+
request_headers=request_headers,
|
|
322
|
+
response_headers=conditional.headers,
|
|
323
|
+
resource_length=representation.size,
|
|
324
|
+
status=conditional.status,
|
|
325
|
+
)
|
|
326
|
+
headers = finalize_response_content_length(
|
|
327
|
+
method=method.upper(),
|
|
328
|
+
status=plan.status,
|
|
329
|
+
headers=plan.headers,
|
|
330
|
+
body_length=plan.body_length,
|
|
331
|
+
)
|
|
332
|
+
segments: tuple[MemoryBodySegment | FileBodySegment, ...]
|
|
333
|
+
if method.upper() == 'HEAD' or not response_allows_body(plan.status) or plan.unsatisfied:
|
|
334
|
+
segments = ()
|
|
335
|
+
elif plan.applied and len(plan.parts) > 1:
|
|
336
|
+
source_content_type = mimetypes.guess_type(str(candidate))[0]
|
|
337
|
+
segments = self._multipart_segments(
|
|
338
|
+
path=representation.path,
|
|
339
|
+
plan=plan,
|
|
340
|
+
total_length=representation.size,
|
|
341
|
+
source_content_type=None if source_content_type is None else source_content_type.encode('latin1'),
|
|
342
|
+
)
|
|
343
|
+
elif plan.applied and len(plan.parts) == 1:
|
|
344
|
+
item = plan.parts[0]
|
|
345
|
+
segments = (FileBodySegment(str(representation.path), item.start, item.end - item.start + 1),)
|
|
346
|
+
else:
|
|
347
|
+
segments = (FileBodySegment(str(representation.path), 0, representation.size),)
|
|
348
|
+
|
|
349
|
+
body = await materialize_response_body_segments(segments) if (segments and not supports_file_response) else b''
|
|
350
|
+
return StaticFileResponse(
|
|
351
|
+
status=plan.status,
|
|
352
|
+
headers=headers,
|
|
353
|
+
body=body,
|
|
354
|
+
segments=segments,
|
|
355
|
+
preprocessed=True,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
async def _response_for_path(
|
|
359
|
+
self,
|
|
360
|
+
method: str,
|
|
361
|
+
path: str,
|
|
362
|
+
request_headers: list[tuple[bytes, bytes]],
|
|
363
|
+
*,
|
|
364
|
+
supports_streaming_response: bool,
|
|
365
|
+
) -> StaticFileResponse:
|
|
366
|
+
candidate = self._resolve_candidate(path)
|
|
367
|
+
if candidate is None or not candidate.exists() or not candidate.is_file():
|
|
368
|
+
return StaticFileResponse(
|
|
369
|
+
status=404,
|
|
370
|
+
headers=[(b'content-type', b'text/plain; charset=utf-8')],
|
|
371
|
+
body=b'not found',
|
|
372
|
+
)
|
|
373
|
+
representation = self._select_representation(candidate, request_headers)
|
|
374
|
+
if (
|
|
375
|
+
representation.content_encoding is None
|
|
376
|
+
and self.apply_content_coding
|
|
377
|
+
and get_header(request_headers, b'accept-encoding') is not None
|
|
378
|
+
and get_header(request_headers, b'range') is None
|
|
379
|
+
and representation.size <= _BUFFERED_DYNAMIC_CODING_MAX_BYTES
|
|
380
|
+
):
|
|
381
|
+
return await self._buffered_dynamic_coding_response(
|
|
382
|
+
method=method,
|
|
383
|
+
request_headers=request_headers,
|
|
384
|
+
candidate=candidate,
|
|
385
|
+
representation=representation,
|
|
386
|
+
)
|
|
387
|
+
return await self._static_file_plan(
|
|
388
|
+
method=method,
|
|
389
|
+
request_headers=request_headers,
|
|
390
|
+
candidate=candidate,
|
|
391
|
+
representation=representation,
|
|
392
|
+
supports_file_response=supports_streaming_response,
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
@staticmethod
|
|
396
|
+
def _supports_file_response(scope: dict) -> bool:
|
|
397
|
+
extensions = scope.get('extensions') or {}
|
|
398
|
+
return bool(extensions.get('tigrcorn.http.response.file'))
|
|
399
|
+
|
|
400
|
+
@staticmethod
|
|
401
|
+
def _supports_pathsend(scope: dict) -> bool:
|
|
402
|
+
extensions = scope.get('extensions') or {}
|
|
403
|
+
return 'http.response.pathsend' in extensions
|
|
404
|
+
|
|
405
|
+
@staticmethod
|
|
406
|
+
def _pathsend_segment(response: StaticFileResponse) -> FileBodySegment | None:
|
|
407
|
+
if not response.segments or len(response.segments) != 1:
|
|
408
|
+
return None
|
|
409
|
+
segment = response.segments[0]
|
|
410
|
+
if not isinstance(segment, FileBodySegment):
|
|
411
|
+
return None
|
|
412
|
+
if segment.offset != 0:
|
|
413
|
+
return None
|
|
414
|
+
if segment.count is None:
|
|
415
|
+
return segment
|
|
416
|
+
try:
|
|
417
|
+
size = Path(segment.path).stat().st_size
|
|
418
|
+
except FileNotFoundError:
|
|
419
|
+
return None
|
|
420
|
+
return segment if segment.count == size else None
|
|
421
|
+
|
|
422
|
+
@staticmethod
|
|
423
|
+
def _serialize_segments(segments: tuple[MemoryBodySegment | FileBodySegment, ...]) -> list[dict]:
|
|
424
|
+
serialized: list[dict] = []
|
|
425
|
+
for segment in segments:
|
|
426
|
+
if isinstance(segment, MemoryBodySegment):
|
|
427
|
+
serialized.append({'type': 'memory', 'body': segment.data})
|
|
428
|
+
else:
|
|
429
|
+
serialized.append({'type': 'file', 'path': segment.path, 'offset': segment.offset, 'count': segment.count})
|
|
430
|
+
return serialized
|
|
431
|
+
|
|
432
|
+
async def __call__(self, scope, receive, send) -> None:
|
|
433
|
+
if scope['type'] != 'http':
|
|
434
|
+
raise RuntimeError('StaticFilesApp only supports HTTP scopes')
|
|
435
|
+
method = str(scope.get('method', 'GET')).upper()
|
|
436
|
+
if method not in {'GET', 'HEAD'}:
|
|
437
|
+
await send(
|
|
438
|
+
{
|
|
439
|
+
'type': 'http.response.start',
|
|
440
|
+
'status': 405,
|
|
441
|
+
'headers': [(b'allow', b'GET, HEAD'), (b'content-type', b'text/plain; charset=utf-8')],
|
|
442
|
+
}
|
|
443
|
+
)
|
|
444
|
+
await send({'type': 'http.response.body', 'body': b'method not allowed'})
|
|
445
|
+
return
|
|
446
|
+
request_headers = [(bytes(name).lower(), bytes(value)) for name, value in scope.get('headers', [])]
|
|
447
|
+
supports_file_response = self._supports_file_response(scope)
|
|
448
|
+
supports_pathsend = self._supports_pathsend(scope)
|
|
449
|
+
response = await self._response_for_path(
|
|
450
|
+
method,
|
|
451
|
+
scope.get('path', '/'),
|
|
452
|
+
request_headers,
|
|
453
|
+
supports_streaming_response=supports_file_response or supports_pathsend,
|
|
454
|
+
)
|
|
455
|
+
await send({'type': 'http.response.start', 'status': response.status, 'headers': response.headers})
|
|
456
|
+
if response.preprocessed:
|
|
457
|
+
pathsend_segment = self._pathsend_segment(response) if supports_pathsend else None
|
|
458
|
+
if pathsend_segment is not None:
|
|
459
|
+
await send({'type': 'http.response.pathsend', 'path': os.fspath(pathsend_segment.path)})
|
|
460
|
+
return
|
|
461
|
+
if supports_file_response and response.segments:
|
|
462
|
+
await send(
|
|
463
|
+
{
|
|
464
|
+
'type': 'tigrcorn.http.response.file',
|
|
465
|
+
'segments': self._serialize_segments(response.segments),
|
|
466
|
+
'more_body': False,
|
|
467
|
+
}
|
|
468
|
+
)
|
|
469
|
+
return
|
|
470
|
+
await send({'type': 'http.response.body', 'body': response.body})
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
async def _not_found_app(scope, receive, send) -> None:
|
|
474
|
+
if scope['type'] == 'lifespan':
|
|
475
|
+
while True:
|
|
476
|
+
message = await receive()
|
|
477
|
+
if message['type'] == 'lifespan.startup':
|
|
478
|
+
await send({'type': 'lifespan.startup.complete'})
|
|
479
|
+
elif message['type'] == 'lifespan.shutdown':
|
|
480
|
+
await send({'type': 'lifespan.shutdown.complete'})
|
|
481
|
+
return
|
|
482
|
+
if scope['type'] == 'websocket':
|
|
483
|
+
await send({'type': 'websocket.close', 'code': 1000})
|
|
484
|
+
return
|
|
485
|
+
if scope['type'] != 'http':
|
|
486
|
+
raise RuntimeError(f'unsupported scope type for static fallback: {scope["type"]!r}')
|
|
487
|
+
if scope.get('method', 'GET').upper() not in {'GET', 'HEAD'}:
|
|
488
|
+
await send({'type': 'http.response.start', 'status': 405, 'headers': [(b'allow', b'GET, HEAD'), (b'content-type', b'text/plain; charset=utf-8')]})
|
|
489
|
+
await send({'type': 'http.response.body', 'body': b'method not allowed'})
|
|
490
|
+
return
|
|
491
|
+
await send({'type': 'http.response.start', 'status': 404, 'headers': [(b'content-type', b'text/plain; charset=utf-8')]})
|
|
492
|
+
await send({'type': 'http.response.body', 'body': b'not found'})
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def normalize_static_route(route: str | None) -> str:
|
|
496
|
+
if not route:
|
|
497
|
+
return '/'
|
|
498
|
+
return ('/' + str(route).lstrip('/')).rstrip('/') or '/'
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def _route_matches(route: str, path: str) -> bool:
|
|
502
|
+
if route == '/':
|
|
503
|
+
return True
|
|
504
|
+
return path == route or path.startswith(route + '/')
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def mount_static_app(
|
|
508
|
+
app: ASGIApp | None,
|
|
509
|
+
*,
|
|
510
|
+
route: str,
|
|
511
|
+
directory: str | Path,
|
|
512
|
+
dir_to_file: bool = True,
|
|
513
|
+
index_file: str | None = 'index.html',
|
|
514
|
+
expires: int | None = None,
|
|
515
|
+
apply_content_coding: bool = True,
|
|
516
|
+
content_coding_policy: str = 'allowlist',
|
|
517
|
+
content_codings: Iterable[str] = ('br', 'gzip', 'deflate'),
|
|
518
|
+
use_precompressed_sidecars: bool = True,
|
|
519
|
+
precompressed_codings: Iterable[str] = ('br', 'gzip'),
|
|
520
|
+
) -> ASGIApp:
|
|
521
|
+
static_app = StaticFilesApp(
|
|
522
|
+
directory,
|
|
523
|
+
index_file=index_file,
|
|
524
|
+
dir_to_file=dir_to_file,
|
|
525
|
+
expires=expires,
|
|
526
|
+
apply_content_coding=apply_content_coding,
|
|
527
|
+
content_coding_policy=content_coding_policy,
|
|
528
|
+
content_codings=content_codings,
|
|
529
|
+
use_precompressed_sidecars=use_precompressed_sidecars,
|
|
530
|
+
precompressed_codings=precompressed_codings,
|
|
531
|
+
)
|
|
532
|
+
fallback = app or _not_found_app
|
|
533
|
+
normalized_route = normalize_static_route(route)
|
|
534
|
+
|
|
535
|
+
async def wrapped(scope, receive, send) -> None:
|
|
536
|
+
if scope['type'] != 'http':
|
|
537
|
+
await fallback(scope, receive, send)
|
|
538
|
+
return
|
|
539
|
+
path = str(scope.get('path') or '/')
|
|
540
|
+
if not _route_matches(normalized_route, path):
|
|
541
|
+
await fallback(scope, receive, send)
|
|
542
|
+
return
|
|
543
|
+
raw_path = bytes(scope.get('raw_path') or path.encode('latin1'))
|
|
544
|
+
mounted_path, mounted_raw_path = strip_root_path(path, raw_path, normalized_route)
|
|
545
|
+
mounted_scope = dict(scope)
|
|
546
|
+
mounted_scope['path'] = mounted_path
|
|
547
|
+
mounted_scope['raw_path'] = mounted_raw_path
|
|
548
|
+
if normalized_route != '/':
|
|
549
|
+
existing_root = str(scope.get('root_path') or '')
|
|
550
|
+
combined_root = (existing_root.rstrip('/') + normalized_route).rstrip('/') or '/'
|
|
551
|
+
mounted_scope['root_path'] = combined_root
|
|
552
|
+
await static_app(mounted_scope, receive, send)
|
|
553
|
+
|
|
554
|
+
return wrapped
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
__all__ = ['StaticFilesApp', 'mount_static_app', 'normalize_static_route']
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tigrcorn-static
|
|
3
|
+
Version: 0.3.16
|
|
4
|
+
Summary: Static file origin, file-send, validators, ranges, and cache-aware HTTP responses for the Tigrcorn ASGI server.
|
|
5
|
+
Author-email: Jacob Stewart <jacob@swarmauri.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
15
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
18
|
+
copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
21
|
+
entities that control, are controlled by, or are under common control with
|
|
22
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
23
|
+
power, direct or indirect, to cause the direction or management of such
|
|
24
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
25
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
26
|
+
such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
29
|
+
permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation source, and
|
|
33
|
+
configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
36
|
+
or translation of a Source form, including but not limited to compiled object
|
|
37
|
+
code, generated documentation, and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
40
|
+
made available under the License, as indicated by a copyright notice that is
|
|
41
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
42
|
+
below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
45
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
46
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
47
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
48
|
+
Derivative Works shall not include works that remain separable from, or
|
|
49
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
50
|
+
Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
53
|
+
version of the Work and any modifications or additions to that Work or
|
|
54
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
55
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
56
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
57
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
58
|
+
verbal, or written communication sent to the Licensor or its representatives,
|
|
59
|
+
including but not limited to communication on electronic mailing lists,
|
|
60
|
+
source code control systems, and issue tracking systems that are managed by,
|
|
61
|
+
or on behalf of, the Licensor for the purpose of discussing and improving the
|
|
62
|
+
Work, but excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
66
|
+
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
67
|
+
incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
70
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
71
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
72
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
73
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
74
|
+
Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
77
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
78
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
79
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
80
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
81
|
+
patent claims licensable by such Contributor that are necessarily infringed by
|
|
82
|
+
their Contribution(s) alone or by combination of their Contribution(s) with
|
|
83
|
+
the Work to which such Contribution(s) was submitted. If You institute patent
|
|
84
|
+
litigation against any entity (including a cross-claim or counterclaim in a
|
|
85
|
+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
86
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
87
|
+
licenses granted to You under this License for that Work shall terminate as of
|
|
88
|
+
the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
91
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
92
|
+
Source or Object form, provided that You meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
95
|
+
of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
98
|
+
You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
101
|
+
distribute, all copyright, patent, trademark, and attribution notices
|
|
102
|
+
from the Source form of the Work, excluding those notices that do not
|
|
103
|
+
pertain to any part of the Derivative Works; and
|
|
104
|
+
|
|
105
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
106
|
+
then any Derivative Works that You distribute must include a readable copy
|
|
107
|
+
of the attribution notices contained within such NOTICE file, excluding
|
|
108
|
+
those notices that do not pertain to any part of the Derivative Works, in
|
|
109
|
+
at least one of the following places: within a NOTICE text file distributed
|
|
110
|
+
as part of the Derivative Works; within the Source form or documentation,
|
|
111
|
+
if provided along with the Derivative Works; or, within a display generated
|
|
112
|
+
by the Derivative Works, if and wherever such third-party notices normally
|
|
113
|
+
appear. The contents of the NOTICE file are for informational purposes only
|
|
114
|
+
and do not modify the License. You may add Your own attribution notices
|
|
115
|
+
within Derivative Works that You distribute, alongside or as an addendum to
|
|
116
|
+
the NOTICE text from the Work, provided that such additional attribution
|
|
117
|
+
notices cannot be construed as modifying the License.
|
|
118
|
+
|
|
119
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
120
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
121
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
122
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
123
|
+
complies with the conditions stated in this License.
|
|
124
|
+
|
|
125
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
126
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
127
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
128
|
+
additional terms or conditions. Notwithstanding the above, nothing herein
|
|
129
|
+
shall supersede or modify the terms of any separate license agreement you may
|
|
130
|
+
have executed with Licensor regarding such Contributions.
|
|
131
|
+
|
|
132
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
133
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
134
|
+
required for reasonable and customary use in describing the origin of the Work
|
|
135
|
+
and reproducing the content of the NOTICE file.
|
|
136
|
+
|
|
137
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
138
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
139
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
140
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
141
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
142
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
144
|
+
associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
147
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
148
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
149
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
150
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
151
|
+
character arising as a result of this License or out of the use or inability
|
|
152
|
+
to use the Work (including but not limited to damages for loss of goodwill,
|
|
153
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
154
|
+
commercial damages or losses), even if such Contributor has been advised of
|
|
155
|
+
the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
158
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
159
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
160
|
+
and/or rights consistent with this License. However, in accepting such
|
|
161
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
162
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
163
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
165
|
+
accepting any such warranty or additional liability.
|
|
166
|
+
|
|
167
|
+
END OF TERMS AND CONDITIONS
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
Keywords: tigrcorn,static-files,file-send,http-origin,etag,range-requests,asgi
|
|
171
|
+
Classifier: Development Status :: 3 - Alpha
|
|
172
|
+
Classifier: Framework :: AsyncIO
|
|
173
|
+
Classifier: Intended Audience :: Developers
|
|
174
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
175
|
+
Classifier: Operating System :: OS Independent
|
|
176
|
+
Classifier: Programming Language :: Python :: 3
|
|
177
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
178
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
179
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
180
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
181
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
182
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
183
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
184
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
185
|
+
Classifier: Typing :: Typed
|
|
186
|
+
Requires-Python: <3.15,>=3.10
|
|
187
|
+
Description-Content-Type: text/markdown
|
|
188
|
+
License-File: LICENSE
|
|
189
|
+
Requires-Dist: tigrcorn-core==0.3.16
|
|
190
|
+
Requires-Dist: tigrcorn-asgi==0.3.16
|
|
191
|
+
Requires-Dist: tigrcorn-http==0.3.16
|
|
192
|
+
Dynamic: license-file
|
|
193
|
+
|
|
194
|
+
<div align="center">
|
|
195
|
+
<h1>tigrcorn-static</h1>
|
|
196
|
+
<img
|
|
197
|
+
src="https://raw.githubusercontent.com/Tigrbl/tigrcorn/master/assets/tigrcorn_logo.png"
|
|
198
|
+
alt="Tigrcorn tiger-unicorn logo"
|
|
199
|
+
width="140"
|
|
200
|
+
/>
|
|
201
|
+
|
|
202
|
+
<p><strong>Static file origin, file-send, validators, ranges, and cache-aware HTTP responses for the Tigrcorn ASGI server.</strong></p>
|
|
203
|
+
|
|
204
|
+
<a href="https://pypi.org/project/tigrcorn-static/"><img alt="PyPI version for tigrcorn-static" src="https://img.shields.io/pypi/v/tigrcorn-static?label=PyPI"></a>
|
|
205
|
+
<a href="https://pypi.org/project/tigrcorn-static/"><img alt="tigrcorn-static package on PyPI" src="https://img.shields.io/badge/package-PyPI-blue"></a>
|
|
206
|
+
<a href="https://pepy.tech/project/tigrcorn-static"><img alt="Downloads for tigrcorn-static" src="https://static.pepy.tech/badge/tigrcorn-static"></a>
|
|
207
|
+
<a href="https://github.com/tigrbl/tigrcorn/blob/master/pkgs/tigrcorn-static/README.md"><img alt="Hits for tigrcorn-static README" src="https://hits.sh/github.com/tigrbl/tigrcorn/blob/master/pkgs/tigrcorn-static/README.md.svg?label=hits"></a>
|
|
208
|
+
<a href="LICENSE"><img alt="Apache 2.0 license" src="https://img.shields.io/badge/license-Apache%202.0-525252"></a>
|
|
209
|
+
<a href="pyproject.toml"><img alt="Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 supported" src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-3776ab"></a>
|
|
210
|
+
<a href="https://pypi.org/project/tigrcorn-static/"><img alt="static role package" src="https://img.shields.io/badge/role-static-0a7f5a"></a>
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<p align="center"><a href="https://github.com/Tigrbl/tigrcorn/blob/master/.ssot/registry.json"><img alt="SSOT governed" src="https://img.shields.io/badge/SSOT-governed-2f6f4e.svg"></a> <a href="https://discord.gg/jzvrbEtTtt"><img alt="Discord" src="https://img.shields.io/badge/Discord-Join%20chat-5865F2?logo=discord&logoColor=white"></a></p>
|
|
214
|
+
|
|
215
|
+
## Install
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
uv add tigrcorn-static
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pip install tigrcorn-static
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Use the aggregate [tigrcorn](https://pypi.org/project/tigrcorn/) distribution when you want the full ASGI3 Python web server stack. Install <code>tigrcorn-static</code> directly when you want only this package boundary and its declared dependencies.
|
|
226
|
+
|
|
227
|
+
## What It Owns
|
|
228
|
+
|
|
229
|
+
<code>tigrcorn-static</code> owns static origin, pathsend, and file-send behavior. Its import package is <code>tigrcorn_static</code>, and its declared package dependencies are: tigrcorn-core, tigrcorn-asgi, tigrcorn-http.
|
|
230
|
+
|
|
231
|
+
This package page is written for developers searching for Tigrcorn ASGI3 server components, Python web server packages, HTTP/3 and QUIC support, WebSocket and WebTransport-adjacent surfaces, and Apache 2.0 licensed infrastructure.
|
|
232
|
+
|
|
233
|
+
## Why Use This?
|
|
234
|
+
|
|
235
|
+
Use <code>tigrcorn-static</code> when you want the static layer as a direct install target instead of the full server bundle. It lets application, operator, or certification workflows depend on this boundary explicitly while keeping the broader Tigrcorn runtime assembled from smaller repo-owned package surfaces.
|
|
236
|
+
|
|
237
|
+
## FAQ
|
|
238
|
+
|
|
239
|
+
### What does this package export?
|
|
240
|
+
|
|
241
|
+
The package exports through the <code>tigrcorn_static</code> namespace and keeps the root <code>tigrcorn</code> package as the compatibility umbrella.
|
|
242
|
+
|
|
243
|
+
### Which boundary does this package own?
|
|
244
|
+
|
|
245
|
+
It is the package boundary for static origin, pathsend, and file-send behavior in the Tigrcorn package graph.
|
|
246
|
+
|
|
247
|
+
### Why keep static delivery separate?
|
|
248
|
+
|
|
249
|
+
Static origin, file-send, validators, cache-aware responses, and pathsend integration are separated so static delivery can evolve independently from protocol and runtime orchestration.
|
|
250
|
+
|
|
251
|
+
## Features
|
|
252
|
+
|
|
253
|
+
- Owns static origin, pathsend, and file-send behavior inside the Tigrcorn split-package architecture.
|
|
254
|
+
- Publishes the <code>tigrcorn_static</code> import surface for named public helpers and entrypoints.
|
|
255
|
+
- Declared runtime dependencies: tigrcorn-core, tigrcorn-asgi, tigrcorn-http.
|
|
256
|
+
- Optional dependency surface: none.
|
|
257
|
+
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
|
|
258
|
+
|
|
259
|
+
## Use It When
|
|
260
|
+
|
|
261
|
+
Use <code>tigrcorn-static</code> when you need static-level behavior without pulling the entire server stack into the import surface. It is part of Tigrcorn's split-package architecture, so it can be installed independently while remaining linked to the rest of the Tigrcorn package family on PyPI.
|
|
262
|
+
|
|
263
|
+
## Import Surface
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
import tigrcorn_static
|
|
267
|
+
|
|
268
|
+
print(tigrcorn_static.__name__)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The package exposes its supported public surface through the <code>tigrcorn_static</code> namespace. The root [tigrcorn](https://pypi.org/project/tigrcorn/) package keeps compatibility shims for users who install the full server distribution.
|
|
272
|
+
|
|
273
|
+
## Related Packages
|
|
274
|
+
|
|
275
|
+
- [tigrcorn-core](https://pypi.org/project/tigrcorn-core/)
|
|
276
|
+
- [tigrcorn-asgi](https://pypi.org/project/tigrcorn-asgi/)
|
|
277
|
+
- [tigrcorn-http](https://pypi.org/project/tigrcorn-http/)
|
|
278
|
+
- [tigrcorn](https://pypi.org/project/tigrcorn/)
|
|
279
|
+
|
|
280
|
+
## Package Graph
|
|
281
|
+
|
|
282
|
+
[tigrcorn-core](https://pypi.org/project/tigrcorn-core/) | [tigrcorn-config](https://pypi.org/project/tigrcorn-config/) | [tigrcorn-http](https://pypi.org/project/tigrcorn-http/) | [tigrcorn-asgi](https://pypi.org/project/tigrcorn-asgi/) | [tigrcorn-contract](https://pypi.org/project/tigrcorn-contract/) | [tigrcorn-transports](https://pypi.org/project/tigrcorn-transports/) | [tigrcorn-security](https://pypi.org/project/tigrcorn-security/) | [tigrcorn-protocols](https://pypi.org/project/tigrcorn-protocols/) | [tigrcorn-static](https://pypi.org/project/tigrcorn-static/) | [tigrcorn-observability](https://pypi.org/project/tigrcorn-observability/) | [tigrcorn-runtime](https://pypi.org/project/tigrcorn-runtime/) | [tigrcorn-compat](https://pypi.org/project/tigrcorn-compat/) | [tigrcorn-certification](https://pypi.org/project/tigrcorn-certification/)
|
|
283
|
+
|
|
284
|
+
## Best Practices
|
|
285
|
+
|
|
286
|
+
- Keep static file semantics and cache behavior rooted here so runtime and app embedding stay smaller.
|
|
287
|
+
- Use the shared validators and range handling instead of duplicating file-response logic elsewhere.
|
|
288
|
+
- Treat pathsend and file-send differences as documented public behavior, not as hidden implementation details.
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
Apache-2.0
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
tigrcorn_static/__init__.py,sha256=7IRQZO1vU9Pu_AxnCyOs5G_opuuU5m8AbmQ4OtNamIs,92
|
|
2
|
+
tigrcorn_static/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
tigrcorn_static/static.py,sha256=_zAdMG5Ym7fCd1wV9hnudZ41Lze7ly_bQz9jM5hlMlY,22916
|
|
4
|
+
tigrcorn_static-0.3.16.dist-info/licenses/LICENSE,sha256=xhBSirl227aDQNeQ8tk2v_yiU9nbQpJ4EZp6OtATX-s,9591
|
|
5
|
+
tigrcorn_static-0.3.16.dist-info/METADATA,sha256=ZIzYFl8CmqWGjjhVNKJVxh9eu69BeaMv7Dg7O0_bZSo,18270
|
|
6
|
+
tigrcorn_static-0.3.16.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
tigrcorn_static-0.3.16.dist-info/top_level.txt,sha256=gmdTiA98fsJ9Sh78-0-rJIXBEqMtCEklpiXgOnrPRbg,16
|
|
8
|
+
tigrcorn_static-0.3.16.dist-info/RECORD,,
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
21
|
+
such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source, and
|
|
28
|
+
configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
31
|
+
or translation of a Source form, including but not limited to compiled object
|
|
32
|
+
code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that is
|
|
36
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
37
|
+
below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
42
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
+
verbal, or written communication sent to the Licensor or its representatives,
|
|
54
|
+
including but not limited to communication on electronic mailing lists,
|
|
55
|
+
source code control systems, and issue tracking systems that are managed by,
|
|
56
|
+
or on behalf of, the Licensor for the purpose of discussing and improving the
|
|
57
|
+
Work, but excluding communication that is conspicuously marked or otherwise
|
|
58
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
59
|
+
|
|
60
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
61
|
+
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
62
|
+
incorporated within the Work.
|
|
63
|
+
|
|
64
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
65
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
66
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
67
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
68
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
69
|
+
Object form.
|
|
70
|
+
|
|
71
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
72
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
73
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
74
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
75
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
76
|
+
patent claims licensable by such Contributor that are necessarily infringed by
|
|
77
|
+
their Contribution(s) alone or by combination of their Contribution(s) with
|
|
78
|
+
the Work to which such Contribution(s) was submitted. If You institute patent
|
|
79
|
+
litigation against any entity (including a cross-claim or counterclaim in a
|
|
80
|
+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
81
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
82
|
+
licenses granted to You under this License for that Work shall terminate as of
|
|
83
|
+
the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
86
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
87
|
+
Source or Object form, provided that You meet the following conditions:
|
|
88
|
+
|
|
89
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
90
|
+
of this License; and
|
|
91
|
+
|
|
92
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
93
|
+
You changed the files; and
|
|
94
|
+
|
|
95
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
96
|
+
distribute, all copyright, patent, trademark, and attribution notices
|
|
97
|
+
from the Source form of the Work, excluding those notices that do not
|
|
98
|
+
pertain to any part of the Derivative Works; and
|
|
99
|
+
|
|
100
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
101
|
+
then any Derivative Works that You distribute must include a readable copy
|
|
102
|
+
of the attribution notices contained within such NOTICE file, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative Works, in
|
|
104
|
+
at least one of the following places: within a NOTICE text file distributed
|
|
105
|
+
as part of the Derivative Works; within the Source form or documentation,
|
|
106
|
+
if provided along with the Derivative Works; or, within a display generated
|
|
107
|
+
by the Derivative Works, if and wherever such third-party notices normally
|
|
108
|
+
appear. The contents of the NOTICE file are for informational purposes only
|
|
109
|
+
and do not modify the License. You may add Your own attribution notices
|
|
110
|
+
within Derivative Works that You distribute, alongside or as an addendum to
|
|
111
|
+
the NOTICE text from the Work, provided that such additional attribution
|
|
112
|
+
notices cannot be construed as modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
115
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
116
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
117
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
118
|
+
complies with the conditions stated in this License.
|
|
119
|
+
|
|
120
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
121
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
122
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
123
|
+
additional terms or conditions. Notwithstanding the above, nothing herein
|
|
124
|
+
shall supersede or modify the terms of any separate license agreement you may
|
|
125
|
+
have executed with Licensor regarding such Contributions.
|
|
126
|
+
|
|
127
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
128
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
129
|
+
required for reasonable and customary use in describing the origin of the Work
|
|
130
|
+
and reproducing the content of the NOTICE file.
|
|
131
|
+
|
|
132
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
133
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
134
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
135
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
136
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
137
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
138
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
139
|
+
associated with Your exercise of permissions under this License.
|
|
140
|
+
|
|
141
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
142
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
143
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
144
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
145
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
146
|
+
character arising as a result of this License or out of the use or inability
|
|
147
|
+
to use the Work (including but not limited to damages for loss of goodwill,
|
|
148
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
149
|
+
commercial damages or losses), even if such Contributor has been advised of
|
|
150
|
+
the possibility of such damages.
|
|
151
|
+
|
|
152
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
153
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
154
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
155
|
+
and/or rights consistent with this License. However, in accepting such
|
|
156
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
157
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
158
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
159
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
160
|
+
accepting any such warranty or additional liability.
|
|
161
|
+
|
|
162
|
+
END OF TERMS AND CONDITIONS
|
|
163
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tigrcorn_static
|