Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simplify ItemPaged
  • Loading branch information
lmazuel committed Jul 22, 2019
commit 62324e45de25b0565934cf619d0c4b79ddf0ebc8
26 changes: 9 additions & 17 deletions sdk/core/azure-core/azure/core/async_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,27 @@ async def __anext__(self):


class AsyncItemPaged(AsyncIterator[ReturnType]):
def __init__(
self,
get_next: Callable[[str], Awaitable[ResponseType]],
extract_data: Callable[
[ResponseType], Awaitable[Tuple[str, AsyncIterator[ReturnType]]]
],
page_iterator_class=AsyncPageIterator,
) -> None:
def __init__(self, *args, **kwargs) -> None:
"""Return an async iterator of items.

:param get_next: Callable that take the continuation token and return a HTTP response
:param extract_data: Callable that take an HTTP response and return a tuple continuation token,
list of ReturnType
args and kwargs will be passed to the AsyncPageIterator constructor directly,
except page_iterator_class
"""
self._get_next = get_next
self._extract_data = extract_data
self._args = args
self._kwargs = kwargs
self._page_iterator = (
None
) # type: Optional[AsyncIterator[AsyncIterator[ReturnType]]]
self._page = None # type: Optional[AsyncIterator[ReturnType]]
self._page_iterator_class = page_iterator_class
self._page_iterator_class = self._kwargs.pop(
"page_iterator_class", AsyncPageIterator
)

def by_page(
self, continuation_token: Optional[str] = None
) -> AsyncIterator[AsyncIterator[ReturnType]]:
return self._page_iterator_class(
get_next=self._get_next,
extract_data=self._extract_data,
continuation_token=continuation_token,
*self._args, **self._kwargs, continuation_token=continuation_token
)

async def __anext__(self) -> ReturnType:
Expand Down
21 changes: 9 additions & 12 deletions sdk/core/azure-core/azure/core/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,24 @@ def __next__(self):


class ItemPaged(Iterator[ReturnType]):
def __init__(self, get_next, extract_data, page_iterator_class=PageIterator):
# type: (Callable[[str], ResponseType], Callable[[ResponseType], Tuple[str, Iterator[ReturnType]]], Type) -> None
def __init__(self, *args, **kwargs):
"""Return an iterator of items.

:param get_next: Callable that take the continuation token and return a HTTP response
:param extract_data: Callable that take an HTTP response and return a tuple continuation token,
list of ReturnType
:param page_iterator_class: The type to use for page iterator
args and kwargs will be passed to the PageIterator constructor directly,
except page_iterator_class
"""
self._get_next = get_next
self._extract_data = extract_data
self._args = args
self._kwargs = kwargs
self._page_iterator = None
self._page = None
self._page_iterator_class = page_iterator_class
self._page_iterator_class = self._kwargs.pop(
"page_iterator_class", PageIterator
)

def by_page(self, continuation_token=None):
# type: (Optional[str]) -> Iterator[Iterator[ReturnType]]
return self._page_iterator_class(
get_next=self._get_next,
extract_data=self._extract_data,
continuation_token=continuation_token,
*self._args, **self._kwargs, continuation_token=continuation_token
)

def __iter__(self):
Expand Down