def append(self, obj): """Override the standard list append method. Args: obj: The object to append. Returns: Whatever list.append returns. Raises: exception.InvalidValue: The object is of the wrong type. exception.DuplicateObject: An object with the same name or number that already exists in the list. """ if not isinstance(obj, schema_object_class): raise exception.InvalidValue( 'Expected %s instance, got %s' % (str(schema_object_class), str(obj))) if self.by_name(obj.base_name): raise exception.DuplicateObject( 'Duplicate %s object by_name on %s: %s' % (str(schema_object_class), self.parent.full_name, obj.base_name)) if self.by_number(obj.number): raise exception.DuplicateObject( 'Duplicate %s object by_number on %s: %s' % (str(schema_object_class), self.parent.full_name, obj.base_name)) self.__validate__(obj) if not isinstance(self.parent, File): obj.parent_list = self obj.parent = self.parent return list.append(self, obj)
def __validate__(self, trait): if self.parent.typespace_list.by_name(trait.base_name): raise exception.DuplicateObject( 'Duplicate Typespace/Trait object by_name on %s: %s' % (self.parent.full_name, trait.base_name))