# Class k.m.PickledModel(Model):

Part of kiwi.model View In Hierarchy

PickledModel is a model that is able to save itself into a pickle using save(). This has all the limitations of a pickle: its instance variables must be picklable, or pickle.dump() will raise exceptions. You can prefix variables with an underscore to make them non-persistent (and you can restore them accordingly by overriding __setstate__, but don't forget to call PickledModel.__setstate__)

Method | __init__ | Undocumented
Method | __getstate__ | Gets the state from the instance to be pickled
Method | __setstate__ | Sets the state to the instance when being unpickled
Method | save | Saves the instance to a pickle filename. If no filename argument is
Method | set_filename | Sets the name of the file which will be used to pickle the
Class Method | unpickle | Loads an instance from a pickle file; if it fails for some reason,

Inherited from Model:

Method | ensure_init | Sets up the variables so the Model's getattr hook and proxy
Method | disable_autonotify | disable automatic notification to proxies based on __setattr__.
Method | notify_proxies | Notify proxies that an attribute value has changed.
Method | register_proxy_for_attribute | Attach a proxy to an attribute. The proxy will be notified of
Method | unregister_proxy_for_attribute | Detach a proxy from an attribute.
Method | unregister_proxy | Deattach a proxy completely from the model
Method | flush_proxies | Removes all proxies attached to Model
Method | block_proxy | Temporarily block a proxy from receiving any notification. See
Method | unblock_proxy | Re-enable notifications to a proxy
Method | __setattr__ | A special setattr hook that notifies the registered proxies that

def __init__(self):
overrides kiwi.model.Model.__init__
Undocumented
def __getstate__(self):
Gets the state from the instance to be pickled

def __setstate__(self, dict):
Sets the state to the instance when being unpickled

def save(self, filename=None):
Saves the instance to a pickle filename. If no filename argument is provided, will try to use the internal _filename attribute that is set using set_filename()

Parameters | filename | optional filename to pass in

def set_filename(self, filename):
Sets the name of the file which will be used to pickle the model

@classmethod
def unpickle(cls, filename=None):
Loads an instance from a pickle file; if it fails for some reason, create a new instance.

- filename: the file from which the pickle should be loaded. If file is not provided, the name of the class suffixed by ".pickle" is used (i.e. "FooClass.pickle" for the class FooClass).

If the pickle file is damaged, it will be saved with the extension ".err"; if a file with that name also exists, it will use ".err.1" and so on. This is to avoid the damaged file being clobbered by an instance calling save() unsuspectingly.