diff --git a/letsencrypt/client/challenge_util.py b/letsencrypt/client/challenge_util.py index b5198217d..1338089ab 100644 --- a/letsencrypt/client/challenge_util.py +++ b/letsencrypt/client/challenge_util.py @@ -53,7 +53,7 @@ def dvsni_gen_cert(filepath, name, r_b64, nonce, key): cert_pem = crypto_util.make_ss_cert( key.pem, [nonce + CONFIG.INVALID_EXT, name, ext]) - with open(filepath, 'w') as chall_cert_file: + with open(filepath, "w") as chall_cert_file: chall_cert_file.write(cert_pem) return le_util.jose_b64encode(dvsni_s) @@ -69,7 +69,7 @@ def _dvsni_gen_ext(dvsni_r, dvsni_s): :rtype: str """ - z_base = hashlib.new('sha256') + z_base = hashlib.new("sha256") z_base.update(dvsni_r) z_base.update(dvsni_s) diff --git a/letsencrypt/client/crypto_util.py b/letsencrypt/client/crypto_util.py index 13d52c4fb..a2e4d27be 100644 --- a/letsencrypt/client/crypto_util.py +++ b/letsencrypt/client/crypto_util.py @@ -102,7 +102,7 @@ def make_csr(key_str, domains): extstack.push(ext) csr.add_extensions(extstack) - csr.sign(pubkey, 'sha256') + csr.sign(pubkey, "sha256") assert csr.verify(pubkey) pubkey2 = csr.get_pubkey() assert csr.verify(pubkey2) @@ -156,7 +156,7 @@ def make_key(bits): :rtype: str """ - return Crypto.PublicKey.RSA.generate(bits).exportKey(format='PEM') + return Crypto.PublicKey.RSA.generate(bits).exportKey(format="PEM") def valid_privkey(privkey): @@ -210,11 +210,11 @@ def make_ss_cert(key_str, domains, not_before=None, if len(domains) > 1: m2_cert.add_ext(M2Crypto.X509.new_extension( - 'basicConstraints', 'CA:FALSE')) + "basicConstraints", "CA:FALSE")) m2_cert.add_ext(M2Crypto.X509.new_extension( - 'subjectAltName', ", ".join(["DNS:%s" % d for d in domains]))) + "subjectAltName", ", ".join(["DNS:%s" % d for d in domains]))) - m2_cert.sign(pubkey, 'sha256') + m2_cert.sign(pubkey, "sha256") assert m2_cert.verify(pubkey) assert m2_cert.verify() # print check_purpose(,0 diff --git a/letsencrypt/client/display.py b/letsencrypt/client/display.py index 6d76cdfeb..7f2f67a21 100644 --- a/letsencrypt/client/display.py +++ b/letsencrypt/client/display.py @@ -85,8 +85,8 @@ class NcursesDisplay(object): """Display a Yes/No dialog box :param str message: message to display to user - :param str yes_label: label on the 'yes' button - :param str no_label: label on the 'no' button + :param str yes_label: label on the "yes" button + :param str no_label: label on the "no" button :returns: if yes_label was selected :rtype: bool @@ -139,7 +139,7 @@ class FileDisplay(object): :param str message: Message to display """ - side_frame = '-' * 79 + side_frame = "-" * 79 lines = message.splitlines() fixed_l = [] for line in lines: @@ -169,12 +169,12 @@ class FileDisplay(object): choices = ["%s - %s" % (c[0], c[1]) for c in choices] self.outfile.write("\n%s\n" % message) - side_frame = '-' * 79 + side_frame = "-" * 79 self.outfile.write("%s\n" % side_frame) for i, choice in enumerate(choices, 1): self.outfile.write(textwrap.fill( - "%d: %s" % (i, choice), 80) + '\n') + "%d: %s" % (i, choice), 80) + "\n") self.outfile.write("%s\n" % side_frame) @@ -197,7 +197,7 @@ class FileDisplay(object): """ ans = raw_input("%s (Enter c to cancel)\n" % message) - if ans == 'c' or ans == 'C': + if ans == "c" or ans == "C": return CANCEL, "-1" else: return OK, ans @@ -207,13 +207,13 @@ class FileDisplay(object): :param str message: question for the user - :returns: True for 'Yes', False for 'No" + :returns: True for "Yes", False for "No" :rtype: bool """ self.outfile.write("\n%s\n" % textwrap.fill(message, 80)) ans = raw_input("y/n: ") - return ans.startswith('y') or ans.startswith('Y') + return ans.startswith("y") or ans.startswith("Y") def filter_names(self, names): """Determine which names the user would like to select from a list. @@ -252,7 +252,7 @@ class FileDisplay(object): :returns: tuple of the form (code, selection) where code is a display exit code - selection is the user's int selection + selection is the user"s int selection :rtype: tuple """ @@ -261,7 +261,7 @@ class FileDisplay(object): while not valid_ans: ans = raw_input(input_string) - if ans.startswith('c') or ans.startswith('C'): + if ans.startswith("c") or ans.startswith("C"): code = CANCEL selection = -1 valid_ans = True diff --git a/letsencrypt/client/recovery_token.py b/letsencrypt/client/recovery_token.py index bf3bad6e1..2c328a46d 100644 --- a/letsencrypt/client/recovery_token.py +++ b/letsencrypt/client/recovery_token.py @@ -75,5 +75,5 @@ class RecoveryToken(object): """ le_util.make_or_verify_dir(self.token_dir, 0o700, os.geteuid()) - with open(os.path.join(self.token_dir, domain), 'w') as token_fd: + with open(os.path.join(self.token_dir, domain), "w") as token_fd: token_fd.write(str(token)) diff --git a/letsencrypt/client/revoker.py b/letsencrypt/client/revoker.py index 236533327..d16a4ee46 100644 --- a/letsencrypt/client/revoker.py +++ b/letsencrypt/client/revoker.py @@ -32,7 +32,7 @@ class Revoker(object): """ cert_der = M2Crypto.X509.load_cert(cert["backup_cert_file"]).as_der() - with open(cert["backup_key_file"], 'rU') as backup_key_file: + with open(cert["backup_key_file"], "rU") as backup_key_file: key = backup_key_file.read() revocation = self.network.send_and_receive_expected( @@ -59,7 +59,7 @@ class Revoker(object): csha1_vhlist = self._get_installed_locations() - with open(list_file, 'rb') as csvfile: + with open(list_file, "rb") as csvfile: csvreader = csv.reader(csvfile) # idx, orig_cert, orig_key for row in csvreader: @@ -96,7 +96,7 @@ class Revoker(object): for (cert_path, _, path) in self.installer.get_all_certs_keys(): try: cert_sha1 = M2Crypto.X509.load_cert( - cert_path).get_fingerprint(md='sha1') + cert_path).get_fingerprint(md="sha1") if cert_sha1 in csha1_vhlist: csha1_vhlist[cert_sha1].append(path) else: @@ -136,10 +136,10 @@ class Revoker(object): list_file = os.path.join(CONFIG.CERT_KEY_BACKUP, "LIST") list_file2 = os.path.join(CONFIG.CERT_KEY_BACKUP, "LIST.tmp") - with open(list_file, 'rb') as orgfile: + with open(list_file, "rb") as orgfile: csvreader = csv.reader(orgfile) - with open(list_file2, 'wb') as newfile: + with open(list_file2, "wb") as newfile: csvwriter = csv.writer(newfile) for row in csvreader: @@ -274,16 +274,16 @@ class Cert(object): status = DELETED_MSG else: o_cert = M2Crypto.X509.load_cert(orig) - if self.get_fingerprint() != o_cert.get_fingerprint(md='sha1'): + if self.get_fingerprint() != o_cert.get_fingerprint(md="sha1"): status = CHANGED_MSG # Verify original key path if not os.path.isfile(orig_key): key_status = DELETED_MSG else: - with open(orig_key, 'r') as fd: + with open(orig_key, "r") as fd: key_pem = fd.read() - with open(backup_key, 'r') as fd: + with open(backup_key, "r") as fd: backup_key_pem = fd.read() if key_pem != backup_key_pem: key_status = CHANGED_MSG @@ -307,7 +307,7 @@ class Cert(object): return self.cert.get_issuer().as_text() def get_fingerprint(self): - return self.cert.get_fingerprint(md='sha1') + return self.cert.get_fingerprint(md="sha1") def get_not_before(self): return self.cert.get_not_before().get_datetime() diff --git a/letsencrypt/client/tests/client_test.py b/letsencrypt/client/tests/client_test.py index 5961b227e..a7d4d1148 100644 --- a/letsencrypt/client/tests/client_test.py +++ b/letsencrypt/client/tests/client_test.py @@ -84,5 +84,5 @@ class RollbackTest(unittest.TestCase): self._call(1) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/letsencrypt/client/tests/recovery_token_test.py b/letsencrypt/client/tests/recovery_token_test.py index 44905789d..5c419da39 100644 --- a/letsencrypt/client/tests/recovery_token_test.py +++ b/letsencrypt/client/tests/recovery_token_test.py @@ -60,5 +60,5 @@ class RecoveryTokenTest(unittest.TestCase): self.assertTrue(response is None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/letsencrypt/scripts/main.py b/letsencrypt/scripts/main.py index ae623b640..4f78de968 100755 --- a/letsencrypt/scripts/main.py +++ b/letsencrypt/scripts/main.py @@ -134,7 +134,7 @@ def main(): # pylint: disable=too-many-statements,too-many-branches def display_eula(): """Displays the end user agreement.""" - with open('EULA') as eula_file: + with open("EULA") as eula_file: if not zope.component.getUtility(interfaces.IDisplay).yesno( eula_file.read(), "Agree", "Cancel"): sys.exit(0) @@ -190,7 +190,7 @@ def read_file(filename): """ try: - return filename, open(filename, 'rU').read() + return filename, open(filename, "rU").read() except IOError as exc: raise argparse.ArgumentTypeError(exc.strerror)