diff options
Diffstat (limited to 'Tools/scripts/get-remote-certificate.py')
-rwxr-xr-x | Tools/scripts/get-remote-certificate.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Tools/scripts/get-remote-certificate.py b/Tools/scripts/get-remote-certificate.py index 5811f20..3890128 100755 --- a/Tools/scripts/get-remote-certificate.py +++ b/Tools/scripts/get-remote-certificate.py @@ -29,9 +29,8 @@ def fetch_server_certificate (host, port): return None else: tn = tempfile.mktemp() - fp = open(tn, "wb") - fp.write(m.group(1) + b"\n") - fp.close() + with open(tn, "wb") as fp: + fp.write(m.group(1) + b"\n") try: tn2 = (outfile or tempfile.mktemp()) status, output = subproc(r'openssl x509 -in "%s" -out "%s"' % @@ -39,9 +38,8 @@ def fetch_server_certificate (host, port): if status != 0: raise RuntimeError('OpenSSL x509 failed with status %s and ' 'output: %r' % (status, output)) - fp = open(tn2, 'rb') - data = fp.read() - fp.close() + with open(tn2, 'rb') as fp: + data = fp.read() os.unlink(tn2) return data finally: @@ -49,9 +47,8 @@ def fetch_server_certificate (host, port): if sys.platform.startswith("win"): tfile = tempfile.mktemp() - fp = open(tfile, "w") - fp.write("quit\n") - fp.close() + with open(tfile, "w") as fp: + fp.write("quit\n") try: status, output = subproc( 'openssl s_client -connect "%s:%s" -showcerts < "%s"' % |