def __init__(self,name,value,owner , copy = True): super(MMAttribute,self).__init__(self,name,value,owner,copy) self.name=str(name) self.valueobj=CreateAttributeValue(value , copy) self.owner=owner self.oldvalue = None self.logger = logging.getLogger("MysteryMachine.schema.MMAttribute")
def set_value(self,val, copy = True , writeback = True ): #Quit early in case of No-Op if val is self.valueobj: return try: self.valueobj.assign(val) except Exception, e: if str(e): self.logger.warn(e) self.valueobj = CreateAttributeValue(val,copy)
class MMAttribute (MMAttributeContainer): """ This class represents an attribute of an MMObject in a MMSystem, such attributes are normally single values, or paragraphs of text, but can also be relationships with other MMObjects Again this is base class to be overr :version: :author: """ """ ATTRIBUTES raw_val (private) type (private) object (private) isLoaded (private) """ def __init__(self,name,value,owner , copy = True): super(MMAttribute,self).__init__(self,name,value,owner,copy) self.name=str(name) self.valueobj=CreateAttributeValue(value , copy) self.owner=owner self.oldvalue = None self.logger = logging.getLogger("MysteryMachine.schema.MMAttribute") #self.logger.setLevel(logging.DEBUG) def get_owner(self): return self.owner @Reader def __str__(self): """ @return string : """ return self.get_raw_rst() def __repr__(self): """ @return string : @author """ return repr(self.owner)+":"+self.name @Reader def GetFullExpansion(self): """ This function returns a Fully expanded string represenation of the Attribute. @return string : """ return self.get_parser().GetString(self.get_raw_rst(),repr(self)) def _compose(self): """ Do the second initialisation phase for the associated value object. Value object support a two phase initialisation, for those values which have a referential integrity requirement which is dependent on their location within the schema. _compose is called on the value object with the attribute object as an argument - in the same manner that exports are called. Calls _compose(self) on the value object. """ if hasattr(self.valueobj,"_compose"): self.valueobj._compose(self) #Special case to override the definiton in Base. def _validate(self): """ @return bool : @author """ self.valueobj._validate(self) @Reader def get_value(self): return self.valueobj @Reader def get_type(self,): """return the type of value stored in the attribute""" if valueobj: return valueobj.get_type() else: return None @Writer def set_value(self,val, copy = True , writeback = True ): #Quit early in case of No-Op if val is self.valueobj: return try: self.valueobj.assign(val) except Exception, e: if str(e): self.logger.warn(e) self.valueobj = CreateAttributeValue(val,copy) self._invalidate_cache() self._compose()