Skip to content

Commit 74badfa

Browse files
authored
[rest] add kwargs to iter_bytes and iter_raw (Azure#21529)
1 parent 973b3c1 commit 74badfa

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

sdk/core/azure-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- add kwargs to the methods for `iter_raw` and `iter_bytes` #21529
8+
79
### Breaking Changes
810

911
- SansIOHTTPPolicy.on_exception returns None instead of bool.

sdk/core/azure-core/azure/core/rest/_http_response_impl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ def read(self):
392392
self._set_read_checks()
393393
return self.content
394394

395-
def iter_bytes(self):
396-
# type: () -> Iterator[bytes]
395+
def iter_bytes(self, **kwargs):
396+
# type: (Any) -> Iterator[bytes]
397397
"""Iterates over the response's bytes. Will decompress in the process.
398398
399399
:return: An iterator of bytes from the response
@@ -413,8 +413,8 @@ def iter_bytes(self):
413413
yield part
414414
self.close()
415415

416-
def iter_raw(self):
417-
# type: () -> Iterator[bytes]
416+
def iter_raw(self, **kwargs):
417+
# type: (Any) -> Iterator[bytes]
418418
"""Iterates over the response's bytes. Will not decompress in the process.
419419
420420
:return: An iterator of bytes from the response
@@ -453,10 +453,10 @@ class RestHttpClientTransportResponse(_RestHttpClientTransportResponseBase, Http
453453
"""Create a Rest HTTPResponse from an http.client response.
454454
"""
455455

456-
def iter_bytes(self):
456+
def iter_bytes(self, **kwargs):
457457
raise TypeError("We do not support iter_bytes for this transport response")
458458

459-
def iter_raw(self):
459+
def iter_raw(self, **kwargs):
460460
raise TypeError("We do not support iter_raw for this transport response")
461461

462462
def read(self):

sdk/core/azure-core/azure/core/rest/_http_response_impl_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# IN THE SOFTWARE.
2424
#
2525
# --------------------------------------------------------------------------
26-
from typing import AsyncIterator
26+
from typing import Any, AsyncIterator
2727
from ._rest_py3 import AsyncHttpResponse as _AsyncHttpResponse
2828
from ._http_response_impl import (
2929
_HttpResponseBaseImpl, _HttpResponseBackcompatMixinBase, _RestHttpClientTransportResponseBase
@@ -90,7 +90,7 @@ async def read(self) -> bytes:
9090
await self._set_read_checks()
9191
return self._content
9292

93-
async def iter_raw(self) -> AsyncIterator[bytes]:
93+
async def iter_raw(self, **kwargs: Any) -> AsyncIterator[bytes]:
9494
"""Asynchronously iterates over the response's bytes. Will not decompress in the process
9595
:return: An async iterator of bytes from the response
9696
:rtype: AsyncIterator[bytes]
@@ -102,7 +102,7 @@ async def iter_raw(self) -> AsyncIterator[bytes]:
102102
yield part
103103
await self.close()
104104

105-
async def iter_bytes(self) -> AsyncIterator[bytes]:
105+
async def iter_bytes(self, **kwargs: Any) -> AsyncIterator[bytes]:
106106
"""Asynchronously iterates over the response's bytes. Will decompress in the process
107107
:return: An async iterator of bytes from the response
108108
:rtype: AsyncIterator[bytes]
@@ -145,10 +145,10 @@ class RestAsyncHttpClientTransportResponse(_RestHttpClientTransportResponseBase,
145145
"""Create a Rest HTTPResponse from an http.client response.
146146
"""
147147

148-
async def iter_bytes(self):
148+
async def iter_bytes(self, **kwargs):
149149
raise TypeError("We do not support iter_bytes for this transport response")
150150

151-
async def iter_raw(self):
151+
async def iter_raw(self, **kwargs):
152152
raise TypeError("We do not support iter_raw for this transport response")
153153

154154
async def read(self):

sdk/core/azure-core/azure/core/rest/_rest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,17 @@ def read(self):
361361
"""
362362

363363
@abc.abstractmethod
364-
def iter_raw(self):
365-
# type: () -> Iterator[bytes]
364+
def iter_raw(self, **kwargs):
365+
# type: (Any) -> Iterator[bytes]
366366
"""Iterates over the response's bytes. Will not decompress in the process.
367367
368368
:return: An iterator of bytes from the response
369369
:rtype: Iterator[str]
370370
"""
371371

372372
@abc.abstractmethod
373-
def iter_bytes(self):
374-
# type: () -> Iterator[bytes]
373+
def iter_bytes(self, **kwargs):
374+
# type: (Any) -> Iterator[bytes]
375375
"""Iterates over the response's bytes. Will decompress in the process.
376376
377377
:return: An iterator of bytes from the response

sdk/core/azure-core/azure/core/rest/_rest_py3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def read(self) -> bytes:
352352
...
353353

354354
@abc.abstractmethod
355-
def iter_raw(self) -> Iterator[bytes]:
355+
def iter_raw(self, **kwargs: Any) -> Iterator[bytes]:
356356
"""Iterates over the response's bytes. Will not decompress in the process.
357357
358358
:return: An iterator of bytes from the response
@@ -361,7 +361,7 @@ def iter_raw(self) -> Iterator[bytes]:
361361
...
362362

363363
@abc.abstractmethod
364-
def iter_bytes(self) -> Iterator[bytes]:
364+
def iter_bytes(self, **kwargs: Any) -> Iterator[bytes]:
365365
"""Iterates over the response's bytes. Will decompress in the process.
366366
367367
:return: An iterator of bytes from the response
@@ -403,7 +403,7 @@ async def read(self) -> bytes:
403403
...
404404

405405
@abc.abstractmethod
406-
async def iter_raw(self) -> AsyncIterator[bytes]:
406+
async def iter_raw(self, **kwargs: Any) -> AsyncIterator[bytes]:
407407
"""Asynchronously iterates over the response's bytes. Will not decompress in the process.
408408
409409
:return: An async iterator of bytes from the response
@@ -414,7 +414,7 @@ async def iter_raw(self) -> AsyncIterator[bytes]:
414414
yield # pylint: disable=unreachable
415415

416416
@abc.abstractmethod
417-
async def iter_bytes(self) -> AsyncIterator[bytes]:
417+
async def iter_bytes(self, **kwargs: Any) -> AsyncIterator[bytes]:
418418
"""Asynchronously iterates over the response's bytes. Will decompress in the process.
419419
420420
:return: An async iterator of bytes from the response

sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,17 @@ async def test_error_reading(client):
203203
await response.read()
204204
assert response.content == b""
205205
await client.close()
206+
207+
@pytest.mark.asyncio
208+
async def test_pass_kwarg_to_iter_bytes(client):
209+
request = HttpRequest("GET", "/basic/string")
210+
response = await client.send_request(request, stream=True)
211+
async for part in response.iter_bytes(chunk_size=5):
212+
assert part
213+
214+
@pytest.mark.asyncio
215+
async def test_pass_kwarg_to_iter_raw(client):
216+
request = HttpRequest("GET", "/basic/string")
217+
response = await client.send_request(request, stream=True)
218+
async for part in response.iter_raw(chunk_size=5):
219+
assert part

sdk/core/azure-core/tests/test_rest_stream_responses.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,15 @@ def test_error_reading(client):
229229
response.read()
230230
assert response.content == b""
231231
# try giving a really slow response, see what happens
232+
233+
def test_pass_kwarg_to_iter_bytes(client):
234+
request = HttpRequest("GET", "/basic/string")
235+
response = client.send_request(request, stream=True)
236+
for part in response.iter_bytes(chunk_size=5):
237+
assert part
238+
239+
def test_pass_kwarg_to_iter_raw(client):
240+
request = HttpRequest("GET", "/basic/string")
241+
response = client.send_request(request, stream=True)
242+
for part in response.iter_raw(chunk_size=5):
243+
assert part

0 commit comments

Comments
 (0)