[kupfer] objects: Raise InvalidDataError on unpickling invalid AppLeaf



commit f6e0f02bf18bb9eb2ca87bc3ecb928caa8fb8c0d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Aug 18 14:37:11 2009 +0200

    objects: Raise InvalidDataError on unpickling invalid AppLeaf
    
    This is a patch for LP bug #414699
    
    1. Patch unpickle_finish so that AppLeaves cannot be created with
    self.object = None, neither from __init__ nor from unpickle (the
    unpickle case was ignored before)
    2. If self.object is unset on pickle (which it should no longer),
    record None

 kupfer/objects.py |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index c83596a..f42386d 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -389,10 +389,8 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
 		self.init_item = item
 		self.init_path = path
 		self.init_item_id = app_id and app_id + ".desktop"
-		self.path = path
+		# unpickle_finish will raise InvalidDataError on invalid item
 		self.unpickle_finish()
-		if not self.object:
-			raise InvalidDataError
 		Leaf.__init__(self, self.object, self.object.get_name())
 		self.name_aliases = self._get_aliases()
 
@@ -411,28 +409,29 @@ class AppLeaf (Leaf, PicklingHelperMixin, pretty.OutputMixin):
 		return name_aliases
 
 	def pickle_prepare(self):
-		self.init_item_id = self.object.get_id()
+		self.init_item_id = self.object and self.object.get_id()
 		self.object = None
 		self.init_item = None
 
 	def unpickle_finish(self):
 		"""Try to set self.object from init's parameters"""
-		if self.init_item:
-			self.object = self.init_item
-			return
-		# Construct an AppInfo item from either path or item_id
-		from gio.unix import DesktopAppInfo, desktop_app_info_new_from_filename
 		item = None
-		if self.init_path:
-			item = desktop_app_info_new_from_filename(self.init_path)
-		elif self.init_item_id:
-			try:
-				item = DesktopAppInfo(self.init_item_id)
-			except RuntimeError:
-				self.output_debug(self, "Application", self.init_item_id,
-						"not found")
-				item = None
+		if self.init_item:
+			item = self.init_item
+		else:
+			# Construct an AppInfo item from either path or item_id
+			from gio.unix import DesktopAppInfo, desktop_app_info_new_from_filename
+			if self.init_path:
+				item = desktop_app_info_new_from_filename(self.init_path)
+			elif self.init_item_id:
+				try:
+					item = DesktopAppInfo(self.init_item_id)
+				except RuntimeError:
+					self.output_debug(self, "Application", self.init_item_id,
+							"not found")
 		self.object = item
+		if not self.object:
+			raise InvalidDataError
 
 	def repr_key(self):
 		return self.get_id() or self



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]