From 1565a3b0017b3a97086278c539256bfd14c50943 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Tue, 1 Dec 2020 10:45:29 -0500 Subject: Fix crash when dnspython is not available If we don't have dnspython, then we don't have _resolver. Make sure it exists and check if it's not None before looking for hasattr. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/b4/__init__.py b/b4/__init__.py index b10b3e1..7cffe47 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -36,6 +36,7 @@ try: _resolver = dns.resolver.get_default_resolver() except ModuleNotFoundError: can_dkim_verify = False + _resolver = None __VERSION__ = '0.6.0-dev' @@ -1698,7 +1699,7 @@ class LoreAttestationSignatureDKIM(LoreAttestationSignature): ddata = get_parts_from_header(dks) self.attestor = LoreAttestorDKIM(ddata['d']) # Do we have a resolve method? - if hasattr(_resolver, 'resolve'): + if _resolver and hasattr(_resolver, 'resolve'): res = dkim.verify(self.msg.as_bytes(), dnsfunc=dkim_get_txt) else: res = dkim.verify(self.msg.as_bytes()) -- cgit v1.2.3