@inlineCallbacks<EOL><INDENT>def write(self):<DEDENT>
self._check()<EOL>cache = self._cache<EOL>pristine_cache = self._pristine_cache<EOL>self._pristine_cache = cache.copy()<EOL>changes = []<EOL>def apply_changes(content, stat):<EOL><INDENT>"""<STR_LIT>"""<EOL>del changes[:]<EOL>current = yaml.load(content) if content else {}<EOL>missing = object()<EOL>for key in set(pristine_cache).union(cache):<EOL><INDENT>old_value = pristine_cache.get(key, missing)<EOL>new_value = cache.get(key, missing)<EOL>if old_value != new_value:<EOL><INDENT>if new_value != missing:<EOL><INDENT>current[key] = new_value<EOL>if old_value != missing:<EOL><INDENT>changes.append(<EOL>ModifiedItem(key, old_value, new_value))<EOL><DEDENT>else:<EOL><INDENT>changes.append(AddedItem(key, new_value))<EOL><DEDENT><DEDENT>elif key in current:<EOL><INDENT>del current[key]<EOL>changes.append(DeletedItem(key, old_value))<EOL><DEDENT><DEDENT><DEDENT>return yaml.safe_dump(current)<EOL><DEDENT>yield retry_change(self._client, self._path, apply_changes)<EOL>returnValue(changes)<EOL>
Write object state to Zookeeper.

        This will write the current state of the object to Zookeeper,
        taking the final merged state as the new one, and resetting
        any write buffers.