Reimplementation of the original RowConfigParser write function. This function is 99% same as its origin. The only change is removing a cast to str. This is needed to handle unicode chars.
(parser, ini_file)
| 277 | """ |
| 278 | |
| 279 | def write(parser, ini_file): |
| 280 | """ |
| 281 | Reimplementation of the original RowConfigParser write function. |
| 282 | |
| 283 | This function is 99% same as its origin. The only change is |
| 284 | removing a cast to str. This is needed to handle unicode chars. |
| 285 | """ |
| 286 | if parser._defaults: |
| 287 | ini_file.write("[DEFAULT]\n") |
| 288 | for (key, value) in parser._defaults.items(): |
| 289 | value_str = str(value).replace('\n', '\n\t') |
| 290 | ini_file.write(f"{key} = {value_str}\n") |
| 291 | ini_file.write("\n") |
| 292 | for section in parser._sections: |
| 293 | ini_file.write(f"[{section}]\n") |
| 294 | for (key, value) in parser._sections[section].items(): |
| 295 | if key == "__name__": |
| 296 | continue |
| 297 | if (value is not None) or (parser._optcre == parser.OPTCRE): |
| 298 | # The line below is the only changed line of the original function. |
| 299 | # This is the original line for reference: |
| 300 | # key = " = ".join((key, str(value).replace('\n', '\n\t'))) |
| 301 | key = " = ".join((key, value.replace('\n', '\n\t'))) |
| 302 | ini_file.write(f"{key}\n") |
| 303 | ini_file.write("\n") |
| 304 | |
| 305 | encoding = detect_encoding(path) or 'utf_8_sig' |
| 306 |