Browse Source

Use 'with' when opening wellknown_path

somecoder42 9 years ago
parent
commit
8d2b46519a
1 changed files with 2 additions and 3 deletions
  1. 2 3
      acme_tiny.py

+ 2 - 3
acme_tiny.py

@@ -113,9 +113,8 @@ def get_crt(account_key, csr, acme_dir):
         token = re.sub(r"[^A-Za-z0-9_\-]", "_", challenge['token'])
         keyauthorization = "{0}.{1}".format(token, thumbprint)
         wellknown_path = os.path.join(acme_dir, token)
-        wellknown_file = open(wellknown_path, "w")
-        wellknown_file.write(keyauthorization)
-        wellknown_file.close()
+        with open(wellknown_path, "w") as wellknown_file:
+            wellknown_file.write(keyauthorization)
 
         # check that the file is in place
         wellknown_url = "http://{0}/.well-known/acme-challenge/{1}".format(domain, token)