A blueprint is a collection of application properties. The application properties include routes, error handlers, and before and after request functions. It is useful to produce modular code as it allows the properties to be defined in a blueprint thereby deferring the addition of t
| 38 | |
| 39 | |
| 40 | class Blueprint(SansioBlueprint): |
| 41 | """A blueprint is a collection of application properties. |
| 42 | |
| 43 | The application properties include routes, error handlers, and |
| 44 | before and after request functions. It is useful to produce |
| 45 | modular code as it allows the properties to be defined in a |
| 46 | blueprint thereby deferring the addition of these properties to the |
| 47 | app. |
| 48 | """ |
| 49 | |
| 50 | def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: |
| 51 | super().__init__(*args, **kwargs) |
| 52 | |
| 53 | self.cli = AppGroup() |
| 54 | self.cli.name = self.name |
| 55 | |
| 56 | self.after_websocket_funcs: dict[ |
| 57 | AppOrBlueprintKey, list[AfterWebsocketCallable] |
| 58 | ] = defaultdict(list) |
| 59 | self.before_websocket_funcs: dict[ |
| 60 | AppOrBlueprintKey, list[BeforeWebsocketCallable] |
| 61 | ] = defaultdict(list) |
| 62 | self.teardown_websocket_funcs: dict[ |
| 63 | AppOrBlueprintKey, list[TeardownCallable] |
| 64 | ] = defaultdict(list) |
| 65 | |
| 66 | def get_send_file_max_age(self, filename: str | None) -> int | None: |
| 67 | """Used by :func:`send_file` to determine the ``max_age`` cache |
| 68 | value for a given file path if it wasn't passed. |
| 69 | |
| 70 | By default, this returns :data:`SEND_FILE_MAX_AGE_DEFAULT` from |
| 71 | the configuration of :data:`~flask.current_app`. This defaults |
| 72 | to ``None``, which tells the browser to use conditional requests |
| 73 | instead of a timed cache, which is usually preferable. |
| 74 | |
| 75 | Note this is a duplicate of the same method in the Quart |
| 76 | class. |
| 77 | |
| 78 | """ |
| 79 | value = current_app.config["SEND_FILE_MAX_AGE_DEFAULT"] |
| 80 | |
| 81 | if value is None: |
| 82 | return None |
| 83 | |
| 84 | if isinstance(value, timedelta): |
| 85 | return int(value.total_seconds()) |
| 86 | |
| 87 | return value |
| 88 | return None |
| 89 | |
| 90 | async def send_static_file(self, filename: str) -> Response: |
| 91 | if not self.has_static_folder: |
| 92 | raise RuntimeError("No static folder for this object") |
| 93 | return await send_from_directory(self.static_folder, filename) |
| 94 | |
| 95 | async def open_resource( |
| 96 | self, |
| 97 | path: FilePath, |
no outgoing calls
searching dependent graphs…