def default_init( self, _GroupedParentVariable=None, _GroupedInt=-1, _GroupedKeyStr="", _GroupedDeriveParentersList=None, _GroupedPathStrsList=None, _GroupedPathStr="/", **_KwargVariablesDict ): #Call the parent __init__ method BaseClass.__init__(self,**_KwargVariablesDict) #set self.HdformatingFileKeyStr=SYS.InflectEngine.plural( Doer.getDoStrWithDoerStr( self.__class__.NameStr ) )+'.hdf5'
def SwitchedFunction(*_LiargVariablesList, **_KwargVariablesDict): # debug """ self.debug('We are in the SwitchedFunction !') """ # Alias InstanceVariable = _LiargVariablesList[0] # set at the class level SwitchedClass = InstanceVariable.__class__ # debug """ self.debug( [ ('self.',self,['SwitchedClassBoolKeyStr','SwitchedInstanceBoolKeyStr']), Representer.represent(InstanceVariable,**{'RepresentingAlineaIsBool':False}) ] ) """ # set the SwitchedBool if it was not already if hasattr(InstanceVariable, self.SwitchedInstanceBoolKeyStr) == False: # debug """ self.debug('The InstanceVariable has not the SwitchedBoolSuffixStr..so set it to False') """ # debug """ self.debug('SwitchedClass is '+str(SwitchedClass)) """ # set setattr(SwitchedClass, self.SwitchedInstanceBoolKeyStr, False) # set at the instance level InstanceVariable.__setattr__(self.SwitchedInstanceBoolKeyStr, False) # set also at the scale of elif getattr(InstanceVariable, self.SwitchedInstanceBoolKeyStr): # debug """ self.debug('The Instance has already done this method') """ # Return return InstanceVariable # debug """ self.debug(('self.',self,['SwitchedBoolSuffixStr'])) """ # At the level of the class set the new triggering set function if hasattr(SwitchedClass, self.SwitchedClassBoolKeyStr) == False: # Definition the SwitchedDoerStr SwitchedDoerStr = Doer.getDoerStrWithDoStr(SwitchedDoStr) # debug """ print('SwitchedDoerStr is ',SwitchedDoerStr) print(InstanceVariable.__class__.__mro__) print('') """ # Find the corresponding base class to reinit SwitchedDoerClass = SYS._filter( lambda __Class: SwitchedDoerStr == SYS.getNameStrWithClassStr(__Class.__name__), SwitchedClass.__mro__, )[0] # Definition the triggering function that will call the init one def triggerBefore(*_TriggeringVariablesList, **_TriggeringVariablesDict): # Alias TriggeredInstanceVariable = _TriggeringVariablesList[0] # debug """ self.debug('Reinit with '+Representer.represent( TriggeredInstanceVariable.SettingKeyVariable,**{'RepresentingAlineaIsBool':False} ) ) """ # Update with the DoneAttributeVariablesOrderedDict map( lambda __ItemTuple: TriggeredInstanceVariable.__setattr__(__ItemTuple[0], __ItemTuple[1]), SwitchedDoerClass.DoneAttributeVariablesOrderedDict.items(), ) # set the name TriggeredBeforeMethodStr = "triggerBeforeWith" + self.SwitchedBoolSuffixStr triggerBefore.__name__ = TriggeredBeforeMethodStr # debug """ self.debug( [ ("SwitchedClass is "+str(SwitchedClass)), ("TriggeredBeforeMethodStr is "+TriggeredBeforeMethodStr), ("Get Method is "+str(getattr( SwitchedClass, TriggeredBeforeMethodStr) ) if hasattr(SwitchedClass, TriggeredBeforeMethodStr) else "None") ] ) """ # Link the triggerBefore function setattr( SwitchedClass, TriggeredBeforeMethodStr, Triggerer.TriggererClass( **{ "TriggeringConditionVariable": [ ("SettingKeyVariable", (operator.eq, self.SwitchedInstanceBoolKeyStr)), (self.SwitchedInstanceBoolKeyStr, (operator.eq, True)), ("SettingValueVariable", (operator.eq, False)), ], "TriggeringHookStr": "Before", } )(triggerBefore), ) # Call with a default instance this trigger function to be installed getattr(SwitchedClass(), TriggeredBeforeMethodStr)() # Say that it is ok setattr(SwitchedClass, self.SwitchedClassBoolKeyStr, True) # debug """ self.debug( [ #('InstanceVariable is '+SYS._str(InstanceVariable)), ('_LiargVariablesList is '+str(_LiargVariablesList)), ('_KwargVariablesDict is '+str(_KwargVariablesDict)) ] ) """ # Call the SwitchingMethodFunction self.SwitchingMethodFunction(*_LiargVariablesList, **_KwargVariablesDict) # debug """ self.debug(('self.',self,['SwitchedBoolSuffixStr'])) """ # set True for the Bool after the call InstanceVariable.__setattr__(self.SwitchedInstanceBoolKeyStr, True) # debug """ self.debug(('InstanceVariable.',InstanceVariable,[self.SwitchedBoolSuffixStr])) """ # Return self for the wrapped method call return InstanceVariable
def do_switch(self): # get self.SwitchingMethodFunction = getattr(self.DoClass, self.SwitchingMethodStr) # debug self.debug(("self.", self, ["SwitchingMethodFunction"])) # set the SwitchedFunctionStr this is the functing function..and we remove all the tagged Functer@ self.SwitchedFunctionStr = self.SwitchingMethodFunction.__name__.split(Functer.FunctingDecorationStr)[-1] # debug """ self.debug(('self.',self,['SwitchedFunctionStr'])) """ # Check if self.SwitchedFunctionStr.startswith(Doer.DoingDoMethodStr): self.SwitchedFunctionStr = Doer.DoingDoMethodStr.join( self.SwitchedFunctionStr.split(Doer.DoingDoMethodStr)[1:] ) # Definition SwitchedDoStr = self.SwitchedFunctionStr[0].upper() + self.SwitchedFunctionStr[1:] # Debug """ print('SwitchedDoStr is ',SwitchedDoStr) print('') """ # Set self.SwitchedBoolSuffixStr = SwitchedDoStr + "Bool" self.SwitchedInstanceBoolKeyStr = "Switch" + self.SwitchedBoolSuffixStr # debug """ self.debug( ('self.',self,[ 'SwitchedInstanceBoolKeyStr' ])) """ # Definition the SwitchedFunction def SwitchedFunction(*_LiargVariablesList, **_KwargVariablesDict): # debug """ self.debug('We are in the SwitchedFunction !') """ # Alias InstanceVariable = _LiargVariablesList[0] # debug """ self.debug( [ ('self.',self,['SwitchedInstanceBoolKeyStr']), Representer.represent(InstanceVariable,**{'RepresentingAlineaIsBool':False}) ] ) """ if hasattr(InstanceVariable, self.SwitchedInstanceBoolKeyStr) == False: # set at the instance level InstanceVariable.__setattr__(self.SwitchedInstanceBoolKeyStr, False) elif getattr(InstanceVariable, self.SwitchedInstanceBoolKeyStr): # debug """ self.debug('The Instance has already done this method') """ # Return return InstanceVariable # Call the SwitchingMethodFunction self.SwitchingMethodFunction(*_LiargVariablesList, **_KwargVariablesDict) # set True for the Bool after the call InstanceVariable.__setattr__(self.SwitchedInstanceBoolKeyStr, True) # debug """ self.debug(('InstanceVariable.',InstanceVariable,[self.SwitchedBoolSuffixStr])) """ # Return self for the wrapped method call return InstanceVariable # Definition the SwitchedDoerStr SwitchedDoerStr = Doer.getDoerStrWithDoStr(SwitchedDoStr) # debug """ print('SwitchedDoerStr is ',SwitchedDoerStr) print('') """ # Find the corresponding base class to reinit SwitchedDoerClass = SYS._filter( lambda __MroClass: SwitchedDoerStr == SYS.getNameStrWithClassStr(__MroClass.__name__), self.DoClass.__mro__ )[0] # Definition the triggering function that will call the init one def triggerBefore(*_TriggeringVariablesList, **_TriggeringVariablesDict): # Alias TriggeredInstanceVariable = _TriggeringVariablesList[0] # debug """ self.debug('Reinit with '+Representer.represent( TriggeredInstanceVariable.SettingKeyVariable,**{'RepresentingAlineaIsBool':False} ) ) """ # Update with the DoneAttributeVariablesOrderedDict map( lambda __ItemTuple: TriggeredInstanceVariable.__setattr__(__ItemTuple[0], __ItemTuple[1]), SwitchedDoerClass.DoneAttributeVariablesOrderedDict.items(), ) # set the name TriggeredBeforeMethodStr = "triggerBeforeWith" + self.SwitchedBoolSuffixStr triggerBefore.__name__ = TriggeredBeforeMethodStr # debug """ self.debug( [ ("SwitchedClass is "+str(SwitchedClass)), ("TriggeredBeforeMethodStr is "+TriggeredBeforeMethodStr), ("Get Method is "+str(getattr( SwitchedClass, TriggeredBeforeMethodStr) ) if hasattr(SwitchedClass, TriggeredBeforeMethodStr) else "None") ] ) """ # Link the triggerBefore function setattr( self.DoClass, TriggeredBeforeMethodStr, Triggerer.TriggererClass( **{ "TriggeringConditionVariable": [ ("SettingKeyVariable", (operator.eq, self.SwitchedInstanceBoolKeyStr)), (self.SwitchedInstanceBoolKeyStr, (operator.eq, True)), ("SettingValueVariable", (operator.eq, False)), ], "TriggeringHookStr": "Before", } )(triggerBefore), )