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: f00e90923c ('tools: Use ElementTree to write XML in generate-docs-nm-settings-docs-gir.py')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1249
This commit is contained in:
Igor Ponomarev
2022-06-02 21:18:44 +03:00
committed by Thomas Haller
parent 68e9f92a81
commit daecc226ee

View File

@@ -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__":