Changeset View
Changeset View
Standalone View
Standalone View
swh/search/utils.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
def stream_results(f, *args, **kwargs): | def stream_results(f, *args, **kwargs): | ||||
if 'cursor' in kwargs: | if 'scroll_token' in kwargs: | ||||
raise TypeError('stream_results has no argument "cursor".') | raise TypeError('stream_results has no argument "scroll_token".') | ||||
cursor = None | scroll_token = None | ||||
while True: | while True: | ||||
results = f(*args, cursor=cursor, **kwargs) | results = f(*args, scroll_token=scroll_token, **kwargs) | ||||
yield from results['results'] | yield from results['results'] | ||||
cursor = results['cursor'] | scroll_token = results['scroll_token'] | ||||
if cursor is None: | if scroll_token is None: | ||||
break | break |