[kupfer: 9/31] objects: AppLeaf must not destroy self on pickle
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 9/31] objects: AppLeaf must not destroy self on pickle
- Date: Thu, 31 Dec 2009 12:55:12 +0000 (UTC)
commit 2d00d4f4f8ce0029967f20ae395ecf4bee339e4b
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed Dec 30 03:50:31 2009 +0100
objects: AppLeaf must not destroy self on pickle
Make sure an AppLeaf object is not destroyed on pickle
kupfer/objects.py | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 2d573fb..07349fe 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -340,7 +340,7 @@ class SourceLeaf (Leaf):
def get_icon_name(self):
return self.object.get_icon_name()
-class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
+class AppLeaf (Leaf, pretty.OutputMixin):
def __init__(self, item=None, init_path=None, app_id=None):
"""Try constructing an Application for GAppInfo @item,
for file @path or for package name @app_id.
@@ -348,8 +348,8 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
self.init_item = item
self.init_path = init_path
self.init_item_id = app_id and app_id + ".desktop"
- # unpickle_finish will raise InvalidDataError on invalid item
- self.unpickle_finish()
+ # finish will raise InvalidDataError on invalid item
+ self.finish()
Leaf.__init__(self, self.object, self.object.get_name())
self.name_aliases.update(self._get_aliases())
@@ -361,12 +361,18 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
if package_name and package_name not in lowername:
yield package_name
- def pickle_prepare(self):
+ def __getstate__(self):
self.init_item_id = self.object and self.object.get_id()
- self.object = None
- self.init_item = None
+ state = dict(vars(self))
+ state["object"] = None
+ state["init_item"] = None
+ return state
- def unpickle_finish(self):
+ def __setstate__(self, state):
+ vars(self).update(state)
+ self.finish()
+
+ def finish(self):
"""Try to set self.object from init's parameters"""
item = None
if self.init_item:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]