(
self, environ: WSGIEnvironment, start_response: StartResponse
)
| 225 | return f"wzsdm-{timestamp}-{file_size}-{checksum}" |
| 226 | |
| 227 | def __call__( |
| 228 | self, environ: WSGIEnvironment, start_response: StartResponse |
| 229 | ) -> t.Iterable[bytes]: |
| 230 | path = get_path_info(environ) |
| 231 | file_loader = None |
| 232 | |
| 233 | for search_path, loader in self.exports: |
| 234 | if search_path == path: |
| 235 | real_filename, file_loader = loader(None) |
| 236 | |
| 237 | if file_loader is not None: |
| 238 | break |
| 239 | |
| 240 | if not search_path.endswith("/"): |
| 241 | search_path += "/" |
| 242 | |
| 243 | if path.startswith(search_path): |
| 244 | real_filename, file_loader = loader(path[len(search_path) :]) |
| 245 | |
| 246 | if file_loader is not None: |
| 247 | break |
| 248 | |
| 249 | if file_loader is None or not self.is_allowed(real_filename): # type: ignore |
| 250 | return self.app(environ, start_response) |
| 251 | |
| 252 | guessed_type = mimetypes.guess_type(real_filename) # type: ignore |
| 253 | mime_type = get_content_type(guessed_type[0] or self.fallback_mimetype, "utf-8") |
| 254 | f, mtime, file_size = file_loader() |
| 255 | |
| 256 | headers = [("Date", http_date())] |
| 257 | |
| 258 | if self.cache: |
| 259 | timeout = self.cache_timeout |
| 260 | etag = self.generate_etag(mtime, file_size, real_filename) # type: ignore |
| 261 | headers += [ |
| 262 | ("Etag", f'"{etag}"'), |
| 263 | ("Cache-Control", f"max-age={timeout}, public"), |
| 264 | ] |
| 265 | |
| 266 | if not is_resource_modified(environ, etag, last_modified=mtime): |
| 267 | f.close() |
| 268 | start_response("304 Not Modified", headers) |
| 269 | return [] |
| 270 | |
| 271 | headers.append(("Expires", http_date(time() + timeout))) |
| 272 | else: |
| 273 | headers.append(("Cache-Control", "public")) |
| 274 | |
| 275 | headers.extend( |
| 276 | ( |
| 277 | ("Content-Type", mime_type), |
| 278 | ("Content-Length", str(file_size)), |
| 279 | ("Last-Modified", http_date(mtime)), |
| 280 | ) |
| 281 | ) |
| 282 | start_response("200 OK", headers) |
| 283 | return wrap_file(environ, f) |
nothing calls this directly
no test coverage detected