From 64d4e6249c010b8fcf3a0a69ed5d83504d690640 Mon Sep 17 00:00:00 2001 From: Seth Schoen Date: Thu, 14 May 2015 17:01:04 -0700 Subject: [PATCH] Fix some PEP8 issues --- letsencrypt/notify.py | 1 + letsencrypt/renewer.py | 11 +++++++---- letsencrypt/storage.py | 10 ++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/letsencrypt/notify.py b/letsencrypt/notify.py index 6efb42d21..b4eec938f 100644 --- a/letsencrypt/notify.py +++ b/letsencrypt/notify.py @@ -5,6 +5,7 @@ import smtplib import socket import subprocess + def notify(subject, whom, what): """Try to notify the addressee (whom) by e-mail, with Subject: defined by subject and message body by what.""" diff --git a/letsencrypt/renewer.py b/letsencrypt/renewer.py index 40a6cfc74..0ded2baab 100644 --- a/letsencrypt/renewer.py +++ b/letsencrypt/renewer.py @@ -25,6 +25,7 @@ DEFAULTS["renewal_configs_dir"] = "/tmp/etc/letsencrypt/configs" DEFAULTS["official_archive_dir"] = "/tmp/etc/letsencrypt/archive" DEFAULTS["live_dir"] = "/tmp/etc/letsencrypt/live" + class AttrDict(dict): """A trick to allow accessing dictionary keys as object attributes.""" @@ -32,16 +33,17 @@ class AttrDict(dict): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = self + def renew(cert, old_version): """Perform automated renewal of the referenced cert, if possible.""" # TODO: handle partial success # TODO: handle obligatory key rotation vs. optional key rotation vs. # requested key rotation - if not cert.configfile.has_key("renewalparams"): + if "renewalparams" not in cert.configfile: # TODO: notify user? return False renewalparams = cert.configfile["renewalparams"] - if not renewalparams.has_key("authenticator"): + if "authenticator" not in renewalparams: # TODO: notify user? return False # Instantiate the appropriate authenticator @@ -74,13 +76,14 @@ def renew(cert, old_version): # new_key if the old key is to be used (since save_successor # already understands this distinction!) return cert.save_successor(old_version, new_cert, new_key, new_chain) - # TODO: Notify results + # TODO: Notify results else: - # TODO: Notify negative results + # TODO: Notify negative results return False # TODO: Consider the case where the renewal was partially successful # (where fewer than all names were renewed) + def main(config=DEFAULTS): """main function for autorenewer script.""" # TODO: Distinguish automated invocation from manual invocation, diff --git a/letsencrypt/storage.py b/letsencrypt/storage.py index 0e410319e..8a6c47768 100644 --- a/letsencrypt/storage.py +++ b/letsencrypt/storage.py @@ -21,6 +21,7 @@ DEFAULTS["official_archive_dir"] = "/tmp/etc/letsencrypt/archive" DEFAULTS["live_dir"] = "/tmp/etc/letsencrypt/live" ALL_FOUR = ("cert", "privkey", "chain", "fullchain") + def parse_time_interval(interval, textparser=parsedatetime.Calendar()): """Parse the time specified time interval, which can be in the English-language format understood by parsedatetime, e.g., '10 days', @@ -33,6 +34,7 @@ def parse_time_interval(interval, textparser=parsedatetime.Calendar()): return datetime.timedelta(0, time.mktime(textparser.parse( interval, time.localtime(0))[0])) + class RenewableCert(object): # pylint: disable=too-many-instance-attributes """Represents a lineage of certificates that is under the management of the Let's Encrypt client, indicated by the existence of an @@ -55,7 +57,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes self.configuration = copy.deepcopy(defaults) self.configuration.merge(self.configfile) - if not all(self.configuration.has_key(x) for x in ALL_FOUR): + if not all(x in self.configuration for x in ALL_FOUR): raise ValueError("renewal config file {0} is missing a required " "file reference".format(configfile)) @@ -244,7 +246,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes pem) i = method(x509) return pyrfc3339.parse(i[0:4] + "-" + i[4:6] + "-" + i[6:8] + "T" + - i[8:10] + ":" + i[10:12] +":" +i[12:]) + i[8:10] + ":" + i[10:12] + ":" + i[12:]) def notbefore(self, version=None): """When is the beginning validity time of the specified version of the @@ -264,7 +266,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes autodeployment is enabled, whether a relevant newer version exists, and whether the time interval for autodeployment has been reached.)""" - if (not self.configuration.has_key("autodeploy") or + if ("autodeploy" not in self.configuration or self.configuration.as_bool("autodeploy")): if self.has_pending_deployment(): interval = self.configuration.get("deploy_before_expiry", @@ -291,7 +293,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes def should_autorenew(self): """Should an attempt be made to automatically renew the most recent certificate in this certificate lineage right now?""" - if (not self.configuration.has_key("autorenew") + if ("autorenew" not in self.configuration or self.configuration.as_bool("autorenew")): # Consider whether to attempt to autorenew this cert now # XXX: both self.ocsp_revoked() and self.notafter() are bugs