File tree Expand file tree Collapse file tree 2 files changed +24
-16
lines changed
Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 55from .._types import URL , Headers , TimeoutDict
66
77
8- async def empty () -> AsyncIterator :
9- yield b""
10-
11-
128class NewConnectionRequired (Exception ):
139 pass
1410
@@ -45,17 +41,25 @@ class AsyncByteStream:
4541 """
4642
4743 def __init__ (
48- self , aiterator : AsyncIterator [bytes ] = None , aclose_func : Callable = None ,
44+ self ,
45+ content : bytes = b"" ,
46+ aiterator : AsyncIterator [bytes ] = None ,
47+ aclose_func : Callable = None ,
4948 ) -> None :
50- self .aiterator = empty () if aiterator is None else aiterator
49+ assert aiterator is None or not content
50+ self .content = content
51+ self .aiterator = aiterator
5152 self .aclose_func = aclose_func
5253
5354 async def __aiter__ (self ) -> AsyncIterator [bytes ]:
5455 """
5556 Yield bytes representing the request or response body.
5657 """
57- async for chunk in self .aiterator :
58- yield chunk
58+ if self .aiterator is None :
59+ yield self .content
60+ else :
61+ async for chunk in self .aiterator :
62+ yield chunk
5963
6064 async def aclose (self ) -> None :
6165 """
Original file line number Diff line number Diff line change 55from .._types import URL , Headers , TimeoutDict
66
77
8- def empty () -> Iterator :
9- yield b""
10-
11-
128class NewConnectionRequired (Exception ):
139 pass
1410
@@ -45,17 +41,25 @@ class SyncByteStream:
4541 """
4642
4743 def __init__ (
48- self , iterator : Iterator [bytes ] = None , close_func : Callable = None ,
44+ self ,
45+ content : bytes = b"" ,
46+ iterator : Iterator [bytes ] = None ,
47+ close_func : Callable = None ,
4948 ) -> None :
50- self .iterator = empty () if iterator is None else iterator
49+ assert iterator is None or not content
50+ self .content = content
51+ self .iterator = iterator
5152 self .close_func = close_func
5253
5354 def __iter__ (self ) -> Iterator [bytes ]:
5455 """
5556 Yield bytes representing the request or response body.
5657 """
57- for chunk in self .iterator :
58- yield chunk
58+ if self .iterator is None :
59+ yield self .content
60+ else :
61+ for chunk in self .iterator :
62+ yield chunk
5963
6064 def close (self ) -> None :
6165 """
You can’t perform that action at this time.
0 commit comments