From 912528253fcf1fc43c1a2d02ffe6e540fe60d8e7 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Mon, 19 Oct 2009 20:15:41 +0000 Subject: Merge the TProbe Integration and fix merging induced bugs --- (limited to 'tutorius/properties.py') diff --git a/tutorius/properties.py b/tutorius/properties.py index 4c34511..78e3c2b 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -95,89 +95,25 @@ class TPropContainer(object): """ return object.__getattribute__(self, "_props").keys() - def __eq__(self, otherContainer): - """ - Compare this property container to the other one and returns True only if - the every property of the first one can be found in the other container, with - the same name and the same value. - - @param otherContainer The other container that we wish to test for equality. - @returns True if every property in the first container can be found with the same - value and the same name in the second container. - """ - # Make sure both have the same number of properties - if len(self._props) != len(otherContainer._props): - return False + # 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]))))) - if not(type(self) == type(otherContainer)): - return False + def __eq__(self, e2): + return self._props == e2._props - # For every property in this container - for prop in self._props.keys(): - found = False - # Try to match it with another property present in the other container - for otherProp in otherContainer._props.keys(): - # If we were able to match the name, then we look up the value - if prop == otherProp: - this_type = getattr(type(self), prop).type - other_type = getattr(type(otherContainer), prop).type - if this_type != other_type: - return False - - # If this is an addon list, then we need to make sure that - # every element of the list is also present in the other list - if this_type == "addonlist": - if not self._are_lists_identical(self._props[prop], otherContainer._props[prop]): - return False - found = True - break + # 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) - # If this is just an embedded / decorated container, then we want to - # make sure the sub component are identical. - elif this_type == "addon": - if not (self._props[prop] == otherContainer._props[prop]): - return False - found = True - break - else: - if self._props[prop] == otherContainer._props[prop]: - found = True - break - # If we arrive here, then we couldn't find any property in the second - # container that matched the current one. We know that the two containers are - # not equal. - if found == False: - return False - return True - - def _are_lists_identical(self, myList, otherList): - """ - Compares two lists of property containers to see if they are identical ( - they have the same properties - - @param myList The first list of properties containers - @param otherList The second list of properties containers - @return True if all of the properties inside the list are identical. False otherwise. - """ - # For each property in the first list, - for container in myList: - found = False - # Attempt to match it with every property in the other list - for other_container in otherList: - # If the containers are identical, - if container == other_container: - # We found a matching container. We don't need to search in the - # second list anymore, so we break - found = True - break - # In the case the property was not found inside the second list - if found == False: - # We know right away that the two lists are not identical - return False - # If we were able to match each property in the first list, then we - # can say the lists are equal. - return True - class TutoriusProperty(object): """ The base class for all actions' properties. The interface is the following : @@ -277,8 +213,20 @@ class TArrayProperty(TutoriusProperty): self.type = "array" self.max_size_limit = MaxSizeConstraint(max_size_limit) self.min_size_limit = MinSizeConstraint(min_size_limit) - self.default = self.validate(value) + self.default = tuple(self.validate(value)) + #Make this thing hashable + def __setstate__(self, state): + self.max_size_limit = MaxSizeConstraint(state["max_size_limit"]) + self.min_size_limit = MinSizeConstraint(state["min_size_limit"]) + self.value = state["value"] + + def __getstate__(self): + return dict( + max_size_limit=self.max_size_limit.limit, + min_size_limit=self.min_size_limit.limit, + value=self.value, + ) class TColorProperty(TutoriusProperty): """ Represents a RGB color with 3 8-bit integer values. @@ -357,8 +305,10 @@ class TUAMProperty(TutoriusProperty): """ Represents a widget of the interface by storing its UAM. """ - # TODO : Pending UAM check-in (LP 355199) - pass + def __init__(self, value=None): + TutoriusProperty.__init__(self) + + self.type = "uam" class TAddonProperty(TutoriusProperty): """ -- cgit v0.9.1