55A class which defines a composite object which can store
66hieararchical dictionaries with names.
77
8- This class is same as a hiearchical dictionary, but it
9- provides methods to add/access/modify children by name,
10- like a Composite.
8+ This class is same as a hiearchical dictionary, but it provides methods
9+ to add/access/modify children by name, like a Composite.
1110
12- Created Anand B Pillai <[email protected] > 11+ Created Anand B Pillai <[email protected] > 1312
1413"""
1514__author__ = "Anand B Pillai"
1817
1918
2019def normalize (val ):
21- """ Normalize a string so that it can be used as an attribute
22- to a Python object """
20+ """Normalize a string so that it can be used as an attribute to a Python
21+
22+ object
23+ """
2324
2425if val .find ('-' ) != - 1 :
2526val = val .replace ('-' , '_' )
@@ -38,8 +39,7 @@ def denormalize(val):
3839
3940class SpecialDict (dict ):
4041
41- """ A dictionary type which allows direct attribute
42- access to its keys """
42+ """A dictionary type which allows direct attribute access to its keys """
4343
4444def __getattr__ (self , name ):
4545
@@ -127,11 +127,13 @@ def isLeaf(self):
127127return not self ._children
128128
129129def getName (self ):
130+
130131""" Return the name of this ConfigInfo object """
131132
132133return self ._name
133134
134135def getIndex (self , child ):
136+
135137""" Return the index of the child ConfigInfo object 'child' """
136138
137139if child in self ._children :
@@ -145,29 +147,31 @@ def getDict(self):
145147return self [self ._name ]
146148
147149def getProperty (self , child , key ):
148- """ Return the value for the property for child
149- 'child' with key 'key' """
150+
151+ """Return the value for the property for child 'child' with key 'key' """
150152
151153# First get the child's dictionary
152154childDict = self .getInfoDict (child )
153155if childDict :
154156return childDict .get (key , None )
155157
156- def setProperty (self , child , key , value ):
157- """ Set the value for the property 'key' for
158- the child 'child' to 'value' """
158+ def setProperty (self , child , key , value ):
159+
160+ """Set the value for the property 'key' for the child 'child' to 'value' """
159161
160162# First get the child's dictionary
161163childDict = self .getInfoDict (child )
162164if childDict :
163165childDict [key ] = value
164166
165167def getChildren (self ):
168+
166169""" Return the list of immediate children of this object """
167170
168171return self ._children
169172
170173def getAllChildren (self ):
174+
171175""" Return the list of all children of this object """
172176
173177l = []
@@ -178,13 +182,15 @@ def getAllChildren(self):
178182return l
179183
180184def getChild (self , name ):
185+
181186""" Return the immediate child object with the given name """
182187
183188for child in self ._children :
184189if child .getName () == name :
185190return child
186191
187192def findChild (self , name ):
193+
188194""" Return the child with the given name from the tree """
189195
190196# Note - this returns the first child of the given name
@@ -196,6 +202,7 @@ def findChild(self, name):
196202return child
197203
198204def findChildren (self , name ):
205+
199206""" Return a list of children with the given name from the tree """
200207
201208# Note: this returns a list of all the children of a given
@@ -210,6 +217,7 @@ def findChildren(self, name):
210217return children
211218
212219def getPropertyDict (self ):
220+
213221""" Return the property dictionary """
214222
215223d = self .getChild ('__properties' )
@@ -219,6 +227,7 @@ def getPropertyDict(self):
219227return {}
220228
221229def getParent (self ):
230+
222231""" Return the person who created me """
223232
224233return self ._father
0 commit comments