From daecc226ee5d0b7e16b9a2c7fccf63aeecb8f000 Mon Sep 17 00:00:00 2001 From: Igor Ponomarev Date: Thu, 2 Jun 2022 21:18:44 +0300 Subject: [PATCH] tools: Fix generate-docs-nm-settings-docs-gir.py on Python 2 On python2 the following error is raised: `LookupError: unknown encoding: unicode` Seems like `unicode` is a correct encoding in Python 3 but not 2. Fix: 1. Change encoding to `utf-8` 2. Pass output path string instead of opening file and passing opened file object. Python2 and 3 might need different file modes, passing just path lets ElementTree select appropriate file mode. Fixes: f00e90923c8c ('tools: Use ElementTree to write XML in generate-docs-nm-settings-docs-gir.py') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1249 --- tools/generate-docs-nm-settings-docs-gir.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/generate-docs-nm-settings-docs-gir.py b/tools/generate-docs-nm-settings-docs-gir.py index a40234efbe..75d5d013a9 100755 --- a/tools/generate-docs-nm-settings-docs-gir.py +++ b/tools/generate-docs-nm-settings-docs-gir.py @@ -267,12 +267,11 @@ def main(gir_path_str, output_path_str): attrib=property_attributes, ) - with open(output_path_str, mode="w") as outfile: - docs_gir.write( - outfile, - encoding="unicode", - xml_declaration=True, - ) + docs_gir.write( + output_path_str, + xml_declaration=True, + encoding="utf-8", + ) if __name__ == "__main__":