def _GetChunkForWriting(self, chunk):
    """Opens a chunk for writing, creating a new one if it doesn't exist yet."""
    try:
      chunk = self.chunk_cache.Get(chunk)
      chunk.dirty = True
      return chunk
    except __HOLE__:
      pass

    try:
      chunk = self._ReadChunk(chunk)
      chunk.dirty = True
      return chunk
    except KeyError:
      pass

    fd = StringIO.StringIO()
    fd.chunk = chunk
    fd.dirty = True
    self.chunk_cache.Put(chunk, fd)
    return fd
dataset/ETHPy150Open google/grr/grr/lib/aff4.py/AFF4ImageBase._GetChunkForWriting