From f14bcb9b6c79f7f071e32a7ef9bba5ce440096bd Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Thu, 15 Oct 2009 14:23:57 +0000 Subject: Big commit! Everything to make Tutorial execution work through dbus. --- (limited to 'tutorius/properties.py') diff --git a/tutorius/properties.py b/tutorius/properties.py index abf76e5..b1c6361 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -95,6 +95,27 @@ class TPropContainer(object): """ return object.__getattribute__(self, "_props").keys() + # Providing the hash methods necessary to use TPropContainers + # in a dictionary, according to their properties + def __hash__(self): + try: + #Return a hash of properties (key, value) sorted by key + return hash(tuple(map(tuple,sorted(self._props.items(), cmp=lambda x, y: cmp(x[0], y[0]))))) + except TypeError: + #FIXME For list properties (and maybe others), hashing will fail, fallback to id + return id(self) + + def __eq__(self, e2): + return self._props.items() == e2._props.items() + + # Adding methods for pickling and unpickling an object with + # properties + def __getstate__(self): + return self._props.copy() + + def __setstate__(self, dict): + self._props.update(dict) + class TutoriusProperty(object): """ The base class for all actions' properties. The interface is the following : -- cgit v0.9.1