bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)

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 @@
             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 @@
                 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 @@
 
     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"' %