def get_page_of_iterator(iterator, page_size, page_number):
try:<EOL><INDENT>page_number = validate_page_number(page_number)<EOL><DEDENT>except (PageNotAnInteger, EmptyPage):<EOL><INDENT>page_number = <NUM_LIT:1><EOL><DEDENT>start = (page_number - <NUM_LIT:1>) * page_size<EOL>end = (page_number * page_size) + <NUM_LIT:1><EOL>skipped_items = list(islice(iterator, start))<EOL>items = list(islice(iterator, end))<EOL>if len(items) == <NUM_LIT:0> and page_number != <NUM_LIT:1>:<EOL><INDENT>items = skipped_items<EOL>page_number = <NUM_LIT:1><EOL><DEDENT>has_next = len(items) > page_size<EOL>items = items[:page_size]<EOL>return NoCountPage(items, page_number, page_size, has_next)<EOL>
Get a page from an interator, handling invalid input from the page number
by defaulting to the first page.