예제 #1
0
 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)
예제 #2
0
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