From 72ec7e8319fbca0111e0eee0533ad8c82be54f0c Mon Sep 17 00:00:00 2001 From: Adrien Ferrand Date: Mon, 3 Jan 2022 23:17:14 +0100 Subject: [PATCH] Finish complete typing --- acme/acme/client.py | 13 +++++++------ acme/tests/fields_test.py | 4 ++-- .../certbot_compatibility_test/test_driver.py | 2 +- certbot/certbot/_internal/auth_handler.py | 14 +++++++------- certbot/certbot/plugins/dns_test_common_lexicon.py | 1 - 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/acme/acme/client.py b/acme/acme/client.py index ad0798a34..7e87e7474 100644 --- a/acme/acme/client.py +++ b/acme/acme/client.py @@ -34,6 +34,7 @@ from requests.adapters import HTTPAdapter from requests.utils import parse_header_links from requests_toolbelt.adapters.source import SourceAddressAdapter +from acme import challenges from acme import crypto_util from acme import errors from acme import jws @@ -161,8 +162,8 @@ class ClientBase: raise errors.UnexpectedUpdate(authzr) return authzr - def answer_challenge(self, challb: messages.ChallengeBody, response: requests.Response - ) -> messages.ChallengeResource: + def answer_challenge(self, challb: messages.ChallengeBody, + response: challenges.ChallengeResponse) -> messages.ChallengeResource: """Answer challenge. :param challb: Challenge Resource body. @@ -177,15 +178,15 @@ class ClientBase: :raises .UnexpectedUpdate: """ - response = self._post(challb.uri, response) + resp = self._post(challb.uri, response) try: - authzr_uri = response.links['up']['url'] + authzr_uri = resp.links['up']['url'] except KeyError: raise errors.ClientError('"up" Link header missing') challr = messages.ChallengeResource( authzr_uri=authzr_uri, - body=messages.ChallengeBody.from_json(response.json())) - # TODO: check that challr.uri == response.headers['Location']? + body=messages.ChallengeBody.from_json(resp.json())) + # TODO: check that challr.uri == resp.headers['Location']? if challr.uri != challb.uri: raise errors.UnexpectedUpdate(challr.uri) return challr diff --git a/acme/tests/fields_test.py b/acme/tests/fields_test.py index 69dde8b89..4cc167f9c 100644 --- a/acme/tests/fields_test.py +++ b/acme/tests/fields_test.py @@ -10,8 +10,8 @@ class FixedTest(unittest.TestCase): """Tests for acme.fields.Fixed.""" def setUp(self): - from acme.fields import Fixed - self.field = Fixed('name', 'x') + from acme.fields import fixed + self.field = fixed('name', 'x') def test_decode(self): self.assertEqual('x', self.field.decode('x')) diff --git a/certbot-compatibility-test/certbot_compatibility_test/test_driver.py b/certbot-compatibility-test/certbot_compatibility_test/test_driver.py index 1b27a2195..26b7660ab 100644 --- a/certbot-compatibility-test/certbot_compatibility_test/test_driver.py +++ b/certbot-compatibility-test/certbot_compatibility_test/test_driver.py @@ -106,7 +106,7 @@ def test_authenticator(plugin: common.Proxy, config: str, temp_dir: str) -> bool def _create_achalls(plugin: common.Proxy) -> List[achallenges.AnnotatedChallenge]: """Returns a list of annotated challenges to test on plugin""" - achalls = [] + achalls: List[achallenges.AnnotatedChallenge] = [] names = plugin.get_testable_domain_names() for domain in names: prefs = plugin.get_chall_pref(domain) diff --git a/certbot/certbot/_internal/auth_handler.py b/certbot/certbot/_internal/auth_handler.py index 019a7470b..e9e7d064f 100644 --- a/certbot/certbot/_internal/auth_handler.py +++ b/certbot/certbot/_internal/auth_handler.py @@ -2,7 +2,7 @@ import datetime import logging import time -from typing import Dict +from typing import Dict, Sequence from typing import Iterable from typing import List from typing import Optional @@ -272,7 +272,7 @@ class AuthHandler: self.auth.cleanup(achalls) def _challenge_factory(self, authzr: messages.AuthorizationResource, - path: List[int]) -> List[achallenges.AnnotatedChallenge]: + path: Sequence[int]) -> List[achallenges.AnnotatedChallenge]: """Construct Namedtuple Challenges :param messages.AuthorizationResource authzr: authorization @@ -350,7 +350,7 @@ def challb_to_achall(challb: messages.ChallengeBody, account_key: josepy.JWK, def gen_challenge_path(challbs: List[messages.ChallengeBody], preferences: List[Type[challenges.Challenge]], - combinations: Tuple[Tuple[int, ...], ...]) -> List[int]: + combinations: Tuple[Tuple[int, ...], ...]) -> Tuple[int, ...]: """Generate a plan to get authority over the identity. .. todo:: This can be possibly be rewritten to use resolved_combinations. @@ -384,7 +384,7 @@ def gen_challenge_path(challbs: List[messages.ChallengeBody], def _find_smart_path(challbs: List[messages.ChallengeBody], preferences: List[Type[challenges.Challenge]], combinations: Tuple[Tuple[int, ...], ...] - ) -> List[int]: + ) -> Tuple[int, ...]: """Find challenge path with server hints. Can be called if combinations is included. Function uses a simple @@ -418,11 +418,11 @@ def _find_smart_path(challbs: List[messages.ChallengeBody], if not best_combo: raise _report_no_chall_path(challbs) - return [item for item in best_combo] + return best_combo def _find_dumb_path(challbs: List[messages.ChallengeBody], - preferences: List[Type[challenges.Challenge]]) -> List[int]: + preferences: List[Type[challenges.Challenge]]) -> Tuple[int, ...]: """Find challenge path without server hints. Should be called if the combinations hint is not included by the @@ -440,7 +440,7 @@ def _find_dumb_path(challbs: List[messages.ChallengeBody], else: raise _report_no_chall_path(challbs) - return path + return tuple(path) def _report_no_chall_path(challbs: List[messages.ChallengeBody]) -> errors.AuthorizationError: diff --git a/certbot/certbot/plugins/dns_test_common_lexicon.py b/certbot/certbot/plugins/dns_test_common_lexicon.py index 76c25881d..7d844d133 100644 --- a/certbot/certbot/plugins/dns_test_common_lexicon.py +++ b/certbot/certbot/plugins/dns_test_common_lexicon.py @@ -7,7 +7,6 @@ import josepy as jose from requests.exceptions import HTTPError from requests.exceptions import RequestException -from acme.challenges import Challenge from certbot import errors from certbot.achallenges import AnnotatedChallenge from certbot.plugins import dns_test_common