'Return the next page of results from a query.
Note: If using backwards paging, then the next page of
results will be the items before the current page
of items.'

def next(self):

    if self._stop:
        raise StopIteration
    self.query[self.interface]['rsm']['before'] = self.reverse
    self.query['id'] = self.query.stream.new_id()
    self.query[self.interface]['rsm']['max'] = str(self.amount)
    if (self.start and self.reverse):
        self.query[self.interface]['rsm']['before'] = self.start
    elif self.start:
        self.query[self.interface]['rsm']['after'] = self.start
    try:
        r = self.query.send(block=True)
        if ((not r[self.interface]['rsm']['first']) and (not r[self.interface]['rsm']['last'])):
            raise StopIteration
        if (r[self.interface]['rsm']['count'] and r[self.interface]['rsm']['first_index']):
            count = int(r[self.interface]['rsm']['count'])
            first = int(r[self.interface]['rsm']['first_index'])
            num_items = len(r[self.interface][self.results])
            if ((first + num_items) == count):
                self._stop = True
        if self.reverse:
            self.start = r[self.interface]['rsm']['first']
        else:
            self.start = r[self.interface]['rsm']['last']
        return r
    except XMPPError:
        raise StopIteration
