

def iter_keys(self, filename):
    f = compat.file_open(filename, 'rb')
    header = f.read(8)
    self._verify_header(header)
    contents = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    remap_size = (mmap.ALLOCATIONGRANULARITY * _MAPPED_LOAD_PAGES)
    max_index = os.path.getsize(filename)
    file_size_bytes = max_index
    num_resizes = 0
    current = 8
    try:
        while (current != max_index):
            try:
                (key_size, val_size) = struct.unpack('!ii', contents[current:(current + 8)])
            except struct.error:
                raise DBMLoadError()
            key = contents[(current + 8):((current + 8) + key_size)]
            if (len(key) != key_size):
                raise DBMLoadError()
            offset = ((((remap_size * num_resizes) + current) + 8) + key_size)
            if ((offset + val_size) > file_size_bytes):
                return
            (yield (key, offset, val_size))
            if (val_size == _DELETED):
                val_size = 0
            current = ((((current + 8) + key_size) + val_size) + 4)
            if (current >= remap_size):
                contents.close()
                num_resizes += 1
                offset = (num_resizes * remap_size)
                contents = mmap.mmap(f.fileno(), (file_size_bytes - offset), access=mmap.ACCESS_READ, offset=offset)
                current -= remap_size
                max_index -= remap_size
    finally:
        contents.close()
        f.close()

dataset/ETHPy150Open jamesls/semidbm/semidbm/loaders/mmapload.py MMapLoader.iter_keys/original