def __init__(self, db, prefix, reverse): self.prefix = prefix if reverse: self.iterator = reversed(db.iteritems()) nxt_prefix = util.increment_byte_string(prefix) if nxt_prefix: self.iterator.seek(nxt_prefix) try: next(self.iterator) except StopIteration: self.iterator.seek(nxt_prefix) else: self.iterator.seek_to_last() else: self.iterator = db.iteritems() self.iterator.seek(prefix)
def test_increment_byte_string(): assert util.increment_byte_string(b'1') == b'2' assert util.increment_byte_string(b'\x01\x01') == b'\x01\x02' assert util.increment_byte_string(b'\xff\xff') is None