[kupfer] puid: Make sure subclasses can be marked non-serializable



commit f0fad9762deda60fc6066193c68d48e2f5c36fcd
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 21 18:05:23 2011 +0100

    puid: Make sure subclasses can be marked non-serializable
    
    Consider serializable = None as a clear mark the object should not be
    serialized. This allows subclasses of fileleaf to not be serialized.

 kupfer/puid.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/puid.py b/kupfer/puid.py
index a206e53..48f1f7b 100644
--- a/kupfer/puid.py
+++ b/kupfer/puid.py
@@ -33,8 +33,8 @@ SERIALIZABLE_ATTRIBUTE = "serializable"
 class SerializedObject (object):
 	# treat the serializable attribute as a version number, defined on the class
 	def __init__(self, obj):
-		self.data = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
 		self.version = getattr(obj, SERIALIZABLE_ATTRIBUTE)
+		self.data = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
 	def __eq__(self, other):
 		return (isinstance(other, type(self)) and self.data == other.data and
 		        self.version == other.version)
@@ -49,7 +49,7 @@ def get_unique_id(obj):
 		return None
 	if hasattr(obj, "qf_id"):
 		return str(qfurl.qfurl(obj))
-	if hasattr(obj, SERIALIZABLE_ATTRIBUTE):
+	if getattr(obj, SERIALIZABLE_ATTRIBUTE, None) is not None:
 		try:
 			return SerializedObject(obj)
 		except pickle.PicklingError, exc:



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