|
4 | 4 | import sys
|
5 | 5 | import typing as t
|
6 | 6 | import warnings
|
| 7 | +from datetime import datetime |
7 | 8 | from datetime import timedelta
|
8 | 9 | from functools import update_wrapper
|
9 | 10 | from threading import RLock
|
@@ -436,14 +437,16 @@ def get_flashed_messages(
|
436 | 437 |
|
437 | 438 |
|
438 | 439 | def _prepare_send_file_kwargs(
|
439 |
| - download_name=None, |
440 |
| - attachment_filename=None, |
441 |
| - etag=None, |
442 |
| - add_etags=None, |
443 |
| - max_age=None, |
444 |
| - cache_timeout=None, |
445 |
| - **kwargs, |
446 |
| -): |
| 440 | + download_name: t.Optional[str] = None, |
| 441 | + attachment_filename: t.Optional[str] = None, |
| 442 | + etag: t.Optional[t.Union[bool, str]] = None, |
| 443 | + add_etags: t.Optional[t.Union[bool]] = None, |
| 444 | + max_age: t.Optional[ |
| 445 | + t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]] |
| 446 | + ] = None, |
| 447 | + cache_timeout: t.Optional[int] = None, |
| 448 | + **kwargs: t.Any, |
| 449 | +) -> t.Dict[str, t.Any]: |
447 | 450 | if attachment_filename is not None:
|
448 | 451 | warnings.warn(
|
449 | 452 | "The 'attachment_filename' parameter has been renamed to"
|
@@ -482,23 +485,25 @@ def _prepare_send_file_kwargs(
|
482 | 485 | max_age=max_age,
|
483 | 486 | use_x_sendfile=current_app.use_x_sendfile,
|
484 | 487 | response_class=current_app.response_class,
|
485 |
| - _root_path=current_app.root_path, |
| 488 | + _root_path=current_app.root_path, # type: ignore |
486 | 489 | )
|
487 | 490 | return kwargs
|
488 | 491 |
|
489 | 492 |
|
490 | 493 | def send_file(
|
491 |
| - path_or_file, |
492 |
| - mimetype=None, |
493 |
| - as_attachment=False, |
494 |
| - download_name=None, |
495 |
| - attachment_filename=None, |
496 |
| - conditional=True, |
497 |
| - etag=True, |
498 |
| - add_etags=None, |
499 |
| - last_modified=None, |
500 |
| - max_age=None, |
501 |
| - cache_timeout=None, |
| 494 | + path_or_file: t.Union[os.PathLike, str, t.BinaryIO], |
| 495 | + mimetype: t.Optional[str] = None, |
| 496 | + as_attachment: bool = False, |
| 497 | + download_name: t.Optional[str] = None, |
| 498 | + attachment_filename: t.Optional[str] = None, |
| 499 | + conditional: bool = True, |
| 500 | + etag: t.Union[bool, str] = True, |
| 501 | + add_etags: t.Optional[bool] = None, |
| 502 | + last_modified: t.Optional[t.Union[datetime, int, float]] = None, |
| 503 | + max_age: t.Optional[ |
| 504 | + t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]] |
| 505 | + ] = None, |
| 506 | + cache_timeout: t.Optional[int] = None, |
502 | 507 | ):
|
503 | 508 | """Send the contents of a file to the client.
|
504 | 509 |
|
@@ -643,7 +648,10 @@ def safe_join(directory: str, *pathnames: str) -> str:
|
643 | 648 |
|
644 | 649 |
|
645 | 650 | def send_from_directory(
|
646 |
| - directory: str, path: str, filename: t.Optional[str] = None, **kwargs: t.Any |
| 651 | + directory: t.Union[os.PathLike, str], |
| 652 | + path: t.Union[os.PathLike, str], |
| 653 | + filename: t.Optional[str] = None, |
| 654 | + **kwargs: t.Any, |
647 | 655 | ) -> "Response":
|
648 | 656 | """Send a file from within a directory using :func:`send_file`.
|
649 | 657 |
|
|
0 commit comments