(data_function, args_provider, event_handler=None)
Repeatedly call a data provider function with successive sets of arguments provided
    by the ``args_provider``

    :param data_function: function to paginate. Must return an list of data elements.
    :param args_provider: An instance of the ``ArgsProvider`` class which is used to
    generate the arguments that get passed to ``data_function``
    :param event_handler: class to be notified on page start and page end.
Repeatedly call a data provider function with successive sets of arguments provided
    by the ``args_provider``
Repeatedly call a data provider function with successive sets of arguments provided by the args_provider
def paginate_function(data_function, args_provider, event_handler=None):
    """
    Repeatedly call a data provider function with successive sets of arguments provided
    by the ``args_provider``

    :param data_function: function to paginate. Must return an list of data elements.
    :param args_provider: An instance of the ``ArgsProvider`` class which is used to
    generate the arguments that get passed to ``data_function``
    :param event_handler: class to be notified on page start and page end.
    """
    event_handler = event_handler or PaginationEventHandler()
    total_emitted = 0
    args, kwargs = args_provider.get_initial_args()

    while True:
        event_handler.page_start(total_emitted, *args, **kwargs)
        results = data_function(*args, **kwargs)
        start_time = datetime.utcnow()

        try:
            results = list(results)
        except Exception as e:
            if event_handler.page_exception(e):
                continue
            raise

        results = args_provider.adjust_results(results, args, kwargs)
        event_handler.page(results)
        for item in results:
            yield item

        total_emitted += len(results)
        event_handler.page_end(total_emitted, datetime.utcnow() - start_time, *args, **kwargs)

        item = item if results else None
        try:
            args, kwargs = args_provider.get_next_args(item, *args, **kwargs)
        except StopIteration:
            event_handler.stop()
            break
def paginate_function ( data_function , args_provider , event_handler = None ) : event_handler = event_handler or PaginationEventHandler ( ) total_emitted = 0 args , kwargs = args_provider . get_initial_args ( ) while True : event_handler . page_start ( total_emitted , * args , * * kwargs ) results = data_function ( * args , * * kwargs ) start_time = datetime . utcnow ( ) try : results = list ( results ) except Exception as e : if event_handler . page_exception ( e ) : continue raise results = args_provider . adjust_results ( results , args , kwargs ) event_handler . page ( results ) for item in results : yield item total_emitted += len ( results ) event_handler . page_end ( total_emitted , datetime . utcnow ( ) - start_time , * args , * * kwargs ) item = item if results else None try : args , kwargs = args_provider . get_next_args ( item , * args , * * kwargs ) except StopIteration : event_handler . stop ( ) break