Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def paginate(method, search=None, **kwargs):
- client = method.__self__
- paginator = client.get_paginator(method.__name__)
- pagination = paginator.paginate(**kwargs)
- if search:
- yield from pagination.search(search)
- elif len(pagination.result_keys) == 1:
- for page in pagination.result_key_iters():
- yield from page
- else:
- raise ValueError('{} has multiple result keys; pass a JMESpath expression'.format(method.__name__))
Add Comment
Please, Sign In to add comment