Wraps a file. This uses the WSGI server's file wrapper if available or otherwise the generic :class:`FileWrapper`. .. versionadded:: 0.5 If the file wrapper from the WSGI server is used it's important to not iterate over it from inside the application but to pass it through un
(
environ: WSGIEnvironment, file: t.IO[bytes], buffer_size: int = 8192
)
| 275 | |
| 276 | |
| 277 | def wrap_file( |
| 278 | environ: WSGIEnvironment, file: t.IO[bytes], buffer_size: int = 8192 |
| 279 | ) -> t.Iterable[bytes]: |
| 280 | """Wraps a file. This uses the WSGI server's file wrapper if available |
| 281 | or otherwise the generic :class:`FileWrapper`. |
| 282 | |
| 283 | .. versionadded:: 0.5 |
| 284 | |
| 285 | If the file wrapper from the WSGI server is used it's important to not |
| 286 | iterate over it from inside the application but to pass it through |
| 287 | unchanged. If you want to pass out a file wrapper inside a response |
| 288 | object you have to set :attr:`Response.direct_passthrough` to `True`. |
| 289 | |
| 290 | More information about file wrappers are available in :pep:`333`. |
| 291 | |
| 292 | :param file: a :class:`file`-like object with a :meth:`~file.read` method. |
| 293 | :param buffer_size: number of bytes for one iteration. |
| 294 | """ |
| 295 | return environ.get("wsgi.file_wrapper", FileWrapper)( # type: ignore |
| 296 | file, buffer_size |
| 297 | ) |
| 298 | |
| 299 | |
| 300 | class FileWrapper: |