diff options
author | Vincent Vinet <vince.vinet@gmail.com> | 2009-10-15 14:23:57 (GMT) |
---|---|---|
committer | Vincent Vinet <vince.vinet@gmail.com> | 2009-10-15 14:23:57 (GMT) |
commit | f14bcb9b6c79f7f071e32a7ef9bba5ce440096bd (patch) | |
tree | 2f4fd1920e484bfdb567eabe83701cd7306d372d /tutorius/properties.py | |
parent | b0274f9a824d8ef82cbe66398d5afaa6ca75d9dc (diff) |
Big commit! Everything to make Tutorial execution work through dbus.
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 21 |
1 files changed, 21 insertions, 0 deletions
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 : |