diff options
author | Simon Poirier <simpoir@gmail.com> | 2009-11-24 00:30:17 (GMT) |
---|---|---|
committer | Simon Poirier <simpoir@gmail.com> | 2009-11-24 00:30:17 (GMT) |
commit | 825143f4e633c4025ba39307760a3924769f2f02 (patch) | |
tree | 725df1f57ab7ac4ef3562f2675a8959bc28b990e /tutorius/properties.py | |
parent | 3c66e5880d84f660979644d2dec51070546f59af (diff) |
creator+probes, not entirely working yet
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py index aab6a0c..01cd2c0 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -19,6 +19,7 @@ TutoriusProperties have the same behaviour as python properties (assuming you also use the TPropContainer), with the added benefit of having builtin dialog prompts and constraint validation. """ +import uuid from copy import copy, deepcopy from .constraints import Constraint, \ @@ -58,6 +59,8 @@ class TPropContainer(object): self._props[attr_name] = propinstance.validate( copy(propinstance.default)) + self.__id = hash(uuid.uuid4()) + def __getattribute__(self, name): """ Process the 'fake' read of properties in the appropriate instance @@ -111,21 +114,23 @@ class TPropContainer(object): # Providing the hash methods necessary to use TPropContainers # in a dictionary, according to their properties def __hash__(self): - #Return a hash of properties (key, value) sorted by key - #We need to transform the list of property key, value lists into - # a tuple of key, value tuples - return hash(tuple(map(tuple,sorted(self._props.items(), cmp=lambda x, y: cmp(x[0], y[0]))))) + # many places we use containers as keys to store additional data. + # Since containers are mutable, there is a need for a hash function + # where the result is constant, so we can still lookup old instances. + return self.__id def __eq__(self, e2): - return isinstance(e2, type(self)) and self._props == e2._props + return self.__id == e2.__id or \ + (isinstance(e2, type(self)) and self._props == e2._props) # Adding methods for pickling and unpickling an object with # properties def __getstate__(self): - return self._props.copy() + return dict(id=self.__id, props=self._props.copy()) def __setstate__(self, dict): - self._props.update(dict) + self.__id = dict['id'] + self._props.update(dict['props']) class TutoriusProperty(object): """ |