File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33from contextvars import ContextVar
4+ from typing import cast
45from typing import TYPE_CHECKING
56
67from werkzeug .local import LocalProxy
4748
4849
4950def _session_lookup () -> RequestContext | WebsocketContext :
50- try :
51- return _cv_request .get ()
52- except LookupError :
53- try :
54- return _cv_websocket .get ()
55- except LookupError :
56- raise RuntimeError ("Not within a request nor websocket context" ) from None
51+ missing = object ()
52+ ctx = _cv_request .get (missing )
53+ if ctx is not missing :
54+ return cast ("RequestContext" , ctx )
55+ ctx = _cv_websocket .get (missing )
56+ if ctx is not missing :
57+ return cast ("WebsocketContext" , ctx )
58+ raise RuntimeError ("Not within a request nor websocket context" )
5759
5860
5961session : SessionMixin = LocalProxy (_session_lookup , "session" ) # type: ignore[assignment]
Original file line number Diff line number Diff line change @@ -321,14 +321,11 @@ async def get_data(self, as_text: bool = False) -> str | bytes:
321321 """Return the body data."""
322322 if self .implicit_sequence_conversion :
323323 await self .make_sequence ()
324- result = "" if as_text else b""
324+ chunks = []
325325 async with self .response as body :
326326 async for data in body :
327- if as_text :
328- result += data .decode ()
329- else :
330- result += data
331- return result
327+ chunks .append (data .decode () if as_text else data )
328+ return ("" if as_text else b"" ).join (chunks )
332329
333330 def set_data (self , data : str | bytes ) -> None :
334331 """Set the response data.
You can’t perform that action at this time.
0 commit comments