Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rest] add kwargs to iter_bytes and iter_raw #21529

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Release History

## 1.19.1 (Unreleased)
## 1.20.0 (Unreleased)

### Features Added

- add kwargs to the methods for `iter_raw` and `iter_bytes` #21529

### Breaking Changes

### Bugs Fixed
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# regenerated.
# --------------------------------------------------------------------------

VERSION = "1.19.1"
VERSION = "1.20.0"
12 changes: 6 additions & 6 deletions sdk/core/azure-core/azure/core/rest/_http_response_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure-core/azure/core/rest/_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ 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
:rtype: Iterator[str]
"""

@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
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure-core/azure/core/rest/_rest_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions sdk/core/azure-core/tests/test_rest_stream_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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