MCPcopy
hub / github.com/pallets/werkzeug / wrap_file

Function wrap_file

src/werkzeug/wsgi.py:277–297  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

275
276
277def 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
300class FileWrapper:

Callers 6

test_range_wrapperFunction · 0.90
view_fileFunction · 0.90
send_fileFunction · 0.85
__call__Method · 0.85

Calls 1

getMethod · 0.45

Tested by 3

test_range_wrapperFunction · 0.72