  Cursor = namedtuple('Cursor', ['offset', 'reverse', 'position'])
  
  
  def decode_cursor(encoded):
      tokens = urlparse.parse_qs(b64decode(encoded))
      try:
          offset = int(tokens['offset'][0])
          reverse = bool(int(tokens['reverse'][0]))
          position = tokens['position'][0]
      except (TypeError, ValueError):
 
</s> remove         last_item = self.page[-1]
        position = self.get_position_from_instance(last_item, self.ordering)
        cursor = Cursor(offset=0, reverse=False, position=position)
 </s> add         compare = self.get_position_from_instance(self.next_item, self.ordering)
        offset = 0
        for item in reversed(self.page):
            position = self.get_position_from_instance(item, self.ordering)
            if position != compare:
                # The item in this position and the item following it
                # have different positions. We can use this position as
                # our marker.
                break

            # The item in this postion has the same position as the item
            # following it, we can't use it as a marker position, so increment
            # the offset and keep seeking to the previous item.
            compare = position
            offset += 1

        else:
            if self.cursor is None:
                # There were no unique positions in the page, and we were
                # on the first page, ie. there was no existing cursor.
                # Our cursor will have an offset equal to the page size,
                # but no position to filter against yet.
                offset = self.page_size
                position = ''
            else:
                # There were no unique positions in the page.
                # Use the position from the existing cursor and increment
                # it's offset by the page size.
                offset = self.cursor.offset + self.page_size
                position = self.cursor.position

        cursor = Cursor(offset=offset, reverse=False, position=position) </s> remove     # reverse
    # limit
 </s> add     # TODO: reverse cursors </s> remove 
    # def decode_cursor(self, encoded, ordering):
    #     items = urlparse.parse_qs(b64decode(encoded))
    #     return items.get(ordering)[0]

    # def encode_cursor(self, cursor, ordering):
    #     items = [(ordering, cursor)]
    #     return b64encode(urlparse.urlencode(items, doseq=True))
 </s> add  </s> remove         results = list(queryset[:self.page_size + 1])
 </s> add         # The offset is used in order to deal with cases where we have
        # items with an identical position. This allows the cursors
        # to gracefully deal with non-unique fields as the ordering.
        offset = 0 if (self.cursor is None) else self.cursor.offset

        # We fetch an extra item in order to determine if there is a next page.
        results = list(queryset[offset:offset + self.page_size + 1])
    tokens = urlparse.parse_qs(b64decode(encoded), keep_blank_values=True)
  Cursor = namedtuple('Cursor', ['offset', 'reverse', 'position'])
  
  
  def decode_cursor(encoded):
    tokens = urlparse.parse_qs(b64decode(encoded), keep_blank_values=True)
      try:
          offset = int(tokens['offset'][0])
          reverse = bool(int(tokens['reverse'][0]))
          position = tokens['position'][0]
      except (TypeError, ValueError):
keep keep keep keep replace keep keep keep keep keep
 Add offset support for cursor pagination 
rest_framework/pagination.py