Check and Raise an Exception if needed
        
        Args:
            pageNum (int): Page number
            itemsPerPage (int): Number of items per Page
            
        Raises:
            ErrPaginationLimits: If we are out of limits
491465
def checkAndRaise(pageNum, itemsPerPage):
        
        if pageNum < 1:
            raise ErrPaginationLimits(ErrPaginationLimits.ERR_PAGE_NUM)
        
        if itemsPerPage < Settings.itemsPerPageMin or itemsPerPage > Settings.itemsPerPageMax:
            raise ErrPaginationLimits(ErrPaginationLimits.ERR_ITEMS_PER_PAGE)
1009767
def page_size(self) -> int:
        
        page_count = self.page_count
        return self.paginator.max_size + len(f'\nPage {page_count}/{page_count}')
567006
public ClientFilter withPage(int pageNumber, int amountPerPage) {
        parameters.put("page", pageNumber);
        parameters.put("per_page", amountPerPage);
        return this;
    }
448269
def handle_document_error(self, item_session: ItemSession) -> Actions:
        '''
        '''
        self._waiter.increment()

        self._statistics.errors[ServerError] += 1

        action = self.handle_response(item_session)

        if action == Actions.NORMAL:
            item_session.set_status(Status.error)

        return action
147071
function (page) {
        if (!lang.isNumber(page)) {
            page = this.getCurrentPage();
        }

        var perPage = this.get('rowsPerPage'),
            records = this.get('totalRecords'),
            start, end;

        if (!page || !perPage) {
            return null;
        }

        start = (page - 1) * perPage;
        if (records !== Paginator.VALUE_UNLIMITED) {
            if (start >= records) {
                return null;
            }
            end = Math.min(start + perPage, records) - 1;
        } else {
            end = start + perPage - 1;
        }

        return [start,end];
    }
73142
def expand_pagination(pages):
    """"""
    # If there is no hyphen, it's a single page, and we're good to go
    parts = pages.split('-')
    if len(parts) == 1: # No hyphen, so no split
        return pages
    elif len(parts) == 2:
        start = parts[0]
        end = parts[1]
        # If the end is the same number of digits as the start, then we
        # don't change anything!
        if len(start) == len(end):
            return pages
        # Otherwise, replace the last digits of start with the digits of end
        num_end_digits = len(end)
        new_end = start[:-num_end_digits] + end
        return '%s-%s' % (start, new_end)
    else: # More than one hyphen, something weird happened
        logger.warning("Multiple hyphens in page number: %s" % pages)
        return pages
1359870
def movePage(self, pno, to = -1):
        
        pl = list(range(len(self)))
        if pno < 0 or pno > pl[-1]:
            raise ValueError("'from' page number out of range")
        if to < -1 or to > pl[-1]:
            raise ValueError("'to' page number out of range")
        pl.remove(pno)
        if to == -1:
            pl.append(pno)
        else:
            pl.insert(to-1, pno)
        return self.select(pl)
472148
def filter_pages(pages, pagenum, pagename):
    
    if pagenum:
        try:
            pages = [list(pages)[pagenum - 1]]
        except IndexError:
            raise IndexError('Invalid page number: %d' % pagenum)

    if pagename:
        pages = [page for page in pages if page.name == pagename]
        if pages == []:
            raise IndexError('Page not found: pagename=%s' % pagename)

    return pages
1325919
public function paginate($page, $perPage = null)
    {
        $page = (int)$page;
        if ($page < 1) {
            $page = 1;
        }
        
        if ($perPage === null) {
            if (!$perPage = $this->select->getRawState('limit')) {
                throw new Exception\InvalidArgumentException(
                    "No per page passed and no limit is set"
                );
            }
        }
        
        $modelClass = $this->modelClass;
        $paginator  = new Paginator($this->select, $modelClass::adapter());
        $items      = $paginator->getItems(($page - 1) * $perPage, $perPage);
        $collection = $this->buildCollection($items->toArray());
        
        $collection->setPage($page);
        $collection->setPerPage($perPage);
        $collection->setPaginator($paginator);
        
        return $collection;
    }
111295
def loadPage(self, number=0):
        """"""
        if self.isClosed or self.isEncrypted:
            raise ValueError("operation illegal for closed / encrypted doc")

        val = _fitz.Document_loadPage(self, number)

        if val:
            val.thisown = True
            val.parent = weakref.proxy(self)
            pageCount = self.pageCount
            n = number
            while n < 0: n += pageCount
            val.number = n
            self._page_refs[id(val)] = val
            val._annot_refs = weakref.WeakValueDictionary()


        return val
184848
private int determineValidPageNumberFrom(int userPage) {
        if (userPage <= 0) {
            return 0;
        }
        if (originalUserPages != null) {
            if (userPage >= originalUserPages.length) {
                return originalUserPages.length - 1;
            }
        } else {
            if (userPage >= documentPageCount) {
                return documentPageCount - 1;
            }
        }
        return userPage;
    }
1181578
def __total_pages(self) -> int:
        
        row_count = self.model.query.count()
        if isinstance(row_count, int):
            return int(row_count / self.limit)
        return None
719028
function (pageIndex, callback, noPageCheck) {

            if (this.$loadingPage) {
                if (callback) {
                    callback();
                }
                return;
            }
            var self = this;

            function cb(err) {
                if (callback) {
                    callback(err);
                }
                self.$loadingPage = false;
            }

            if (this.hasPage(pageIndex)) {
                this.$loadingPage = true;

                var i;
                pageIndex = pageIndex || 0;
                noPageCheck = _.isUndefined(noPageCheck) ? true : noPageCheck;

                if (!this.$.baseList || (!noPageCheck && pageIndex === this.$.page)) {
                    // nothing to do
                    cb();
                    return;
                }

                var list = this.$.list;
                var baseList = this.$.baseList;

                list.clear();

                // add items
                var startIndex = this.$.pageSize * pageIndex;
                if (baseList.$items.length > startIndex) {
                    for (i = 0; i < this.$.pageSize; i++) {
                        list.add(baseList.at(startIndex + i));
                    }
                }


                if (baseList instanceof Collection) {
                    // determinate pages to load based on the page size
                    var collectionPageSize = this.$.baseList.$.pageSize;

                    var collectionStartPage = this._itemIndexToPageIndex(this._pageIndexToItemIndex(pageIndex), collectionPageSize);
                    var collectionEndPage = this._itemIndexToPageIndex(this._pageIndexToItemIndex(pageIndex + 1) - 1, collectionPageSize);

                    var pageIndices = {};
                    for (i = collectionStartPage; i <= collectionEndPage; i++) {
                        pageIndices[i] = i;
                    }


                    flow()
                        .seq("execId", function () {
                            return ++self.$execId;
                        })
                        .parEach(pageIndices, function (pageIndex, cb) {
                            baseList.fetchPage(pageIndex, null, cb);
                        })
                        .exec(function (err, results) {

                            if (!err && results.execId == self.$execId) {
                                var items = [];
                                for (i = collectionStartPage; i <= collectionEndPage; i++) {
                                    items = items.concat(results[i].$items);
                                }

                                self._calculatePageCount();


                                var viewStartIndex = self._pageIndexToItemIndex(pageIndex, self.$.pageSize);
                                viewStartIndex -= collectionStartPage * collectionPageSize;
                                if (viewStartIndex < items.length) {
                                    // remove overlapping at start and end
                                    items = items.slice(viewStartIndex, viewStartIndex + self.$.pageSize);

                                    // and reset list
                                    self.$.list.reset(items);
                                }
                            }
                            self.set('page', pageIndex);
                            cb(err);
                        });

                } else {
                    self._calculatePageCount();
                    self.set('page', pageIndex);
                    cb();
                }
            } else {
                this._calculatePageCount();
                cb();
            }

        }
961637
def return_item_count_on_subpage(self, subpage=1, total_items=1):
        
        up_to_subpage = ((subpage - 1) * self.subpage_items)
        #   Number of items up to the page in question

        if total_items > up_to_subpage:
            #   Remove all the items up to the page in question
            #
            count = total_items - up_to_subpage
        else:
            count = total_items

        if count >= self.subpage_items:
            # The remaining items are greater than the items per page
            # so the answer is a full page
            return self.subpage_items
        else:
            #   There are less items than a full page,
            #
            return count
15552
function ErrorRenderer(err, req, res) {
    PageRenderer.call(this, req, res);
    Object.defineProperties(this, {
        err: {
            value: err || new Error()
        }
    });
    req.attrs.isErrorPage = true;
}
1356497
public ItemList<Item> userComments(int perPage, int page) throws FlickrException {
        ItemList<Item> items = new ItemList<Item>();
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_USER_COMMENTS);

        if (perPage > 0) {
            parameters.put("per_page", "" + perPage);
        }

        if (page > 0) {
            parameters.put("page", "" + page);
        }

        Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }

        Element itemList = response.getPayload();
        NodeList itemElements = itemList.getElementsByTagName("item");
        items.setPage(itemList.getAttribute("page"));
        items.setPages(itemList.getAttribute("pages"));
        items.setPerPage(itemList.getAttribute("perpage"));
        items.setTotal(itemList.getAttribute("total"));

        for (int i = 0; i < itemElements.getLength(); i++) {
            Element itemElement = (Element) itemElements.item(i);
            items.add(createItem(itemElement));
        }

        return items;
    }
1248181
def per(num, max_per_page: nil)
      max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
      @_per = (num || default_per_page).to_i
      if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
        self
      elsif n.zero?
        limit(n)
      elsif max_per_page && (max_per_page < n)
        limit(max_per_page).offset(offset_value / limit_value * max_per_page)
      else
        limit(n).offset(offset_value / limit_value * n)
      end
    end