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 <abpillai@gmail.com>
11+ Created Anand B Pillai <abpillai@gmail.com>
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
2425 if val .find ('-' ) != - 1 :
2526 val = 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
4444 def __getattr__ (self , name ):
4545
@@ -127,11 +127,13 @@ def isLeaf(self):
127127 return not self ._children
128128
129129 def getName (self ):
130+
130131 """ Return the name of this ConfigInfo object """
131132
132133 return self ._name
133134
134135 def getIndex (self , child ):
136+
135137 """ Return the index of the child ConfigInfo object 'child' """
136138
137139 if child in self ._children :
@@ -145,29 +147,31 @@ def getDict(self):
145147 return self [self ._name ]
146148
147149 def 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
152154 childDict = self .getInfoDict (child )
153155 if childDict :
154156 return 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
161163 childDict = self .getInfoDict (child )
162164 if childDict :
163165 childDict [key ] = value
164166
165167 def getChildren (self ):
168+
166169 """ Return the list of immediate children of this object """
167170
168171 return self ._children
169172
170173 def getAllChildren (self ):
174+
171175 """ Return the list of all children of this object """
172176
173177 l = []
@@ -178,13 +182,15 @@ def getAllChildren(self):
178182 return l
179183
180184 def getChild (self , name ):
185+
181186 """ Return the immediate child object with the given name """
182187
183188 for child in self ._children :
184189 if child .getName () == name :
185190 return child
186191
187192 def 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):
196202 return child
197203
198204 def 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):
210217 return children
211218
212219 def getPropertyDict (self ):
220+
213221 """ Return the property dictionary """
214222
215223 d = self .getChild ('__properties' )
@@ -219,6 +227,7 @@ def getPropertyDict(self):
219227 return {}
220228
221229 def getParent (self ):
230+
222231 """ Return the person who created me """
223232
224233 return self ._father
0 commit comments