diff --git a/base64.patch b/base64.patch new file mode 100644 index 0000000..9d295a9 --- /dev/null +++ b/base64.patch @@ -0,0 +1,99 @@ +From f36ac6022a2a3d5b067387908aa31932234a31e1 Mon Sep 17 00:00:00 2001 +From: Lumir Balhar +Date: Fri, 17 Apr 2020 08:01:22 +0200 +Subject: [PATCH] Backwards compatibility for base64 module + +--- + dns/tsigkeyring.py | 16 ++++++++++++---- + tests/test_tsigkeyring.py | 39 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 51 insertions(+), 4 deletions(-) + create mode 100644 tests/test_tsigkeyring.py + +diff --git a/dns/tsigkeyring.py b/dns/tsigkeyring.py +index 5e5fe1c..1dab2aa 100644 +--- a/dns/tsigkeyring.py ++++ b/dns/tsigkeyring.py +@@ -19,7 +19,14 @@ + + from dns._compat import maybe_decode, maybe_encode + +-import base64 ++ ++try: ++ # New in version 3.1 ++ from base64 import decodebytes, encodebytes ++except ImportError: ++ # Deprecated since version 3.1 and removed since 3.9 ++ from base64 import decodestring as decodebytes ++ from base64 import encodestring as encodebytes + + import dns.name + +@@ -32,7 +39,7 @@ def from_text(textring): + keyring = {} + for keytext in textring: + keyname = dns.name.from_text(keytext) +- secret = base64.decodestring(maybe_encode(textring[keytext])) ++ secret = decodebytes(textring[keytext].encode()) + keyring[keyname] = secret + return keyring + +@@ -44,7 +51,8 @@ def to_text(keyring): + + textring = {} + for keyname in keyring: +- keytext = maybe_decode(keyname.to_text()) +- secret = maybe_decode(base64.encodestring(keyring[keyname])) ++ keytext = keyname.to_text() ++ # rstrip to get rid of the \n encoding adds ++ secret = encodebytes(keyring[keyname]).decode().rstrip() + textring[keytext] = secret + return textring +diff --git a/tests/test_tsigkeyring.py b/tests/test_tsigkeyring.py +new file mode 100644 +index 0000000..17177c0 +--- /dev/null ++++ b/tests/test_tsigkeyring.py +@@ -0,0 +1,39 @@ ++# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license ++ ++try: ++ # New in version 3.1 ++ from base64 import decodebytes ++except ImportError: ++ # Deprecated since version 3.1 and removed since 3.9 ++ from base64 import decodestring as decodebytes ++ ++import unittest ++ ++import dns.tsigkeyring ++ ++text_keyring = { ++ 'keyname.' : 'NjHwPsMKjdN++dOfE5iAiQ==' ++} ++ ++rich_keyring = { ++ dns.name.from_text('keyname.') : \ ++ decodebytes('NjHwPsMKjdN++dOfE5iAiQ=='.encode()) ++} ++ ++class TSIGKeyRingTestCase(unittest.TestCase): ++ ++ def test_from_text(self): ++ """text keyring -> rich keyring""" ++ rkeyring = dns.tsigkeyring.from_text(text_keyring) ++ self.assertEqual(rkeyring, rich_keyring) ++ ++ def test_to_text(self): ++ """text keyring -> rich keyring -> text keyring""" ++ tkeyring = dns.tsigkeyring.to_text(rich_keyring) ++ self.assertEqual(tkeyring, text_keyring) ++ ++ def test_from_and_to_text(self): ++ """text keyring -> rich keyring -> text keyring""" ++ rkeyring = dns.tsigkeyring.from_text(text_keyring) ++ tkeyring = dns.tsigkeyring.to_text(rkeyring) ++ self.assertEqual(tkeyring, text_keyring) +-- +2.25.2 + diff --git a/collections_abc.patch b/collections_abc.patch new file mode 100644 index 0000000..7d247ba --- /dev/null +++ b/collections_abc.patch @@ -0,0 +1,22 @@ +diff -ru dnspython-1.16.0-orig/dns/namedict.py dnspython-1.16.0/dns/namedict.py +--- dnspython-1.16.0-orig/dns/namedict.py 2018-12-01 10:25:27.000000000 -0500 ++++ dnspython-1.16.0/dns/namedict.py 2020-01-21 19:48:57.266576401 -0500 +@@ -27,12 +27,16 @@ + + """DNS name dictionary""" + +-import collections + import dns.name + from ._compat import xrange + ++try: ++ from collections.abc import MutableMapping ++except ImportError: ++ from collections import MutableMapping + +-class NameDict(collections.MutableMapping): ++ ++class NameDict(MutableMapping): + """A dictionary whose keys are dns.name.Name objects. + + In addition to being like a regular Python dictionary, this diff --git a/dnspython-1.16.0.tar.gz b/dnspython-1.16.0.tar.gz new file mode 100644 index 0000000..ddcb639 Binary files /dev/null and b/dnspython-1.16.0.tar.gz differ diff --git a/dnspython-2.1.0.tar.gz b/dnspython-2.1.0.tar.gz deleted file mode 100644 index 3991c89..0000000 Binary files a/dnspython-2.1.0.tar.gz and /dev/null differ diff --git a/fix-failed-tests.patch b/fix-failed-tests.patch index 17ca075..6f976a6 100644 --- a/fix-failed-tests.patch +++ b/fix-failed-tests.patch @@ -22,42 +22,8 @@ index 1738c1a..1e0c727 100644 - _network_available = False +_network_available = False - # Some tests use a "nano nameserver" for testing. It requires trio - # and threading, so try to import it and if it doesn't work, skip -diff -ruNa dnspython-2.1.0-org/tests/test_async.py dnspython-2.1.0/tests/test_async.py ---- dnspython-2.1.0-org/tests/test_async.py 2021-07-07 10:04:01.861405149 +0800 -+++ dnspython-2.1.0/tests/test_async.py 2021-07-07 10:04:59.981489084 +0800 -@@ -41,12 +41,8 @@ - - # Some tests require the internet to be available to run, so let's - # skip those if it's not there. --_network_available = True --try: -- socket.gethostbyname('dnspython.org') --except socket.gaierror: -- _network_available = False - -+_network_available = False - - # Probe for IPv4 and IPv6 - query_addresses = [] -diff -ruNa dnspython-2.1.0-org/tests/test_query.py dnspython-2.1.0/tests/test_query.py ---- dnspython-2.1.0-org/tests/test_query.py 2021-07-07 10:04:01.861405149 +0800 -+++ dnspython-2.1.0/tests/test_query.py 2021-07-07 10:05:44.431553273 +0800 -@@ -38,11 +38,8 @@ - - # Some tests require the internet to be available to run, so let's - # skip those if it's not there. --_network_available = True --try: -- socket.gethostbyname('dnspython.org') --except socket.gaierror: -- _network_available = False -+ -+_network_available = False - - # Some tests use a "nano nameserver" for testing. It requires trio - # and threading, so try to import it and if it doesn't work, skip + resolv_conf = u""" + /t/t -- 1.8.3.1 diff --git a/python-dns.spec b/python-dns.spec index 6009950..8358a44 100644 --- a/python-dns.spec +++ b/python-dns.spec @@ -13,18 +13,19 @@ messages, names, and records. Name: python-dns Summary: %{sum} -Version: 2.1.0 -Release: 1 -License: ISC and MIT +Version: 1.16.0 +Release: 3 +License: MIT URL: http://www.dnspython.org/ -Source0: https://github.com/rthalley/dnspython/archive/v%{version}/dnspython-%{version}.tar.gz - -Patch0: fix-failed-tests.patch +Source0: http://www.dnspython.org/kits/%{version}/dnspython-%{version}.tar.gz BuildArch: noarch +Patch0: unicode_label_escapify.patch +Patch1: collections_abc.patch +Patch2: base64.patch +Patch3: fix-failed-tests.patch BuildRequires: python3-devel python3-setuptools python3-pycryptodome python3-ecdsa -BuildRequires: python3-pytest %description %{_description} @@ -50,7 +51,7 @@ find examples -type f | xargs chmod a-x %py3_install %check -pytest +%{__python3} setup.py test %files -n python3-dns %doc LICENSE @@ -61,9 +62,6 @@ pytest %doc examples %changelog -* Wed Jul 07 2021 gaihuiying - 2.1.0-1 -- update to 2.1.0 - * Tue Nov 17 2020 jinzhimin - 1.16.0-3 - fix tests failed diff --git a/unicode_label_escapify.patch b/unicode_label_escapify.patch new file mode 100644 index 0000000..58e5aa8 --- /dev/null +++ b/unicode_label_escapify.patch @@ -0,0 +1,110 @@ +diff -ru dnspython-1.16.0-orig/dns/name.py dnspython-1.16.0/dns/name.py +--- dnspython-1.16.0-orig/dns/name.py 2018-12-05 08:35:40.000000000 -0500 ++++ dnspython-1.16.0/dns/name.py 2020-01-22 01:07:53.319289996 -0500 +@@ -195,16 +195,10 @@ + self.allow_pure_ascii = allow_pure_ascii + self.strict_decode = strict_decode + +- def is_all_ascii(self, label): +- for c in label: +- if ord(c) > 0x7f: +- return False +- return True +- + def encode(self, label): + if label == '': + return b'' +- if self.allow_pure_ascii and self.is_all_ascii(label): ++ if self.allow_pure_ascii and is_all_ascii(label): + return label.encode('ascii') + if not have_idna_2008: + raise NoIDNA2008 +@@ -230,6 +224,7 @@ + raise IDNAException(idna_exception=e) + + _escaped = bytearray(b'"().;\\@$') ++_escaped_text = u'"().;\\@$' + + IDNA_2003_Practical = IDNA2003Codec(False) + IDNA_2003_Strict = IDNA2003Codec(True) +@@ -263,7 +258,9 @@ + if isinstance(label, binary_type): + label = label.decode() + for c in label: +- if c > u'\x20' and c < u'\x7f': ++ if c in _escaped_text: ++ text += u'\\' + c ++ elif c > u'\x20' and c < u'\x7f': + text += c + else: + if c >= u'\x7f': +@@ -827,7 +824,7 @@ + if text == u'@': + text = u'' + if text: +- if text == u'.': ++ if text in [u'.', u'\u3002', u'\uff0e', u'\uff61']: + return Name([b'']) # no Unicode "u" on this constant! + for c in text: + if escaping: +@@ -870,6 +867,13 @@ + return Name(labels) + + ++def is_all_ascii(text): ++ for c in text: ++ if ord(c) > 0x7f: ++ return False ++ return True ++ ++ + def from_text(text, origin=root, idna_codec=None): + """Convert text into a Name object. + +@@ -886,7 +890,18 @@ + """ + + if isinstance(text, text_type): +- return from_unicode(text, origin, idna_codec) ++ if not is_all_ascii(text): ++ # Some codepoint in the input text is > 127, so IDNA applies. ++ return from_unicode(text, origin, idna_codec) ++ # The input is all ASCII, so treat this like an ordinary non-IDNA ++ # domain name. Note that "all ASCII" is about the input text, ++ # not the codepoints in the domain name. E.g. if text has value ++ # ++ # r'\150\151\152\153\154\155\156\157\158\159' ++ # ++ # then it's still "all ASCII" even though the domain name has ++ # codepoints > 127. ++ text = text.encode('ascii') + if not isinstance(text, binary_type): + raise ValueError("input to from_text() must be a string") + if not (origin is None or isinstance(origin, Name)): +diff -ru dnspython-1.16.0-orig/tests/test_name.py dnspython-1.16.0/tests/test_name.py +--- dnspython-1.16.0-orig/tests/test_name.py 2018-12-01 10:48:40.000000000 -0500 ++++ dnspython-1.16.0/tests/test_name.py 2020-01-21 23:19:07.998492185 -0500 +@@ -255,6 +255,23 @@ + t = dns.name.root.to_unicode() + self.assertEqual(t, '.') + ++ def testToText12(self): ++ n = dns.name.from_text(r'a\.b.c') ++ t = n.to_unicode() ++ self.assertEqual(t, r'a\.b.c.') ++ ++ def testToText13(self): ++ n = dns.name.from_text(r'\150\151\152\153\154\155\156\157\158\159.') ++ t = n.to_text() ++ self.assertEqual(t, r'\150\151\152\153\154\155\156\157\158\159.') ++ ++ def testToText14(self): ++ # You can't send this to_unicode() as it wasn't unicode to begin with. ++ def bad(): ++ n = dns.name.from_text(r'\150\151\152\153\154\155\156\157\158\159.') ++ t = n.to_unicode() ++ self.failUnlessRaises(UnicodeDecodeError, bad) ++ + def testSlice1(self): + n = dns.name.from_text(r'a.b.c.', origin=None) + s = n[:]