This is a response from aspect_mkn8rd 'given Gerrat's comments, but it is too long for a true comment.
You will need 2 special classes of containers emulating a list and a dictionary. In both cases, you add a pointer to a top-level object and override the following methods:
__setitem__(self, key, value)__delitem__(self, key)__reversed__(self)
All these methods are called in modification and must have a top-level object for writing to disk.
In addition, __setitem__(self, key, value) should look to see if the value is a list and transfers it to a special list object or, if it is a dictionary, inserts it into a special dictionnary object. In both cases, the method should set the top-level object in a new container. If none of them and the object defines __setitem__ , it should raise an exception message that does not support the object. Of course, you must then modify the method to take this new class into account.
Of course, there is a lot of code for writing and testing, but it should work - left to the reader as an exercise :-)
source share