Add USE_ASYNC flag to allow async to be disabled when aiodns is

installed (LP: #1954331) - see README.md for details
This commit is contained in:
Scott Kitterman
2023-02-25 16:25:20 -05:00
parent 50a81ab8d6
commit 233a9699ed
3 changed files with 21 additions and 8 deletions
+16 -8
View File
@@ -40,6 +40,9 @@ import sys
import time
import binascii
# Set to False to not use async functions even though aiodns is installed.
USE_ASYNC = True
# only needed for arc
try:
from authres import AuthenticationResultsHeader
@@ -72,13 +75,17 @@ from dkim.crypto import (
try:
from dkim.dnsplug import get_txt
except ImportError:
try:
import aiodns
from dkim.asyncsupport import get_txt_async as get_txt
except:
# Only true if not using async
def get_txt(s,timeout=5):
raise RuntimeError("DKIM.verify requires DNS or dnspython module")
if USE_ASYNC:
try:
import aiodns
from dkim.asyncsupport import get_txt_async as get_txt
except:
# Only true if not using async
def get_txt(s,timeout=5):
raise RuntimeError("DKIM.verify requires DNS or dnspython module")
else:
raise RuntimeError("DKIM.verify requires DNS or dnspython module")
from dkim.util import (
get_default_logger,
InvalidTagValueList,
@@ -94,6 +101,7 @@ __all__ = [
"ValidationError",
"AuthresNotFoundError",
"NaClNotFoundError",
"USE_ASYNC",
"CV_Pass",
"CV_Fail",
"CV_None",
@@ -1369,7 +1377,7 @@ def verify(message, logger=None, dnsfunc=get_txt, minkey=1024,
# aiodns requires Python 3.5+, so no async before that
if sys.version_info >= (3, 5):
if sys.version_info >= (3, 5) and USE_ASYNC:
try:
import aiodns
from dkim.asyncsupport import verify_async