17
17
import types
18
18
import inspect
19
19
import logging
20
+ import collections
20
21
21
22
from _config_base import *
22
23
from springpython .context import scope
@@ -65,23 +66,12 @@ def read_object_defs(self):
65
66
# A dictionary of abstract objects, keyed by their IDs, used in
66
67
# traversing the hierarchies of parents; built upfront here for
67
68
# convenience.
68
- abstract_objects = {}
69
+ self . abstract_objects = {}
69
70
for object in doc ["objects" ]:
70
71
if "abstract" in object :
71
- abstract_objects [object ["object" ]] = object
72
+ self . abstract_objects [object ["object" ]] = object
72
73
73
74
for object in doc ["objects" ]:
74
- if not "class" in object and not "parent" in object :
75
- self ._map_custom_class (object , yaml_mappings )
76
-
77
- elif "parent" in object :
78
- # Children are added to self.objects during the children->abstract parents traversal.
79
- pos_constr = self ._get_pos_constr (object )
80
- named_constr = self ._get_named_constr (object )
81
- props = self ._get_props (object )
82
- self ._traverse_parents (object , object , pos_constr , named_constr , props , abstract_objects )
83
- continue
84
-
85
75
self ._print_obj (object )
86
76
self .objects .append (self ._convert_object (object ))
87
77
@@ -104,10 +94,10 @@ def _map_custom_class(self, obj, mappings):
104
94
else :
105
95
self .logger .warning ("No matching type found for object %s" % obj )
106
96
107
- def _traverse_parents (self , leaf , child , pos_constr ,
108
- named_constr , props , abstract_objects ):
97
+ def _convert_child_object (self , leaf , child , pos_constr ,
98
+ named_constr , props ):
109
99
110
- parent = abstract_objects [child ["parent" ]]
100
+ parent = self . abstract_objects [child ["parent" ]]
111
101
112
102
# At this point we only build up the lists of parameters but we don't create
113
103
# the object yet because the current parent object may still have its
@@ -147,20 +137,19 @@ def _traverse_parents(self, leaf, child, pos_constr,
147
137
props .append (parent_prop )
148
138
149
139
if "parent" in parent :
150
- self ._traverse_parents (leaf , parent , pos_constr , named_constr , props , abstract_objects )
140
+ # Continue traversing up the parent objects
141
+ return self ._convert_child_object (leaf , parent , pos_constr , named_constr , props )
151
142
else :
152
143
# Now we know we can create an object out of all the accumulated values.
153
-
144
+
154
145
# The object's class is its topmost parent's class.
155
146
class_ = parent ["class" ]
156
147
id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (leaf , class_ )
157
148
158
149
c = self ._create_object (id , factory , lazy_init , abstract , parent ,
159
150
scope_ , pos_constr , named_constr , props )
160
151
161
- self .objects .append (c )
162
-
163
- return parent
152
+ return c
164
153
165
154
def _get_pos_constr (self , object ):
166
155
""" Returns a list of all positional constructor arguments of an object.
@@ -224,20 +213,25 @@ def _convert_object(self, object, prefix=""):
224
213
object ["object" ] = prefix + "." + object ["object" ]
225
214
else :
226
215
object ["object" ] = prefix + ".<anonymous>"
227
-
228
- id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
229
-
216
+
217
+ if not "class" in object and "parent" not in object :
218
+ self ._map_custom_class (object , yaml_mappings )
219
+
230
220
pos_constr = self ._get_pos_constr (object )
231
221
named_constr = self ._get_named_constr (object )
232
222
props = self ._get_props (object )
223
+
224
+ if "parent" in object :
225
+ return self ._convert_child_object (object , object , pos_constr , named_constr , props )
226
+ else :
227
+ id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
233
228
234
- return self ._create_object (id , factory , lazy_init , abstract , parent ,
235
- scope_ , pos_constr , named_constr , props )
229
+ return self ._create_object (id , factory , lazy_init , abstract , parent ,
230
+ scope_ , pos_constr , named_constr , props )
236
231
237
232
def _print_obj (self , obj , level = 0 ):
238
233
self .logger .debug ("%sobject = %s" % ("\t " * level , obj ["object" ]))
239
- self .logger .debug ("%sobject id = %s" % ("\t " * level , obj ["object" ]))
240
- self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj ["class" ]))
234
+ self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj .get ("class" )))
241
235
242
236
if "scope" in obj :
243
237
self .logger .debug ("%sscope = %s" % ("\t " * (level + 1 ), obj ["scope" ]))
@@ -247,7 +241,7 @@ def _print_obj(self, obj, level=0):
247
241
if "properties" in obj :
248
242
self .logger .debug ("%sproperties:" % ("\t " * (level + 1 )))
249
243
for prop in obj ["properties" ].keys ():
250
- if "object" in obj ["properties" ][prop ]:
244
+ if isinstance ( obj [ "properties" ][ prop ], collections . Iterable ) and "object" in obj ["properties" ][prop ]:
251
245
self .logger .debug ("%s%s = ..." % ("\t " * (level + 2 ), prop ))
252
246
self ._print_obj (obj ["properties" ][prop ], level + 3 )
253
247
else :
@@ -398,10 +392,8 @@ def _convert_prop_def(self, comp, p, name):
398
392
return self ._convert_dict (p , comp ["object" ], name )
399
393
elif isinstance (p , list ):
400
394
return self ._convert_list (p , comp ["object" ], name )
401
- elif isinstance (p , unicode ):
402
- return ValueDef (name , unicode (p ))
403
395
else :
404
- return ValueDef (name , str ( p ) )
396
+ return ValueDef (name , p )
405
397
return None
406
398
407
399
if hasattr (p , "ref" ):
0 commit comments