From 34fca1529a0837d5e99c07fa496da833ef4fbd77 Mon Sep 17 00:00:00 2001 From: rozgonik Date: Sun, 15 Mar 2020 17:35:46 +0100 Subject: [PATCH] Refactor the disguised counting loop in check_authorization_status method --- sewer/client.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sewer/client.py b/sewer/client.py index eced5dfc..ed7d0dc2 100644 --- a/sewer/client.py +++ b/sewer/client.py @@ -463,15 +463,13 @@ def check_authorization_status(self, authorization_url, desired_status=None): """ self.logger.info("check_authorization_status") desired_status = desired_status or ["pending", "valid"] - number_of_checks = 0 - while True: + for _ in range(self.ACME_AUTH_STATUS_MAX_CHECKS): time.sleep(self.ACME_AUTH_STATUS_WAIT_PERIOD) headers = {"User-Agent": self.User_Agent} check_authorization_status_response = requests.get( authorization_url, timeout=self.ACME_REQUEST_TIMEOUT, headers=headers ) authorization_status = check_authorization_status_response.json()["status"] - number_of_checks = number_of_checks + 1 self.logger.debug( "check_authorization_status_response. status_code={0}. response={1}".format( check_authorization_status_response.status_code, @@ -480,14 +478,12 @@ def check_authorization_status(self, authorization_url, desired_status=None): ) if authorization_status in desired_status: break - if number_of_checks == self.ACME_AUTH_STATUS_MAX_CHECKS: - raise StopIteration( - "Checks done={0}. Max checks allowed={1}. Interval between checks={2}seconds.".format( - number_of_checks, - self.ACME_AUTH_STATUS_MAX_CHECKS, - self.ACME_AUTH_STATUS_WAIT_PERIOD, - ) + else: + raise StopIteration( + "Checks done={0}. Max checks allowed={0}. Interval between checks={1}seconds.".format( + self.ACME_AUTH_STATUS_MAX_CHECKS, self.ACME_AUTH_STATUS_WAIT_PERIOD ) + ) self.logger.info("check_authorization_status_success") return check_authorization_status_response