]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extract dns.rcode compatibility code to isctest.compat
authorMichal Nowak <mnowak@isc.org>
Tue, 27 Aug 2024 18:14:00 +0000 (20:14 +0200)
committerMichal Nowak <mnowak@isc.org>
Thu, 12 Sep 2024 09:42:22 +0000 (11:42 +0200)
bin/tests/system/isctest/check.py
bin/tests/system/isctest/compat.py [new file with mode: 0644]
bin/tests/system/isctest/query.py
bin/tests/system/isctest/run.py
bin/tests/system/rpzextra/tests_rpzextra.py

index 28eb16d5dd42af1c00eedd58c71dca99b159255b..251e87e4f37c72bde6e8f55b104cc43b4f5533c4 100644 (file)
 # information regarding copyright ownership.
 
 import shutil
-from typing import Any, Optional
+from typing import Optional
 
 import dns.rcode
 import dns.message
 import dns.zone
 
 import isctest.log
-
-# compatiblity with dnspython<2.0.0
-try:
-    # In dnspython>=2.0.0, dns.rcode.Rcode class is available
-    # pylint: disable=invalid-name
-    dns_rcode = dns.rcode.Rcode  # type: Any
-except AttributeError:
-    # In dnspython<2.0.0, selected rcodes are available as integers directly
-    # from dns.rcode
-    dns_rcode = dns.rcode
+from isctest.compat import dns_rcode
 
 
 def rcode(message: dns.message.Message, expected_rcode) -> None:
diff --git a/bin/tests/system/isctest/compat.py b/bin/tests/system/isctest/compat.py
new file mode 100644 (file)
index 0000000..5580f1f
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from typing import Any
+
+import dns.rcode
+
+# compatiblity with dnspython<2.0.0
+try:
+    # In dnspython>=2.0.0, dns.rcode.Rcode class is available
+    # pylint: disable=invalid-name
+    dns_rcode = dns.rcode.Rcode  # type: Any
+except AttributeError:
+    # In dnspython<2.0.0, selected rcodes are available as integers directly
+    # from dns.rcode
+    dns_rcode = dns.rcode
index c001e063d109d6f6f0ac9ab45f7788ff0ec13385..3e5ed8b78b01aaaee48dd27a14eb950b905cbc6c 100644 (file)
@@ -17,16 +17,7 @@ import dns.query
 import dns.message
 
 import isctest.log
-
-# compatiblity with dnspython<2.0.0
-try:
-    # In dnspython>=2.0.0, dns.rcode.Rcode class is available
-    # pylint: disable=invalid-name
-    dns_rcode = dns.rcode.Rcode  # type: Any
-except AttributeError:
-    # In dnspython<2.0.0, selected rcodes are available as integers directly
-    # from dns.rcode
-    dns_rcode = dns.rcode
+from isctest.compat import dns_rcode
 
 QUERY_TIMEOUT = 10
 
index 60703749ce0ff9637493f6dda1bb8202249efc7f..b3cb8200c069713c34dfc8c946b6d6ee1a96795b 100644 (file)
 import os
 import subprocess
 import time
-from typing import Any, Optional
+from typing import Optional
 
 import isctest.log
+from isctest.compat import dns_rcode
 
 import dns.message
 
 
-# compatiblity with dnspython<2.0.0
-try:
-    # In dnspython>=2.0.0, dns.rcode.Rcode class is available
-    # pylint: disable=invalid-name
-    dns_rcode = dns.rcode.Rcode  # type: Any
-except AttributeError:
-    # In dnspython<2.0.0, selected rcodes are available as integers directly
-    # from dns.rcode
-    dns_rcode = dns.rcode
-
-
 def cmd(  # pylint: disable=too-many-arguments
     args,
     cwd=None,
index 5c2740ad637cacf997827c9d5dba88ac1c7af4d3..bf2fe94c6b4d6d25121d92589da583cd939c9a10 100644 (file)
@@ -16,21 +16,11 @@ import pytest
 
 pytest.importorskip("dns", minversion="2.0.0")
 import isctest
+from isctest.compat import dns_rcode
 
 import dns.message
 
 
-# compatiblity with dnspython<2.0.0
-try:
-    # In dnspython>=2.0.0, dns.rcode.Rcode class is available
-    # pylint: disable=invalid-name
-    dns_rcode = dns.rcode.Rcode  # type: Any
-except AttributeError:
-    # In dnspython<2.0.0, selected rcodes are available as integers directly
-    # from dns.rcode
-    dns_rcode = dns.rcode
-
-
 @pytest.mark.parametrize(
     "qname,source,rcode",
     [