MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / convert_stream

Function convert_stream

convert_v3_to_v4.py:107–126  ·  view source on GitHub ↗

Converts the behavior tree V3 xml from in_file to V4, and writes to out_file. Args: in_stream (typing.TextIO): The input file stream. out_stream (typing.TextIO): The output file stream.

(in_stream: typing.TextIO, out_stream: typing.TextIO)

Source from the content-addressed store, hash-verified

105
106
107def convert_stream(in_stream: typing.TextIO, out_stream: typing.TextIO):
108 """Converts the behavior tree V3 xml from in_file to V4, and writes to out_file.
109 Args:
110 in_stream (typing.TextIO): The input file stream.
111 out_stream (typing.TextIO): The output file stream.
112 """
113
114 class CommentedTreeBuilder(ET.TreeBuilder):
115 """Class for preserving comments in xml
116 see: https://stackoverflow.com/a/34324359/17094594
117 """
118
119 def comment(self, text):
120 self.start(ET.Comment, {})
121 self.data(text)
122 self.end(ET.Comment)
123
124 element_tree = ET.parse(in_stream, ET.XMLParser(target=CommentedTreeBuilder()))
125 convert_all_nodes(element_tree.getroot())
126 element_tree.write(out_stream, encoding="unicode", xml_declaration=True)
127
128
129def main():

Callers 1

mainFunction · 0.85

Calls 4

convert_all_nodesFunction · 0.85
parseMethod · 0.80
XMLParserMethod · 0.45

Tested by

no test coverage detected