1# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2# 3# SPDX-License-Identifier: MPL-2.0 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, you can obtain one at https://mozilla.org/MPL/2.0/. 8# 9# See the COPYRIGHT file distributed with this work for additional 10# information regarding copyright ownership. 11 12from typing import Any 13 14import dns.rcode 15import dns.message 16 17 18# compatiblity with dnspython<2.0.0 19try: 20 # In dnspython>=2.0.0, dns.rcode.Rcode class is available 21 # pylint: disable=invalid-name 22 dns_rcode = dns.rcode.Rcode # type: Any 23except AttributeError: 24 # In dnspython<2.0.0, selected rcodes are available as integers directly 25 # from dns.rcode 26 dns_rcode = dns.rcode 27 28 29def rcode(message: dns.message.Message, expected_rcode) -> None: 30 assert message.rcode() == expected_rcode, str(message) 31 32 33def noerror(message: dns.message.Message) -> None: 34 rcode(message, dns_rcode.NOERROR) 35