File tree 1 file changed +8
-9
lines changed
1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -96,8 +96,10 @@ def parse_stream_helper(line: bytes) -> Optional[str]:
96
96
# and it will close http connection with TCP Reset
97
97
return None
98
98
if line .startswith (b"data: " ):
99
- line = line [len (b"data: " ) :]
100
- return line .decode ("utf-8" )
99
+ line = line [len (b"data: " ):]
100
+ return line .decode ("utf-8" )
101
+ else :
102
+ return None
101
103
return None
102
104
103
105
@@ -109,13 +111,10 @@ def parse_stream(rbody: Iterator[bytes]) -> Iterator[str]:
109
111
110
112
111
113
async def parse_stream_async (rbody : aiohttp .StreamReader ):
112
- async for chunk , _ in rbody .iter_chunks ():
113
- # While the `ChunkTupleAsyncStreamIterator` iterator is meant to iterate over chunks (and thus lines) it seems
114
- # to still sometimes return multiple lines at a time, so let's split the chunk by lines again.
115
- for line in chunk .splitlines ():
116
- _line = parse_stream_helper (line )
117
- if _line is not None :
118
- yield _line
114
+ async for line in rbody :
115
+ _line = parse_stream_helper (line )
116
+ if _line is not None :
117
+ yield _line
119
118
120
119
121
120
class APIRequestor :
You can’t perform that action at this time.
0 commit comments