# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
A Parenter completes the list of grand-parent nodes that
a child node could have. It acts only at one level.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Noders.Distinguisher"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import copy
from ShareYourSystem.Standards.Itemizers import Pather
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass(
**{'ClassingSwitchMethodStrsList':['parent']}
)
class ParenterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ParentingWalkBool',
'ParentedDeriveParentersList',
'ParentedNodeCollectionStrsList',
'ParentedNodePathStr'
]
def default_init(self,
_ParentingWalkBool=True,
_ParentedDeriveParentersList=None,
_ParentedNodeCollectionStrsList=None,
_ParentedNodePathStr="",
**_KwargVariablesDict):
#Call the parent init method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_parent(self):
#debug
'''
self.debug(('self.',self,['ParentingNodeStr','NodePointDeriveNoder']))
'''
#Check of a parent pointer
if self.NodePointDeriveNoder!=None:
#debug
'''
self.debug('We are going to node the parent pointer')
'''
#Parent the parent maybe
if self.ParentingWalkBool:
#parent the parent
self.NodePointDeriveNoder.parent()
#set
self.ParentedDeriveParentersList=[self.NodePointDeriveNoder
]+self.NodePointDeriveNoder.ParentedDeriveParentersList
self.ParentedNodeCollectionStrsList=[self.NodedCollectionStr
]+self.NodePointDeriveNoder.ParentedNodeCollectionStrsList
self.ParentedNodeCollectionStrsList.reverse()
#definition
ParentedNodePathStrsList=map(
lambda __ParentedDeriveParenter:
__ParentedDeriveParenter.NodeKeyStr,
self.ParentedDeriveParentersList
)
ParentedNodePathStrsList.reverse()
#Debug
'''
self.debug('ParentedNodePathStrsList is '+str(ParentedNodePathStrsList))
'''
#set
self.ParentedNodePathStr=Pather.PathPrefixStr.join(ParentedNodePathStrsList)
#Return self
#return self
#</DefineClass>
View the Parenter sources on Github
In [3]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Standards.Noders import Parenter
#Short expression and set in the appended manner
MyParenter=Parenter.ParenterClass().__setitem__(
'<Tree>ChildParenter',
Parenter.ParenterClass().__setitem__(
'<Tree>GrandChildParenter',
Parenter.ParenterClass()
)
)
#Parent for the children
#MyParenter['<Tree>ChildParenter'].parent('Tree')
MyParenter['<Tree>ChildParenter']['<Tree>GrandChildParenter'].parent()
#Definition the AttestedStr
SYS._attest(
[
'MyParenter is '+SYS._str(
MyParenter,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
#Print