@@ -30,8 +30,10 @@ def fromdict____(cls, dic):
30
30
"""
31
31
# print(f"fromdict____ dic: {dic}") # Debug
32
32
result = DotDict ()
33
+
33
34
for key in dic :
34
35
result .setattr____ (key , dic [key ])
36
+
35
37
return result
36
38
37
39
@classmethod
@@ -66,26 +68,34 @@ def __init__(self, *args, **kwargs):
66
68
# Set the inherited keys from the custom class level
67
69
if selftype is not DotDict and issubclass (selftype , DotDict ):
68
70
classdict = type (self ).__dict__
71
+
69
72
for key in classdict :
70
73
key = str (key )
71
74
# print(f"__init__ classdict {key}: {classdict[key]}") # Debug
75
+
72
76
if not type (self ).isprotected____ (key ):
73
77
value = classdict [key ]
74
78
self .setattr____ (key , value )
79
+ # end for
80
+ # end if
75
81
76
82
# Set keys with the key names from the variable arguments
77
83
for arg in args :
78
84
arg = str (arg )
79
85
# print(f"__init__ *args arg {arg}") # Debug
86
+
80
87
if not selftype .isprotected____ (key ):
81
88
self .setattr____ (arg , None )
89
+ # end for
82
90
83
91
# Set keys with the key names and values from the keyword arguments
84
92
for kw in kwargs :
85
93
kw = str (kw )
86
94
# print(f"__init__ **kwargs kw {kw}: {kwargs[kw]}") # Debug
95
+
87
96
if not selftype .isprotected____ (key ):
88
97
self .setattr____ (kw , kwargs [kw ])
98
+ # end for
89
99
90
100
def __getattr__ (self , name ):
91
101
return self .getattr____ (name )
@@ -142,8 +152,10 @@ def setattr____(self, name, value):
142
152
"""
143
153
if isinstance (value , dict ):
144
154
value = DotDict .fromdict____ (value )
155
+
145
156
if not type (self ).isprotected____ (name ):
146
157
self .__dict__ [name ] = value
158
+
147
159
value = self .__dict__ [name ]
148
160
return value
149
161
@@ -183,11 +195,14 @@ def setclassattr____(self, name, value):
183
195
value: the value
184
196
"""
185
197
selftype = type (self )
198
+
186
199
if isinstance (value , DotDict ):
187
200
value = value .todict____ ()
201
+
188
202
if not selftype .isprotected____ (name ):
189
203
self .setattr____ (name , value )
190
204
setattr (selftype , name , value )
205
+
191
206
value = selftype .__dict__ [name ]
192
207
return value
193
208
@@ -198,10 +213,12 @@ def str____(self):
198
213
result: the resulting string representation
199
214
"""
200
215
result = ".{}"
216
+
201
217
if len (self .__dict__ ) <= 0 :
202
218
return result
203
219
204
220
result = ".{"
221
+
205
222
for key in self .__dict__ :
206
223
result += f"{ key .__str__ ()} : { self .__dict__ [key ].__str__ ()} , "
207
224
@@ -219,9 +236,14 @@ def todict____(self):
219
236
result: the result dict
220
237
"""
221
238
result = {}
239
+
222
240
for key in self .__dict__ :
223
241
value = self .__dict__ [key ]
242
+
224
243
if isinstance (value , DotDict ):
225
244
value = value .todict____ ()
245
+
226
246
result [key ] = value
247
+ # end for
248
+
227
249
return result
0 commit comments