From 1a022c27bf7326665f956b710182f05f244b4f4d Mon Sep 17 00:00:00 2001 From: cclauss Date: Sat, 24 Aug 2019 10:58:58 +0200 Subject: [PATCH] tools: fix Python 3 issues in inspector_protocol PR-URL: https://github.com/nodejs/node/pull/29296 Reviewed-By: Jiawen Geng Reviewed-By: Trivikram Kamat --- .../inspector_protocol/convert_protocol_to_json.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/inspector_protocol/inspector_protocol/convert_protocol_to_json.py b/tools/inspector_protocol/inspector_protocol/convert_protocol_to_json.py index f98bebcd5e66c5..835e6387120bcc 100755 --- a/tools/inspector_protocol/inspector_protocol/convert_protocol_to_json.py +++ b/tools/inspector_protocol/inspector_protocol/convert_protocol_to_json.py @@ -21,14 +21,12 @@ def main(argv): parser.add_argument("json_file", help="The .json output file write.") args = parser.parse_args(argv) file_name = os.path.normpath(args.pdl_file) - input_file = open(file_name, "r") - pdl_string = input_file.read() + with open(file_name, "r") as input_file: + pdl_string = input_file.read() protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string) - input_file.close() - output_file = open(os.path.normpath(args.json_file), 'wb') - json.dump(protocol, output_file, indent=4, separators=(',', ': ')) - output_file.close() + with open(os.path.normpath(args.json_file), 'w') as output_file: + json.dump(protocol, output_file, indent=4, separators=(',', ': ')) if __name__ == '__main__':