@@ -30,8 +30,10 @@ def fromdict____(cls, dic):
3030 """
3131 # print(f"fromdict____ dic: {dic}") # Debug
3232 result = DotDict ()
33+
3334 for key in dic :
3435 result .setattr____ (key , dic [key ])
36+
3537 return result
3638
3739 @classmethod
@@ -66,26 +68,34 @@ def __init__(self, *args, **kwargs):
6668 # Set the inherited keys from the custom class level
6769 if selftype is not DotDict and issubclass (selftype , DotDict ):
6870 classdict = type (self ).__dict__
71+
6972 for key in classdict :
7073 key = str (key )
7174 # print(f"__init__ classdict {key}: {classdict[key]}") # Debug
75+
7276 if not type (self ).isprotected____ (key ):
7377 value = classdict [key ]
7478 self .setattr____ (key , value )
79+ # end for
80+ # end if
7581
7682 # Set keys with the key names from the variable arguments
7783 for arg in args :
7884 arg = str (arg )
7985 # print(f"__init__ *args arg {arg}") # Debug
86+
8087 if not selftype .isprotected____ (key ):
8188 self .setattr____ (arg , None )
89+ # end for
8290
8391 # Set keys with the key names and values from the keyword arguments
8492 for kw in kwargs :
8593 kw = str (kw )
8694 # print(f"__init__ **kwargs kw {kw}: {kwargs[kw]}") # Debug
95+
8796 if not selftype .isprotected____ (key ):
8897 self .setattr____ (kw , kwargs [kw ])
98+ # end for
8999
90100 def __getattr__ (self , name ):
91101 return self .getattr____ (name )
@@ -142,8 +152,10 @@ def setattr____(self, name, value):
142152 """
143153 if isinstance (value , dict ):
144154 value = DotDict .fromdict____ (value )
155+
145156 if not type (self ).isprotected____ (name ):
146157 self .__dict__ [name ] = value
158+
147159 value = self .__dict__ [name ]
148160 return value
149161
@@ -183,11 +195,14 @@ def setclassattr____(self, name, value):
183195 value: the value
184196 """
185197 selftype = type (self )
198+
186199 if isinstance (value , DotDict ):
187200 value = value .todict____ ()
201+
188202 if not selftype .isprotected____ (name ):
189203 self .setattr____ (name , value )
190204 setattr (selftype , name , value )
205+
191206 value = selftype .__dict__ [name ]
192207 return value
193208
@@ -198,10 +213,12 @@ def str____(self):
198213 result: the resulting string representation
199214 """
200215 result = ".{}"
216+
201217 if len (self .__dict__ ) <= 0 :
202218 return result
203219
204220 result = ".{"
221+
205222 for key in self .__dict__ :
206223 result += f"{ key .__str__ ()} : { self .__dict__ [key ].__str__ ()} , "
207224
@@ -219,9 +236,14 @@ def todict____(self):
219236 result: the result dict
220237 """
221238 result = {}
239+
222240 for key in self .__dict__ :
223241 value = self .__dict__ [key ]
242+
224243 if isinstance (value , DotDict ):
225244 value = value .todict____ ()
245+
226246 result [key ] = value
247+ # end for
248+
227249 return result
0 commit comments