MCPcopy Create free account
hub / github.com/apache/madlib / construct_object

Method construct_object

src/madpack/yaml/constructor.py:53–102  ·  view source on GitHub ↗
(self, node, deep=False)

Source from the content-addressed store, hash-verified

51 return data
52
53 def construct_object(self, node, deep=False):
54 if deep:
55 old_deep = self.deep_construct
56 self.deep_construct = True
57 if node in self.constructed_objects:
58 return self.constructed_objects[node]
59 if node in self.recursive_objects:
60 raise ConstructorError(None, None,
61 "found unconstructable recursive node", node.start_mark)
62 self.recursive_objects[node] = None
63 constructor = None
64 state_constructor = None
65 tag_suffix = None
66 if node.tag in self.yaml_constructors:
67 constructor = self.yaml_constructors[node.tag]
68 else:
69 for tag_prefix in self.yaml_multi_constructors:
70 if node.tag.startswith(tag_prefix):
71 tag_suffix = node.tag[len(tag_prefix):]
72 constructor = self.yaml_multi_constructors[tag_prefix]
73 break
74 else:
75 if None in self.yaml_multi_constructors:
76 tag_suffix = node.tag
77 constructor = self.yaml_multi_constructors[None]
78 elif None in self.yaml_constructors:
79 constructor = self.yaml_constructors[None]
80 elif isinstance(node, ScalarNode):
81 constructor = self.__class__.construct_scalar
82 elif isinstance(node, SequenceNode):
83 constructor = self.__class__.construct_sequence
84 elif isinstance(node, MappingNode):
85 constructor = self.__class__.construct_mapping
86 if tag_suffix is None:
87 data = constructor(self, node)
88 else:
89 data = constructor(self, tag_suffix, node)
90 if isinstance(data, types.GeneratorType):
91 generator = data
92 data = generator.next()
93 if self.deep_construct:
94 for dummy in generator:
95 pass
96 else:
97 self.state_generators.append(generator)
98 self.constructed_objects[node] = data
99 del self.recursive_objects[node]
100 if deep:
101 self.deep_construct = old_deep
102 return data
103
104 def construct_scalar(self, node):
105 if not isinstance(node, ScalarNode):

Callers 6

construct_documentMethod · 0.95
construct_sequenceMethod · 0.95
construct_mappingMethod · 0.95
construct_pairsMethod · 0.95
construct_yaml_omapMethod · 0.80
construct_yaml_pairsMethod · 0.80

Calls 1

ConstructorErrorClass · 0.85

Tested by

no test coverage detected