update to 1.16.0

This commit is contained in:
jinzhimin369 2020-11-10 14:24:04 +08:00
parent 354fb814d3
commit ef75dd2b7d
7 changed files with 245 additions and 22 deletions

99
base64.patch Normal file
View File

@ -0,0 +1,99 @@
From f36ac6022a2a3d5b067387908aa31932234a31e1 Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar@redhat.com>
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

22
collections_abc.patch Normal file
View File

@ -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

Binary file not shown.

BIN
dnspython-1.16.0.tar.gz Normal file

Binary file not shown.

View File

@ -13,17 +13,18 @@ messages, names, and records.
Name: python-dns
Summary: %{sum}
Version: 1.15.0
Release: 11
Version: 1.16.0
Release: 1
License: MIT
URL: http://www.dnspython.org/
Source0: http://www.dnspython.org/kits/%{version}/dnspython-%{version}.tar.gz
Patch0: test_fails_on_missing_file.patch
BuildRequires: python3-devel python3-setuptools python3-crypto
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
BuildRequires: python3-devel python3-setuptools python3-pycryptodome python3-ecdsa
%description
%{_description}
@ -31,7 +32,7 @@ BuildArch: noarch
%package -n python3-dns
Summary: %{sum}
%{?python_provide:%python_provide python3-dns}
Requires: python3-crypto
Requires: python3-pycryptodome python3-ecdsa
%description -n python3-dns
%{_description}
@ -57,11 +58,14 @@ find examples -type f | xargs chmod a-x
%{python3_sitelib}/dns
%files help
%doc ChangeLog examples
%doc examples
%changelog
* Tue Nov 10 2020 jinzhimin<jinzhimin2@huawei.com> - 1.16.0-1
* update to 1.16.0
* Wed Oct 21 2020 jinzhimin<jinzhimin2@huawei.com> - 1.15.0-11
* remove python2-dns subpackage
* Fri Dec 6 2019 caomeng<caomeng5@huawei.com> - 1.15.0-10
- Package init
- Package init

View File

@ -1,12 +0,0 @@
diff -ruN /home/avram/Desktop/dnspython-1.15.0.orig/tests/test_zone.py /home/avram/Desktop/dnspython-1.15.0/tests/test_zone.py
--- a/tests/test_zone.py 2016-09-20 12:24:02.000000000 -0400
+++ b/tests/test_zone.py 2016-10-04 07:59:39.717946790 -0400
@@ -177,7 +177,7 @@
def testToFileFilename(self):
z = dns.zone.from_file(here('example'), 'example')
try:
- z.to_file('example3-filename.out')
+ z.to_file(here('example3-filename.out'))
ok = filecmp.cmp(here('example3-filename.out'),
here('example3.good'))
finally:

View File

@ -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[:]