Skip to content

Commit

Permalink
fix AioPageIterator search method (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-jones committed Oct 7, 2020
1 parent fedb9d2 commit 0ae9be3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aiobotocore/paginate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from botocore.utils import set_value_from_jmespath, merge_dicts
from botocore.compat import six

import jmespath
import aioitertools


Expand Down Expand Up @@ -129,6 +130,16 @@ async def build_full_result(self):
complete_result['NextToken'] = self.resume_token
return complete_result

async def search(self, expression):
compiled = jmespath.compile(expression)
async for page in self:
results = compiled.search(page)
if isinstance(results, list):
for element in results:
yield element
else:
yield results


class AioPaginator(Paginator):
PAGE_ITERATOR_CLS = AioPageIterator
Expand Down
16 changes: 16 additions & 0 deletions tests/test_basic_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ async def test_can_paginate_with_page_size(
assert key_names == ['key0', 'key1', 'key2', 'key3', 'key4']


@pytest.mark.asyncio
@pytest.mark.moto
async def test_can_search_paginate(
s3_client, bucket_name, create_object):
keys = []
for i in range(5):
key_name = 'key%s' % i
keys.append(key_name)
await create_object(key_name)

paginator = s3_client.get_paginator('list_objects')
page_iter = paginator.paginate(Bucket=bucket_name)
async for key_name in page_iter.search('Contents[*].Key'):
assert key_name in keys


@pytest.mark.asyncio
@pytest.mark.moto
async def test_can_paginate_iterator(s3_client, bucket_name, create_object):
Expand Down

0 comments on commit 0ae9be3

Please sign in to comment.