diff options
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py index d9c68b1..8593e00 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -95,6 +95,19 @@ 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() + class TutoriusProperty(object): """ The base class for all actions' properties. The interface is the following : |