'Returns ``per_page`` items from page ``page``.
If no items are found and ``page`` is greater than 1, or if page is
less than 1, it aborts with 404.
This behavior can be disabled by passing ``error_out=False``.
If ``page`` or ``per_page`` are ``None``, they will be retrieved from
the request query.
If the values are not ints and ``error_out`` is ``True``, it aborts
with 404.
If there is no request or they aren\'t in the query, they default to 1
and 20 respectively.
Returns a :class:`Pagination` object.'

def paginate(self, page=None, per_page=None, error_out=True):

    if request:
        if (page is None):
            try:
                page = int(request.args.get('page', 1))
            except (TypeError, ValueError):
                if error_out:
                    abort(404)
                page = 1
        if (per_page is None):
            try:
                per_page = int(request.args.get('per_page', 20))
            except (TypeError, ValueError):
                if error_out:
                    abort(404)
                per_page = 20
    else:
        if (page is None):
            page = 1
        if (per_page is None):
            per_page = 20
    if (error_out and (page < 1)):
        abort(404)
    items = self.limit(per_page).offset(((page - 1) * per_page)).all()
    if ((not items) and (page != 1) and error_out):
        abort(404)
    if ((page == 1) and (len(items) < per_page)):
        total = len(items)
    else:
        total = self.order_by(None).count()
    return Pagination(self, page, per_page, total, items)
