|
1 | 1 | """
|
2 |
| -Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. |
3 | 3 | Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
4 | 4 |
|
5 | 5 | This model provider translation classes that convert between JSON and Python Dictionaries.
|
@@ -170,13 +170,34 @@ def _write_dictionary_to_json_file(self, dictionary, writer, indent=''):
|
170 | 170 | writer.write(indent + '"' + _quote_embedded_quotes(key) + '" : ')
|
171 | 171 | if isinstance(value, dict):
|
172 | 172 | self._write_dictionary_to_json_file(value, writer, indent)
|
| 173 | + elif isinstance(value, list): |
| 174 | + self._write_list_to_json_file(value, writer, indent) |
173 | 175 | else:
|
174 | 176 | writer.write(_format_json_value(value))
|
175 | 177 | writer.println()
|
176 | 178 | writer.write(end_indent + _end_dict)
|
177 | 179 |
|
178 | 180 | return
|
179 | 181 |
|
| 182 | + def _write_list_to_json_file(self, alist, writer, indent=''): |
| 183 | + """ |
| 184 | + Write the python list in json syntax using the provided writer stream. |
| 185 | + :param alist: python list to convert to json syntax |
| 186 | + :param writer: where to write the list into json syntax |
| 187 | + :param indent: current string indention of the json syntax. If not provided, indent is an empty string |
| 188 | + """ |
| 189 | + writer.write('[') |
| 190 | + end_line = '' |
| 191 | + list_indent = indent + self._indent_unit |
| 192 | + for value in alist: |
| 193 | + writer.write(end_line) |
| 194 | + writer.println() |
| 195 | + writer.write(list_indent) |
| 196 | + writer.write(_format_json_value(value)) |
| 197 | + end_line = ',' |
| 198 | + writer.println() |
| 199 | + writer.write(indent + ']') |
| 200 | + |
180 | 201 | def _close_streams(self, fos, writer):
|
181 | 202 | """
|
182 | 203 | Close the correct output stream.
|
|
0 commit comments