[kupfer] puid: Check "class version number" in SerializedObject
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] puid: Check "class version number" in SerializedObject
- Date: Sat, 9 Jan 2010 20:22:25 +0000 (UTC)
commit a281daaacdc77b276978386e3d1904ea8410f05d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sat Jan 9 15:32:01 2010 +0100
puid: Check "class version number" in SerializedObject
kupfer/puid.py | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/puid.py b/kupfer/puid.py
index 897d746..a6b32b8 100644
--- a/kupfer/puid.py
+++ b/kupfer/puid.py
@@ -17,12 +17,18 @@ from kupfer import pretty
SERIALIZABLE_ATTRIBUTE = "serilizable"
class SerializedObject (object):
+ # treat the serilizable 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)
def __eq__(self, other):
- return isinstance(other, type(self)) and self.data == other.data
+ return (isinstance(other, type(self)) and self.data == other.data and
+ self.version == other.version)
def reconstruct(self):
- return pickle.loads(self.data)
+ obj = pickle.loads(self.data)
+ if self.version != getattr(obj, SERIALIZABLE_ATTRIBUTE):
+ raise ValueError("Version mismatch for reconstructed %s" % obj)
+ return obj
def get_unique_id(obj):
if obj is None:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]