diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-01-10 13:07:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 13:07:19 (GMT) |
commit | b3d2427f2280fa8dae3515036c518d74ba43ebd1 (patch) | |
tree | e9fda1fdaf580c57ca6bda8c0d7e7bfc965f91d5 /Tools/ssl/make_ssl_data.py | |
parent | a8629816c6c0e6770248a60529fd7c9ba08aad55 (diff) | |
download | cpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.zip cpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.tar.gz cpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.tar.bz2 |
gh-58032: Do not use argparse.FileType in module CLIs and scripts (GH-113649)
Open and close files manually. It prevents from leaking files,
preliminary creation of output files, and accidental closing of stdin
and stdout.
Diffstat (limited to 'Tools/ssl/make_ssl_data.py')
-rwxr-xr-x | Tools/ssl/make_ssl_data.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Tools/ssl/make_ssl_data.py b/Tools/ssl/make_ssl_data.py index ab1134e..9860871 100755 --- a/Tools/ssl/make_ssl_data.py +++ b/Tools/ssl/make_ssl_data.py @@ -23,7 +23,7 @@ parser = argparse.ArgumentParser( ) parser.add_argument("srcdir", help="OpenSSL source directory") parser.add_argument( - "output", nargs="?", type=argparse.FileType("w"), default=sys.stdout + "output", nargs="?", default=None ) @@ -126,8 +126,13 @@ def main(): lines.append("") lines.extend(gen_error_codes(args)) - for line in lines: - args.output.write(line + "\n") + if args.output is None: + for line in lines: + print(line) + else: + with open(args.output, 'w') as output: + for line in lines: + print(line, file=output) if __name__ == "__main__": |