diff options
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 : |