]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Do all httpx imports before setting _have_httpx.
authorBob Halley <halley@dnspython.org>
Sat, 15 Jul 2023 15:26:21 +0000 (08:26 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 15 Jul 2023 15:27:53 +0000 (08:27 -0700)
This gives us the expected test skipping when httpx isn't available
or is too old, vs. the test failures that were happening before
this change.

(cherry picked from commit 71a90fc934ef190e6a371f14e136a5a34e27849a)

dns/query.py

index d49688ddac28376875cddd663978d6bf541a9698..bd8388af418541d580ee6f68ec267de014605ca7 100644 (file)
@@ -60,8 +60,13 @@ def _expiration_for_this_attempt(timeout, expiration):
 _have_httpx = False
 _have_http2 = False
 try:
+    import httpcore
+    import httpcore._backends.sync
     import httpx
 
+    _CoreNetworkBackend = httpcore.NetworkBackend
+    _CoreSyncStream = httpcore._backends.sync.SyncStream
+
     _have_httpx = True
     try:
         # See if http2 support is available.
@@ -70,12 +75,6 @@ try:
     except Exception:
         pass
 
-    import httpcore
-    import httpcore._backends.sync
-
-    _CoreNetworkBackend = httpcore.NetworkBackend
-    _CoreSyncStream = httpcore._backends.sync.SyncStream
-
     class _NetworkBackend(_CoreNetworkBackend):
         def __init__(self, resolver, local_port, bootstrap_address, family):
             super().__init__()