diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 58900823d075..bda8facfec96 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -1,9 +1,11 @@ # Release History -## 1.19.2 (Unreleased) +## 1.20.0 (Unreleased) ### Features Added +- add kwargs to the methods for `iter_raw` and `iter_bytes` #21529 + ### Breaking Changes ### Bugs Fixed diff --git a/sdk/core/azure-core/azure/core/_version.py b/sdk/core/azure-core/azure/core/_version.py index 6c8b9f65e0fd..229982c5253b 100644 --- a/sdk/core/azure-core/azure/core/_version.py +++ b/sdk/core/azure-core/azure/core/_version.py @@ -9,4 +9,4 @@ # regenerated. # -------------------------------------------------------------------------- -VERSION = "1.19.2" +VERSION = "1.20.0" diff --git a/sdk/core/azure-core/azure/core/rest/_http_response_impl.py b/sdk/core/azure-core/azure/core/rest/_http_response_impl.py index 44badd1eb9d6..378677b25c9b 100644 --- a/sdk/core/azure-core/azure/core/rest/_http_response_impl.py +++ b/sdk/core/azure-core/azure/core/rest/_http_response_impl.py @@ -392,8 +392,8 @@ def read(self): self._set_read_checks() return self.content - def iter_bytes(self): - # type: () -> Iterator[bytes] + def iter_bytes(self, **kwargs): + # type: (Any) -> Iterator[bytes] """Iterates over the response's bytes. Will decompress in the process. :return: An iterator of bytes from the response @@ -413,8 +413,8 @@ def iter_bytes(self): yield part self.close() - def iter_raw(self): - # type: () -> Iterator[bytes] + def iter_raw(self, **kwargs): + # type: (Any) -> Iterator[bytes] """Iterates over the response's bytes. Will not decompress in the process. :return: An iterator of bytes from the response @@ -453,10 +453,10 @@ class RestHttpClientTransportResponse(_RestHttpClientTransportResponseBase, Http """Create a Rest HTTPResponse from an http.client response. """ - def iter_bytes(self): + def iter_bytes(self, **kwargs): raise TypeError("We do not support iter_bytes for this transport response") - def iter_raw(self): + def iter_raw(self, **kwargs): raise TypeError("We do not support iter_raw for this transport response") def read(self): diff --git a/sdk/core/azure-core/azure/core/rest/_http_response_impl_async.py b/sdk/core/azure-core/azure/core/rest/_http_response_impl_async.py index 6bc93ea0b2e0..2674ba1de450 100644 --- a/sdk/core/azure-core/azure/core/rest/_http_response_impl_async.py +++ b/sdk/core/azure-core/azure/core/rest/_http_response_impl_async.py @@ -23,7 +23,7 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- -from typing import AsyncIterator +from typing import Any, AsyncIterator from ._rest_py3 import AsyncHttpResponse as _AsyncHttpResponse from ._http_response_impl import ( _HttpResponseBaseImpl, _HttpResponseBackcompatMixinBase, _RestHttpClientTransportResponseBase @@ -90,7 +90,7 @@ async def read(self) -> bytes: await self._set_read_checks() return self._content - async def iter_raw(self) -> AsyncIterator[bytes]: + async def iter_raw(self, **kwargs: Any) -> AsyncIterator[bytes]: """Asynchronously iterates over the response's bytes. Will not decompress in the process :return: An async iterator of bytes from the response :rtype: AsyncIterator[bytes] @@ -102,7 +102,7 @@ async def iter_raw(self) -> AsyncIterator[bytes]: yield part await self.close() - async def iter_bytes(self) -> AsyncIterator[bytes]: + async def iter_bytes(self, **kwargs: Any) -> AsyncIterator[bytes]: """Asynchronously iterates over the response's bytes. Will decompress in the process :return: An async iterator of bytes from the response :rtype: AsyncIterator[bytes] @@ -145,10 +145,10 @@ class RestAsyncHttpClientTransportResponse(_RestHttpClientTransportResponseBase, """Create a Rest HTTPResponse from an http.client response. """ - async def iter_bytes(self): + async def iter_bytes(self, **kwargs): raise TypeError("We do not support iter_bytes for this transport response") - async def iter_raw(self): + async def iter_raw(self, **kwargs): raise TypeError("We do not support iter_raw for this transport response") async def read(self): diff --git a/sdk/core/azure-core/azure/core/rest/_rest.py b/sdk/core/azure-core/azure/core/rest/_rest.py index db4dc90dfcf6..6d766b5d26d8 100644 --- a/sdk/core/azure-core/azure/core/rest/_rest.py +++ b/sdk/core/azure-core/azure/core/rest/_rest.py @@ -361,8 +361,8 @@ def read(self): """ @abc.abstractmethod - def iter_raw(self): - # type: () -> Iterator[bytes] + def iter_raw(self, **kwargs): + # type: (Any) -> Iterator[bytes] """Iterates over the response's bytes. Will not decompress in the process. :return: An iterator of bytes from the response @@ -370,8 +370,8 @@ def iter_raw(self): """ @abc.abstractmethod - def iter_bytes(self): - # type: () -> Iterator[bytes] + def iter_bytes(self, **kwargs): + # type: (Any) -> Iterator[bytes] """Iterates over the response's bytes. Will decompress in the process. :return: An iterator of bytes from the response diff --git a/sdk/core/azure-core/azure/core/rest/_rest_py3.py b/sdk/core/azure-core/azure/core/rest/_rest_py3.py index b3fa25445f67..42d7d9d9bf38 100644 --- a/sdk/core/azure-core/azure/core/rest/_rest_py3.py +++ b/sdk/core/azure-core/azure/core/rest/_rest_py3.py @@ -352,7 +352,7 @@ def read(self) -> bytes: ... @abc.abstractmethod - def iter_raw(self) -> Iterator[bytes]: + def iter_raw(self, **kwargs: Any) -> Iterator[bytes]: """Iterates over the response's bytes. Will not decompress in the process. :return: An iterator of bytes from the response @@ -361,7 +361,7 @@ def iter_raw(self) -> Iterator[bytes]: ... @abc.abstractmethod - def iter_bytes(self) -> Iterator[bytes]: + def iter_bytes(self, **kwargs: Any) -> Iterator[bytes]: """Iterates over the response's bytes. Will decompress in the process. :return: An iterator of bytes from the response @@ -403,7 +403,7 @@ async def read(self) -> bytes: ... @abc.abstractmethod - async def iter_raw(self) -> AsyncIterator[bytes]: + async def iter_raw(self, **kwargs: Any) -> AsyncIterator[bytes]: """Asynchronously iterates over the response's bytes. Will not decompress in the process. :return: An async iterator of bytes from the response @@ -414,7 +414,7 @@ async def iter_raw(self) -> AsyncIterator[bytes]: yield # pylint: disable=unreachable @abc.abstractmethod - async def iter_bytes(self) -> AsyncIterator[bytes]: + async def iter_bytes(self, **kwargs: Any) -> AsyncIterator[bytes]: """Asynchronously iterates over the response's bytes. Will decompress in the process. :return: An async iterator of bytes from the response diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py index 2b8a68cb7bd1..14693420c133 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py @@ -203,3 +203,17 @@ async def test_error_reading(client): await response.read() assert response.content == b"" await client.close() + +@pytest.mark.asyncio +async def test_pass_kwarg_to_iter_bytes(client): + request = HttpRequest("GET", "/basic/string") + response = await client.send_request(request, stream=True) + async for part in response.iter_bytes(chunk_size=5): + assert part + +@pytest.mark.asyncio +async def test_pass_kwarg_to_iter_raw(client): + request = HttpRequest("GET", "/basic/string") + response = await client.send_request(request, stream=True) + async for part in response.iter_raw(chunk_size=5): + assert part diff --git a/sdk/core/azure-core/tests/test_rest_stream_responses.py b/sdk/core/azure-core/tests/test_rest_stream_responses.py index 841927430b83..2b255f8a5f83 100644 --- a/sdk/core/azure-core/tests/test_rest_stream_responses.py +++ b/sdk/core/azure-core/tests/test_rest_stream_responses.py @@ -229,3 +229,15 @@ def test_error_reading(client): response.read() assert response.content == b"" # try giving a really slow response, see what happens + +def test_pass_kwarg_to_iter_bytes(client): + request = HttpRequest("GET", "/basic/string") + response = client.send_request(request, stream=True) + for part in response.iter_bytes(chunk_size=5): + assert part + +def test_pass_kwarg_to_iter_raw(client): + request = HttpRequest("GET", "/basic/string") + response = client.send_request(request, stream=True) + for part in response.iter_raw(chunk_size=5): + assert part