From cf40c1951f4f0f26090226fb4969ca147341a031 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 02 Oct 2009 22:24:56 +0000 Subject: LP 439980 : Refactored the XMLSerializer to support complex components; Corrected specs for the addons properties and constructor parameters names; Moved all existing actions and events to components (except a few left in code for testing purposes) --- (limited to 'tutorius/properties.py') diff --git a/tutorius/properties.py b/tutorius/properties.py index abf76e5..6d30a8d 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -95,6 +95,39 @@ class TPropContainer(object): """ return object.__getattribute__(self, "_props").keys() + def is_identical(self, otherContainer): + for prop in self._props.keys(): + found = False + for otherProp in otherContainer._props.keys(): + 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_type == "addonlist": + for inner_cont in self._props[prop]: + inner_found = False + for other_inner in otherContainer._props[prop]: + if inner_cont.is_identical(other_inner): + inner_found = True + break + if inner_found == False: + return False + found = True + break + elif this_type == "addon": + if not self._props[prop].is_identical(otherContainer._props[prop]): + return False + found = True + break + else: + if self._props[prop]== otherContainer._props[prop]: + found = True + break + if found == False: + return False + return True + class TutoriusProperty(object): """ The base class for all actions' properties. The interface is the following : @@ -317,8 +350,15 @@ class TAddonListProperty(TutoriusProperty): See TAddonProperty """ def __init__(self): - super(TAddonProperty, self).__init__() + TutoriusProperty.__init__(self) self.type = "addonlist" self.default = [] + def validate(self, value): + if isinstance(value, list): + for component in value: + if not (isinstance(component, TPropContainer)): + raise ValueError("Expected a list of TPropContainer instances inside TAddonListProperty value, got a %s" % (str(type(component)))) + return value + raise ValueError("Value proposed to TAddonListProperty is not a list") -- cgit v0.9.1