def default_init(self,**_KwargVariablesDict): #set the NameStr self.NameStr=SYS.getNameStrWithClassStr(self.__class__.__name__) #Map the update map( lambda __ItemTuple: self.__setattr__(__ItemTuple[0],__ItemTuple[1]) #If we want to not set the items setted during hooks and that are not specified... if hasattr(self,__ItemTuple[0]) else None ,_KwargVariablesDict.iteritems() ) #call the base method object.__init__(self)
def getSwitch(_InstanceVariable,_MethodVariable=None): #Check if _MethodVariable==None: SwitchItemTuplesList=_InstanceVariable.SwitchMethodDict.items() elif type(_MethodVariable) in [list,tuple]: SwitchItemTuplesList=map( lambda __MethodStr: ( __MethodStr, _InstanceVariable.SwitchMethodDict[__MethodStr] ), _MethodVariable ) else: SwitchItemTuplesList=[ ( _MethodVariable, _InstanceVariable.SwitchMethodDict[_MethodVariable] ) ] #Debug ''' print('getSwitch l 266') print('_MethodVariable is ') print(_MethodVariable) print('SwitchItemTuplesList is ') print(SwitchItemTuplesList) print('') ''' #return WatchKeyStrsList=SYS.flat( SYS.flat( map( lambda __SwitchItemTuple: map( lambda __ClassStr: map( lambda __HookStr: 'Watch'+__HookStr+SYS.getUpperWordStr( __SwitchItemTuple[0] )+'With'+SYS.getNameStrWithClassStr( __ClassStr )+'Bool', ['Before','After'] ), map(lambda __Class:__Class.__name__,__SwitchItemTuple[1]) ), SwitchItemTuplesList ) ) ) #Debug ''' print('getSwitch l 300') print('WatchKeyStrsList is ') print(WatchKeyStrsList) print('WatchKeyStrsList is ') print(WatchKeyStrsList) print('') ''' #return return dict( zip( WatchKeyStrsList, map( lambda __WatchKeyStr: getattr(_InstanceVariable,__WatchKeyStr), WatchKeyStrsList ) ) )
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), )
def __call__(self,_Class): #/###################/# # Set the NameStr, Module, SelfClass... # #get self.Module=sys.modules[_Class.__module__] #debug ''' print('Classor l.53 __call__ method') print('_Class is ',_Class) print('') ''' #set in the class the classed Strs _Class.NameStr=SYS.getNameStrWithClassStr(_Class.__name__) #Give a Pointer to the Hooker setattr(_Class,'DeriveClassor',self) #set to the SYS the module if len(SYS.NameStrsList)==0: setattr(SYS,self.NameStr,sys.modules[self.__class__.__module__]) setattr(SYS,self.__class__.__name__,self.__class__) SYS.NameStrsList.append(self.NameStr) setattr(SYS,_Class.NameStr,self.Module) setattr(SYS,_Class.__name__,_Class) SYS.NameStrsList.append(_Class.NameStr) #get the module and set it to the class _Class.Module=self.Module _Class.Module.LocalFolderPathStr=SYS.PythonlogyLocalFolderPathStr+self.Module.__name__.replace( '.','/')+'/' #set a pointer to itself _Class.SelfClass=_Class _Class.MroClassesList=_Class.__mro__ _Class.MroClassesDict=dict( map( lambda __Class: (__Class.__name__,__Class), _Class.__mro__ ) ) #Check if hasattr(_Class,'callAllMro')==False: setattr( _Class, callAllMro.__name__, callAllMro ) setattr( _Class, setAllMro.__name__, setAllMro ) setattr( _Class, mapSetAllMro.__name__, mapSetAllMro ) setattr( _Class, getClass.__name__, getClass ) #add in LocalModuleFolderPathStrAndModuleStrTuplesList global LocalModuleFolderPathStrAndModuleStrTuplesList LocalModuleFolderPathStrAndModuleStrTuplesList.append( ( _Class.Module.LocalFolderPathStr, _Class.Module.__name__ ) ) #/###################/# # Give ref to the concept module # #append ConceptModuleStr='.'.join(_Class.Module.__name__.split('.')[:-1]) if hasattr(_Class,"ConceptModuleStr")==False or _Class.ConceptModuleStr!=ConceptModuleStr: #set _Class.ConceptModuleStr=ConceptModuleStr #append LocalModuleFolderPathStrAndModuleStrTuplesList.append( ( SYS.PythonlogyLocalFolderPathStr+ConceptModuleStr.replace('.','/')+'/', ConceptModuleStr ) ) #/###################/# # Alert the base method that a derive object exists # #set if len(_Class.__bases__)>0: #set the DerivedBaseClas FirstBaseClass=_Class.__bases__[0] #Debug ''' print('l. 183 Classor') print('We can set derived bases for the base') print('FirstBaseClass is ',FirstBaseClass) print('') ''' #Append to the parent class if hasattr(FirstBaseClass,'DeriveClassesList'): FirstBaseClass.DeriveClassesList.append(_Class) elif FirstBaseClass!=object: FirstBaseClass.DeriveClassesList=[_Class] #/###################/# # Inspect the methods # #Get the Methods _Class.InspectMethodDict=SYS.MethodDict(_Class) #dict _Class.InspectInspectDict=dict( map( lambda __MethodItemTuple: ( __MethodItemTuple[0], SYS.InspectDict( __MethodItemTuple[1] ) ), _Class.InspectMethodDict.items() ) ) #/###################/# # set the KeyStrsList # #set the KeyStrsList _Class.KeyStrsList=SYS.getKeyStrsListWithClass(_Class)+['KeyStrsList'] #/###################/# # alias # self.WrapClass=_Class #Return return _Class