Guest User

Untitled

a guest
Jul 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. def paginate(method, search=None, **kwargs):
  2. client = method.__self__
  3. paginator = client.get_paginator(method.__name__)
  4. pagination = paginator.paginate(**kwargs)
  5. if search:
  6. yield from pagination.search(search)
  7. elif len(pagination.result_keys) == 1:
  8. for page in pagination.result_key_iters():
  9. yield from page
  10. else:
  11. raise ValueError('{} has multiple result keys; pass a JMESpath expression'.format(method.__name__))
Add Comment
Please, Sign In to add comment