# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Printer is an object that can directly print
Strs in the Representer context.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Initiator"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Representer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
Representer=DecorationModule
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class PrinterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'PrintingVariable'
]
def default_init(self,
_PrintingVariable=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
#<DefineDoMethod>
def do__print(self,**_KwargVariablesDict):
#debug
'''
print('self.PrintingVariable is ',self.PrintingVariable)
print('')
'''
#print
print(
Representer.getRepresentedStrWithVariable(
self.PrintingVariable,
**_KwargVariablesDict
)
)
#</DefineClass>
View the Printer sources on Github
In [3]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Attester
from ShareYourSystem.Standards.Interfacers import Printer
#Definition of an instance Printer and make it print hello
MyPrinter=Printer.PrinterClass()._print('hello')
#Definition the AttestedStr
SYS._attest(
[
'MyPrinter is '+SYS._str(MyPrinter)
]
)
#Print
The Debugger from a DebuggerClass instance has a debug function that prints in the console a state (to be defined) of the environnement. This print can be indented with the number of function frames from which the process has passed through, for a nicer visualisation of the kind of hooked functions. More options in the display can be possible like the number of the line in the corresponding code or the pick of KeyStrs helping for precising the debugging instance identity.
View the Debugger notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/Debugger.ipynb)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Debugger from a DebuggerClass instance has a debug function
that prints in the console a state (to be defined)
of the environnement. This print can be indented with
the number of function frames from which the process
has passed through, for a nicer visualisation of the
kind of hooked functions. More options in the display
can be possible like the number of the line in the corresponding
code or the pick of KeyStrs helping for precising the
debugging instance identity.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Interfacers.Printer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Representer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import inspect
Representer=DecorationModule
#</ImportSpecificModules>
#<DefineLocals>
DebuggingStartStr='\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n'
DebuggingEndStr='\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n'
DebuggingElementStr=' '
DebuggingIsStr=' is '
DebuggingHeadPrefixStr='////////////////////////////////\n'
DebuggingHeadSuffixStr='\n////////////////////////////////\n\n'
DebuggingWhoStr='\n*****\n'
#</DefineLocals>
#<DefineFunctions>
def getDebuggedListWithFrame(_Frame):
#Definition the FilePathStr
FilePathStr='/'.join(_Frame.f_code.co_filename.split('/')[-2:])
#Return
return [FilePathStr,_Frame.f_code.co_name]
def getDebuggedStrWithPrintVariable(_PrintVariable):
#Type
Type=type(_PrintVariable)
#Debug
'''
print('l 62 Debugger')
print('Type is ',Type)
print('SYS.StrTypesList is ',SYS.StrTypesList)
print('')
'''
#set the DebuggedStr with the _PrintVariable
if type(_PrintVariable) in SYS.StrTypesList:
return _PrintVariable
elif type(_PrintVariable)==tuple:
#Check for an end
if len(_PrintVariable)>3:
DebuggedEndStr=_PrintVariable[3]
else:
DebuggedEndStr=""
#join
DebuggedStr='\n'.join(
map(
lambda __KeyStr:
_PrintVariable[0]+__KeyStr+DebuggedEndStr+' is '+SYS._str(
_PrintVariable[1][__KeyStr] if type(
_PrintVariable[1]
) in [collections.OrderedDict,dict]
else getattr(
_PrintVariable[1],
__KeyStr
)
if hasattr(_PrintVariable[1],__KeyStr)
else "WARNING : No attribute like this"
,**{
'RepresentingAlineaIsBool':False
}),
_PrintVariable[2]
)
)+'\n'
#return
return DebuggedStr
elif type(_PrintVariable)==list:
return '\n'.join(map(getDebuggedStrWithPrintVariable,_PrintVariable))
else:
#return
return str(_PrintVariable)
#</DefineFunctions>
#<DefineClass>
@DecorationClass()
class DebuggerClass(BaseClass):
RepresentingKeyStrsList=[
'DebuggingPrintStr',
'DebuggingIdentityBool',
'DebuggingFrameBool',
'DebuggingBacksInt'
'DebuggingNotFrameFunctionStrsList',
'DebuggingNotFrameModuleStrsList',
'DebuggingIsBool',
'DebuggedFramesList'
]
def default_init(self,
_DebuggingPrintStr="",
_DebuggingIdentityBool=True,
_DebuggingFrameBool=True,
_DebuggingBacksInt=1,
_DebuggingNotFrameFunctionStrsList=[
"AlertedFunction",
"ArgumentedFunction",
"TriggeredFunction",
"HookedFunction",
"SwitchedFunction",
"<lambda>",
"DoerFunction",
"initDo",
"ImitaterFunction",
"imitateDo",
"superDo_debug",
"do",
"watch",
"switch"
],
_DebuggingNotFrameCodeStrsList=[
"<string>"
],
_DebuggingIsBool=True,
_DebuggedFramesList=None,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_debug(self):
'''
#Special keywords args
if self.DebuggingPrintVariable=='<DoingVariables>':
self.debug(('self.',self,self.__class__.DoingAttributeVariablesOrderedDict.keys()))
'''
#Check
if self.DebuggingIsBool:
#debug
'''
print('Debugger debug method')
print('DebuggedCurrentFrame is ',DebuggedCurrentFrame)
print('self.DebuggedFramesList is ',self.DebuggedFramesList)
print('')
'''
#Definition the DebuggedCurrentFrame
DebuggedCurrentFrame=inspect.currentframe()
for __BackInt in xrange(self.DebuggingBacksInt):
DebuggedCurrentFrame=DebuggedCurrentFrame.f_back
#Init the DebuggedStr
DebuggedStr=DebuggingStartStr
#Append maybe for the first time
DebuggedDecorationBool=False
if len(self.DebuggedFramesList
)==0 or DebuggedCurrentFrame!=self.DebuggedFramesList[0]:
#debug
'''
print('This is the first frame ')
print('')
'''
#Build the DebuggedBackFramesList
DebuggedBackFramesList=[]
DebuggedBackFrame=DebuggedCurrentFrame
while DebuggedBackFrame.f_back!=None:
#if hasattr(self,DebuggedBackFrame.f_back.f_code.co_name):
#debug
'''
print("DebuggedCurrentFrame.f_code.co_name is ",DebuggedCurrentFrame.f_code.co_name)
print("DebuggedBackFrame.f_back.f_code.co_name is ",DebuggedBackFrame.f_back.f_code.co_name)
print('')
'''
#Append
if DebuggedBackFrame.f_back.f_code.co_name in self.DebuggingNotFrameFunctionStrsList or DebuggedBackFrame.f_back.f_code.co_filename.split('/')[-1] in self.DebuggingNotFrameCodeStrsList:
DebuggedDecorationBool=True
else:
DebuggedBackFramesList.append(DebuggedBackFrame.f_back)
DebuggedBackFrame=DebuggedBackFrame.f_back
#Reduce the DebuggedBackFramesList with the DebuggedCurrentFrame
self.DebuggedFramesList=[DebuggedCurrentFrame]+DebuggedBackFramesList
#Debug
'''
print('DebuggedCurrentFrame.f_code.co_name is ',DebuggedCurrentFrame.f_code.co_name)
print('')
'''
#set
CodeStr= DebuggedCurrentFrame.f_code.co_filename.split('/')[-1]
#Shift maybe
if DebuggedCurrentFrame.f_code.co_name in self.DebuggingNotFrameFunctionStrsList or CodeStr in self.DebuggingNotFrameCodeStrsList:
self.DebuggedFramesList=self.DebuggedFramesList[1:]
DebuggedCurrentFrame=self.DebuggedFramesList[0]
#set the DebuggedBackFrameStr
DebuggedBackFrameStr='\nFrom '+' | '.join(
map(
lambda __InspectedList:
' '.join(__InspectedList),
map(getDebuggedListWithFrame,DebuggedBackFramesList)
)
)
#Check
if self.DebuggingFrameBool:
#Add the name of the function or method
DebuggedStr+=DebuggingHeadPrefixStr+" ".join(
[
'/'.join(DebuggedCurrentFrame.f_code.co_filename.split('/')[-2:]),
DebuggedCurrentFrame.f_code.co_name
]
)+DebuggedBackFrameStr+DebuggingHeadSuffixStr
#Update the RepresentingDict
Representer.RepresentedAlineaStr=''.join(
[DebuggingElementStr]*(len(self.DebuggedFramesList)-1))
#debug
'''
print('self.DebuggedAlineaStr is ',self.DebuggedAlineaStr)
print('self.DebuggingRepresentingDict is ',self.DebuggingRepresentingDict)
print('')
'''
#Add the lineno
DebuggedStr+='l.'+str(DebuggedCurrentFrame.f_lineno)+' : '
#Add some features to identify the instance
if self.DebuggingIdentityBool:
DebuggedStr+=DebuggingWhoStr+'I am with '+str(
SYS._filter(
lambda __ItemTuple:
__ItemTuple[0].endswith('KeyStr')
and __ItemTuple[0] not in self.__class__.RepresentedBaseKeyStrsList
+self.__class__.RepresentingKeyStrsList,
self.__dict__.items()
)
)+DebuggingWhoStr
#Add the DebuggedStr from the debugging variable
DebuggedStr+=getDebuggedStrWithPrintVariable(
self.DebuggingPrintStr)
#add the end
DebuggedStr+=DebuggingEndStr
#Print
self._print(
DebuggedStr+Representer.RepresentedAlineaStr,
**{
#'RepresentedDeepInt':1
}
)
#Reinit
#Representer.RepresentedAlineaStr=""
#Return
#return self
#</DefineClass>
View the Debugger sources on Github
In [7]:
# ImportModules
from ShareYourSystem.Standards.Classors import Doer
from ShareYourSystem.Standards.Classors.Representer import _print
from ShareYourSystem.Standards.Objects import Debugger
#Definition a debugging make class
@Doer.DoerClass()
class MakerClass(Debugger.DebuggerClass):
def make1(self):
#debug
self.debug('I am in the make1 method')
#Call the make2 method
self.make2()
#debug
self.debug('I am back in the make1 method')
def make2(self):
#debug
self.debug('I am in the make2 method')
#Call the make3 method
self.make3()
#debug
self.debug('I am back in the make2 method')
def make3(self):
#debug
self.debug('I am in the make3 method')
#Call the make4 method
self.make4()
def make4(self):
#debug
self.debug('I am in the make4 method')
#debug
self.debug('I am still in the make4 method')
#Call the make1
MyMaker=MakerClass()
MyMaker.make1()
#Call the make1 but with also showing the frame of the argumentinf function
MyMaker.DebuggingNotFrameFunctionStrsList=[]
MyMaker.make1()
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Conditioner
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Debugger"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Representer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
Representer=DecorationModule
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class ConditionerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ConditioningTestGetVariable',
'ConditioningGetBoolFunction',
'ConditionedIsBool'
]
def default_init(self,
_ConditioningTestGetVariable=None,
_ConditioningGetBoolFunction=None,
_ConditioningAttestGetVariable=None,
_ConditionedIsBool=True,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
#<DefineDoMethod>
def do_condition(self):
#debug
'''
self.debug(('self.',self,[
'ConditioningTestGetVariable',
'ConditioningAttestGetVariable'
]))
'''
#call
self.ConditionedIsBool=self.ConditioningGetBoolFunction(
self.ConditioningTestGetVariable,
self.ConditioningAttestGetVariable
)
#debug
'''
self.debug(('self.',self,['ConditionedIsBool']))
'''
#</DefineClass>
View the Conditioner sources on Github
In [11]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Attester
from ShareYourSystem.Standards.Objects import Conditioner
#Definition of an instance Conditioner and make it print hello
MyConditioner=Conditioner.ConditionerClass(**{
'ConditioningGetBoolFunction':lambda _TestVariable,_AttestVariable:_TestVariable==_AttestVariable,
'ConditioningAttestGetVariable':2
})
MyConditioner.condition(3).ConditionedIsBool
#Definition the AttestedStr
SYS._attest(
[
'MyConditioner.condition(3).ConditionedIsBool is '+str(
MyConditioner.condition(3).ConditionedIsBool),
'MyConditioner.condition(2).ConditionedIsBool is '+str(
MyConditioner.condition(2).ConditionedIsBool)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
A Concluder
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Conditioner"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Tester"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class ConcluderClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ConcludingTestVariable',
'ConcludingConditionVariable',
'ConcludedConditionIsBoolsList',
'ConcludedIsBool'
]
def default_init(self,
_ConcludingTestVariable=None,
_ConcludingConditionVariable=None,
_ConcludedConditionIsBoolsList=None,
_ConcludedIsBool=True,
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_conclude(self):
""" """
#debug
'''
self.debug(('self.',self,['ConcludingConditionVariable']))
'''
#Apply __getitem__
self.ConcludedConditionIsBoolsList=map(
lambda __ConcludingConditionTuple:
self.condition(
self.ConcludingTestVariable[
__ConcludingConditionTuple[0]
] if type(
__ConcludingConditionTuple[0])
in SYS.StrTypesList else __ConcludingConditionTuple[0],
__ConcludingConditionTuple[1],
__ConcludingConditionTuple[2]
).ConditionedIsBool,
self.ConcludingConditionVariable
)
#all
self.ConcludedIsBool=all(self.ConcludedConditionIsBoolsList)
#Return self
#return self
#</DefineClass>
View the Concluder sources on Github
In [15]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Objects import Concluder
import operator
#Definition of an instance Concluder and make it print hello
MyConcluder=Concluder.ConcluderClass().conclude(
{'MyColorStr':'Black','MySuperInt':6},
[
('MyColorStr',operator.eq,"Black"),
('MySuperInt',operator.gt,3),
(1,operator.eq,1)
]
)
#Definition the AttestedStr
SYS._attest(
[
'MyConcluder is '+SYS._str(
MyConcluder,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
),
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Caller is an Object that helps to get an make call a function/method.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Packager"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Tester"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import sys
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class CallerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'CallingVariable',
'CallingFunctionStr',
'CallingMethod',
'CallingMethodStr',
'CallingInstanceVariable',
'CallingClass',
'CallingClassStr',
]
def default_init(self,
_CallingVariable=None,
_CallingFunctionStr="",
_CallingMethod=None,
_CallingMethodStr="",
_CallingInstanceVariable=None,
_CallingClass=None,
_CallingClassStr="",
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
#<DefineDoMethod>
def do_call(self):
#Module first to know where we are
self.package()
#debug
'''
print("self.CallingVariable is ",self.CallingVariable)
print('')
'''
#If it was not yet setted or changed
if self.CallingVariable==None or self.CallingVariable.__name__!=self.CallingFunctionStr:
#debug
'''
print('Get in the module')
print('self.PackagingModuleVariable is '+str(self.PackagingModuleVariable))
print('')
'''
#Get maybe the one in the module
if self.CallingFunctionStr!="":
#debug
'''
print('Get in the module with the function Str')
print('self.CallingFunctionStr is ',self.CallingFunctionStr)
print('')
'''
#Get and return
self.CallingVariable=getattr(self.PackagedModuleVariable,self.CallingFunctionStr)
return self
#Get the function
if self.CallingVariable==None or self.CallingVariable.__name__!=self.CallingMethodStr:
#debug
'''
print('Get in a class')
print('self.PackagingModuleVariable is '+str(self.PackagingModuleVariable))
print('self.CallingVariable is ',self.CallingVariable)
print('self.CallingMethodStr is ',self.CallingMethodStr)
print('self.CallingClass is ',self.CallingClass)
print('self.CallingClassStr is ',self.CallingClassStr)
print('self.CallingInstanceVariable is ',self.CallingInstanceVariable)
print('')
'''
#Get with the CallingInstanceVariable class maybe
if self.CallingClass==None and self.CallingInstanceVariable!=None:
self.CallingClass=self.CallingInstanceVariable.__class__
#Import the module if not already
if self.CallingClass==None:
if self.CallingClassStr!="":
self.CallingClass=getattr(self.PackagedModuleVariable,self.CallingClassStr)
else:
self.CallingClass=getattr(
self.PackagedModuleVariable,
SYS.getClassStrWithNameStr(
SYS.getNameStrWithModuleStr(self.PackagedModuleVariable.__name__)
)
)
#debug
'''
print('Now get the unbounded method function')
print('self.CallingClass is '+str(self.CallingClass))
print('')
'''
#Check
if self.CallingMethodStr!="":
#debug
'''
print('self.CallingMethodStr is ',self.CallingMethodStr)
print('')
'''
#Return
self.CallingVariable=getattr(self.CallingClass,self.CallingMethodStr)
#Return
#return self
#</DefineClass>
View the Caller sources on Github
In [19]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Objects import Caller
#Definition of a Caller instance
MyCaller=Caller.CallerClass()
#Call the _print from the Rep
MyCaller.call(
_FunctionStr='represent',
**{
'PackagingModuleVariable':'ShareYourSystem.Standards.Classors.Representer',
}
)
#Definition the AttestedStr
SYS._attest(
[
'MyCaller is '+SYS._str(
MyCaller,
**{
'RepresentingBaseKeyStrsListBool':False
}
)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Cloner
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Caller"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import copy
#</ImportSpecificModules>
#<DefineDoStrsList>
DoStrsList=["Cloner","Clone","Cloning","Cloned"]
#<DefineDoStrsList>
#<DefineLocals>
CloningIdStringsList=[]
#</DefineLocals>
def getCopiedMutableVariableWithMutableVariable(_MutableVariable,**_KwargVariablesDict):
if 'CloningIdsDict' not in _KwargVariablesDict:
_KwargVariablesDict['CloningIdsDict']={}
if 'CloningNotCopyKeyStringsList' not in _KwargVariablesDict:
_KwargVariablesDict['CloningNotCopyKeyStringsList']=[]
#get the type
Type=type(_MutableVariable)
#Debug
print('_MutableVariable is ',_MutableVariable)
print('')
#itemized variable case
if Type in [dict,collections.OrderedDict]:
return Type(
map(
lambda __ItemTuple:
(
__ItemTuple[0],
__ItemTuple[1].clone(
_KwargVariablesDict['CloningIdsDict'],
_KwargVariablesDict['CloningNotCopyKeyStringsList']
)
if hasattr(__ItemTuple[1],'clone')
else getCopiedMutableVariableWithMutableVariable(
__ItemTuple[1],
**_KwargVariablesDict
)
if type(__ItemTuple[1]) in [list,tuple,set,dict,collections.OrderedDict]
else __ItemTuple[1]
),
_MutableVariable.items()
)
)
#listed variable case
elif Type in [list,tuple,set]:
return Type(
map(
lambda __ListedVariable:
__ListedVariable.clone(
_KwargVariablesDict['CloningIdsDict'],
_KwargVariablesDict['CloningNotCopyKeyStringsList']
)
if hasattr(__ListedVariable,'clone')
else getCopiedMutableVariableWithMutableVariable(
__ListedVariable,
**_KwargVariablesDict
)
if type(__ListedVariable) in [list,tuple,set,dict,collections.OrderedDict]
else __ListedVariable,
_MutableVariable
)
)
#other
else:
return _MutableVariable
#<DefineClass>
@DecorationClass(**{'DoingGetBool':True})
class ClonerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'CloningIdsDict',
'CloningNotCopyKeyStringsList',
'CloningResetBool',
'ClonedItemTuplesList',
'ClonedCopyVariable'
]
def default_init(self,
_CloningIdsDict=None,
_CloningNotCopyKeyStringsList=None,
_CloningResetBool=False,
_ClonedItemTuplesList=None,
_ClonedCopyVariable=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
#@Argumenter.ArgumenterClass()
def do_clone(self):
#filter
self.ClonedItemTuplesList=SYS._filter(
lambda __ItemTuple:
__ItemTuple[0] not in self.CloningNotCopyKeyStringsList,
self.__dict__.items()
)
"""
#global
global CloningIdStringsList
#check
if self.CloningResetBool:
CloningIdStringsList=[]
self.CloningIdsDict={}
#if self.IdString in CloningIdStringsList:
#return
#append
#CloningIdStringsList.append(id(self))
#debug
'''
self.debug(
('self.',self,['ClonedItemTuplesList'])
)
'''
#debug
self.ClonedValueTuplesList=[]
for __ClonedItemTuple in self.ClonedItemTuplesList:
print('__ClonedItemTuple[0] is ',__ClonedItemTuple[0])
print('__ClonedItemTuple[1] is ',__ClonedItemTuple[1])
print('')
ClonedIdString=id(__ClonedItemTuple[1])
if hasattr(
__ClonedItemTuple[1],
'clone'
):
print('IdString in CloningIdStringsList is ',ClonedIdString in CloningIdStringsList)
print('')
#Check
if ClonedIdString in CloningIdStringsList:
#
self.ClonedValueTuplesList.append(self.CloningIdsDict[ClonedIdString])
else:
#append
CloningIdStringsList.append(ClonedIdString)
#set
self.CloningIdsDict[ClonedIdString]=__ClonedItemTuple[1]
#append
self.ClonedValueTuplesList.append(
__ClonedItemTuple[1].clone(
self.CloningIdsDict,
self.CloningNotCopyKeyStringsList
)
)
else:
self.ClonedValueTuplesList.append(
getCopiedMutableVariableWithMutableVariable(__ClonedItemTuple[1],
**{
'CloningIdsDict':self.CloningIdsDict,
'CloningNotCopyKeyStringsList':self.CloningNotCopyKeyStringsList
})
)
'''
#copy or clone
self.ClonedValueTuplesList=map(
lambda __ClonedValueTuple:
__ClonedValueTuple.clone() if hasattr(
__ClonedValueTuple,
'clone'
)
else getCopiedMutableVariableWithMutableVariable(__ClonedValueTuple),
SYS.unzip(self.ClonedItemTuplesList,[1])
)
'''
#update
self.CloningIdsDict[self.IdString]=self.ClonedCopyVariable
#instance
self.ClonedCopyVariable=self.__class__(
**dict(
copy.deepcopy(
self.ClonedItemTuplesList
#zip(
# SYS.unzip(self.ClonedItemTuplesList,[0]),
# self.ClonedValueTuplesList
# )
)
)
)
"""
for __ClonedItemTuple in self.ClonedItemTuplesList:
print(__ClonedItemTuple)
copy.deepcopy(__ClonedItemTuple)
#copy
self.ClonedCopyVariable=copy.deepcopy(self)
#return
return self.ClonedCopyVariable
#Return self
#return self
#</DefineClass>
View the Cloner sources on Github
In [23]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Objects import Cloner
#Definition of an instance Cloner
MyCloner=Cloner.ClonerClass()
MyCloner.MyInt=1
#clone
MyFirstCloner=MyCloner.clone()
MyFirstCloner.MyInt=2
#Definition the AttestedStr
SYS._attest(
[
'MyCloner is '+SYS._str(MyCloner),
'MyFirstCloner is '+SYS._str(MyFirstCloner)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Rebooter
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Objects.Concluder"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import copy
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class RebooterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'RebootingDoStrsList',
'RebootingNameStrsList',
'RebootingAllDoBool',
'RebootingAllNameBool',
'RebootingDoingIsBool',
'RebootedWatchBoolKeyStrsList',
'RebootingSetDoIsBool'
]
def default_init(self,
_RebootingNameStrsList=None,
_RebootingDoStrsList=None,
_RebootingAllNameBool=True,
_RebootingAllDoBool=True,
_RebootingSetDoIsBool=True,
_RebootedWatchBoolKeyStrsList=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_reboot(self):
#set
if self.RebootingAllNameBool:
#filter
self.RebootingNameStrsList=SYS.filterNone(
map(
lambda __MroClass:
__MroClass.NameStr
if hasattr(__MroClass,'DoStr')
else None,
self.__class__.__mro__
)
)
#set
if self.RebootingAllDoBool:
#filter
self.RebootingDoStrsList=SYS.filterNone(
map(
lambda __MroClass:
__MroClass.DoStr
if hasattr(__MroClass,'DoStr')
else None,
self.__class__.__mro__
)
)
#debug
'''
self.debug(
('self.',self,[
'RebootingDoStrsList',
'RebootingNameStrsList'
])
)
'''
#map
map(
lambda __RebootingNameStr:
self.setSwitch(
__RebootingNameStr,
self.RebootingDoStrsList
),
self.RebootingNameStrsList
)
#Check
if self.RebootingSetDoIsBool:
#debug
'''
self.debug(('self.',self,['RebootingNameStrsList']))
'''
#map
map(
lambda __RebootingClass:
self.setDone(
__RebootingClass
)
#if hasattr(__RebootingClass,'DoneAttributeVariablesOrderedDict')
#else None,
,map(
lambda __RebootingClassStr:
getattr(
SYS,
__RebootingClassStr
)
#if hasattr(SYS,__RebootingClassStr)
#else None
,map(SYS.getClassStrWithNameStr,self.RebootingNameStrsList)
)
)
#</DefineClass>
View the Rebooter sources on Github
In [27]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Classors import Classer
from ShareYourSystem.Standards.Objects import Rebooter
#Definition
@Classer.ClasserClass(**
{
'ClassingSwitchMethodStrsList':['make']
})
class MakerClass(Rebooter.RebooterClass):
#Definition
RepresentingKeyStrsList=[
'MakingMyFloat',
'MadeMyInt'
]
def default_init(self,
_MakingMyFloat=0.,
_MadeMyInt=0,
**_KwarVariablesDict
):
Rebooter.RebooterClass.__init__(self,**_KwarVariablesDict)
def do_make(self):
#print
print('I am in the do_make of the Maker')
#cast
self.MadeMyInt=int(self.MakingMyFloat)
#Definition
@Classer.ClasserClass(**{
'ClassingSwitchMethodStrsList':["make"]
})
class BuilderClass(MakerClass):
#Definition
RepresentingKeyStrsList=[
]
def default_init(self,
**_KwarVariablesDict
):
MakerClass.__init__(self,**_KwarVariablesDict)
def mimic_make(self):
#print
print('I am in the mimic_make of the Builder')
#call the parent method
MakerClass.make(self)
#cast
self.MadeMyInt+=10
def do_build(self):
pass
#Definition an instance
MyBuilder=BuilderClass()
#Print
print('Before make, MyBuilder is ')
SYS._print(MyBuilder,**{
'RepresentingKeyStrsList':[
'MakingMyFloat',
'MadeMyInt',
]
})
#make once
MyBuilder.make(3.)
#Print
print('After the first make, MyBuilder is ')
SYS._print(MyBuilder,**{
'RepresentingKeyStrsList':[
'MakingMyFloat',
'MadeMyInt',
]
})
#make again
MyBuilder.make(5.)
#Print
print('After the second make, MyBuilder is ')
SYS._print(MyBuilder,**{
'RepresentingKeyStrsList':[
'MakingMyFloat',
'MadeMyInt',
]
})
#make again
print('Now we reboot')
MyBuilder.reboot(
#_NameStrsList=['Maker','Builder'],
#_DoStrsList=['Make'],
#_AllDoBool=True,
#_AllNameBool=True,
)
#Print
print('After the reboot, MyBuilder is ')
SYS._print(MyBuilder,**{
'RepresentingKeyStrsList':[
'MakingMyFloat',
'MadeMyInt',
]
})
#make again
MyBuilder.make(8.)
#Definition the AttestedStr
SYS._attest(
[
'MyBuilder is '+SYS._str(
MyBuilder,
**{
'RepresentingAlineaIsBool':False,
'RepresentingKeyStrsList':[
'MakingMyFloat',
'MadeMyInt',
'RebootedWatchBoolKeyStrsList'
]
}
)
]
)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Packager is an Object that helps to get a module in the SYS framework
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Interfacers.Folderer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Tester"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import sys
import importlib
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class PackagerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'PackagingModuleVariable',
'PackagedModuleStr',
'PackagedModuleVariable',
'PackagedInstallFolderPathStr',
'PackagedLocalFolderPathStr'
]
def default_init(self,
_PackagingModuleVariable=None,
_PackagedModuleStr="",
_PackagedModuleVariable=None,
_PackagedInstallFolderPathStr="",
_PackagedLocalFolderPathStr="",
**_KwargVariablesDict
):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_package(self):
#debug
'''
self.debug(('self.',self,
[
'PackagingModuleVariable'
]))
'''
#Check
if type(self.PackagingModuleVariable) in SYS.StrTypesList:
self.PackagedModuleStr=self.PackagingModuleVariable
else:
self.PackagedModuleVariable=self.PackagingModuleVariable
self.PackagedModuleStr=self.PackagingModuleVariable.__name__
#Check for a module
if self.PackagedModuleVariable==None or self.PackagedModuleStr!=self.PackagedModuleVariable.__name__:
#Check
if self.PackagedModuleStr!="":
#Import the module if not already
if self.PackagedModuleStr not in sys.modules:
importlib.import_module(self.PackagedModuleStr)
#set with sys
self.PackagedModuleVariable=sys.modules[self.PackagedModuleStr]
#set
if self.PackagedModuleVariable!=None:
#set
self.PackagedInstallFolderPathStr='/'.join(
self.PackagedModuleVariable.__file__.split('/')[:-1]
)+'/'
#set
self.PackagedLocalFolderPathStr=SYS.PythonlogyLocalFolderPathStr+self.PackagedModuleVariable.__name__.replace(
'.','/')+'/'
#debug
'''
self.debug(('self.',self,[
'PackagedInstallFolderPathStr',
'PackagedLocalFolderPathStr'
]))
'''
#Hook
self.folder(self.PackagedLocalFolderPathStr)
#Return
#return self
#</DefineClass>
View the Packager sources on Github
In [31]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Objects import Packager
#Definition of a Packager instance and module
MyPackager=Packager.PackagerClass().package(
'ShareYourSystem.Standards.Interfacers.Printer'
)
#Definition the AttestedStr
SYS._attest(
[
'MyPackager'+SYS._str(MyPackager)
]
)
#Print