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)
| 105 | |
| 106 | |
| 107 | def 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 | |
| 129 | def main(): |
no test coverage detected