code: def pagination(page, limit, length):
          
          realpage = page
          page = page or CtsCapitainsLocalResolver.DEFAULT_PAGE
          limit = limit or CtsCapitainsLocalResolver.PER_PAGE[1]
  
          if limit < CtsCapitainsLocalResolver.PER_PAGE[0] or limit > CtsCapitainsLocalResolver.PER_PAGE[2]:
              limit = CtsCapitainsLocalResolver.PER_PAGE[1]
  
          page = (page - 1) * limit
  
          if page > length:
              realpage = int(ceil(length / limit))
              page = limit * (realpage - 1)
              count = length - 1
          elif limit - 1 + page < length:
              count = limit - 1 + page
          else:
              count = length - 1
  
          return page, count + 1, realpage, count - page + 1
docs: Help for pagination
          :param page: Provided Page
          :param limit: Number of item to show
          :param length: Length of the list to paginate
          :return: (Start Index, End Index, Page Number, Item Count)