'Opens a chunk for writing, creating a new one if it doesn\'t exist yet.'

def _GetChunkForWriting(self, chunk):

    try:
        chunk = self.chunk_cache.Get(chunk)
        chunk.dirty = True
        return chunk
    except KeyError:
        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
