ci/utils.py
def get_page_of_iterator(iterator, page_size, page_number):
    """
    Get a page from an interator, handling invalid input from the page number
    by defaulting to the first page.
    """
    try:
        page_number = validate_page_number(page_number)
    except (PageNotAnInteger, EmptyPage):
        page_number = 1

    start = (page_number - 1) * page_size
    # End 1 more than we need, so that we can see if there's another page
    end = (page_number * page_size) + 1
    skipped_items = list(islice(iterator, start))
    items = list(islice(iterator, end))

    if len(items) == 0 and page_number != 1:
        items = skipped_items
        page_number = 1

    has_next = len(items) > page_size
    items = items[:page_size]

    return NoCountPage(items, page_number, page_size, has_next)
def get_page_of_iterator(iterator, page_size, page_number):
    try:
        page_number = validate_page_number(page_number)
    except (PageNotAnInteger, EmptyPage):
        page_number = 1

    start = (page_number - 1) * page_size
    # End 1 more than we need, so that we can see if there's another page
    end = (page_number * page_size) + 1
    skipped_items = list(islice(iterator, start))
    items = list(islice(iterator, end))

    if len(items) == 0 and page_number != 1:
        items = skipped_items
        page_number = 1

    has_next = len(items) > page_size
    items = items[:page_size]

    return NoCountPage(items, page_number, page_size, has_next)
def get_page_of_iterator ( iterator , page_size , page_number ) : try : page_number = validate_page_number ( page_number ) except ( PageNotAnInteger , EmptyPage ) : page_number = 1 start = ( page_number - 1 ) * page_size # End 1 more than we need, so that we can see if there's another page end = ( page_number * page_size ) + 1 skipped_items = list ( islice ( iterator , start ) ) items = list ( islice ( iterator , end ) ) if len ( items ) == 0 and page_number != 1 : items = skipped_items page_number = 1 has_next = len ( items ) > page_size items = items [ : page_size ] return NoCountPage ( items , page_number , page_size , has_next )
Get a page from an interator, handling invalid input from the page number
    by defaulting to the first page.
Get a page from an interator handling invalid input from the page number by defaulting to the first page .