Package kiwi :: Module model :: Class PickledModel
[frames | no frames]

Class PickledModel

Model --+
        |
       PickledModel


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 Summary
  save(self, filename)
Saves the instance to a pickle filename.
  set_filename(self, filename)
Sets the name of the file which will be used to pickle the model
  unpickle(cls, filename)
Loads an instance from a pickle file; if it fails for some reason, create a new instance. (Class method)
    Inherited from Model
  block_proxy(self, proxy)
Temporarily block a proxy from receiving any notification.
  disable_autonotify(self)
disable automatic notification to proxies based on __setattr__.
  ensure_init(self)
Sets up the variables so the Model's getattr hook and proxy notification work properly.
  flush_proxies(self)
Removes all proxies attached to Model
  notify_proxies(self, attr)
Notify proxies that an attribute value has changed.
  register_proxy_for_attribute(self, attr, proxy)
Attach a proxy to an attribute.
  unblock_proxy(self, proxy)
Re-enable notifications to a proxy
  unregister_proxy(self, proxy)
Deattach a proxy completely from the model
  unregister_proxy_for_attribute(self, attr, proxy)
Detach a proxy from an attribute.

Instance Method Details

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

set_filename(self, filename)

Sets the name of the file which will be used to pickle the model

Class Method Details

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.

Generated by Epydoc 2.1 on Mon Jan 29 16:46:04 2007 http://epydoc.sf.net