Bring python2 subpackage back and fix weak dependencies

This commit is contained in:
Lumir Balhar 2020-04-17 08:30:31 +02:00
parent d7c591ffd9
commit 6e0db25373
3 changed files with 146 additions and 65 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

View File

@ -1,60 +0,0 @@
diff -Naur dnspython-1.16.0-orig/dns/tsigkeyring.py dnspython-1.16.0/dns/tsigkeyring.py
--- dnspython-1.16.0-orig/dns/tsigkeyring.py 2018-12-01 10:25:27.000000000 -0500
+++ dnspython-1.16.0/dns/tsigkeyring.py 2020-04-15 15:25:22.026211793 -0400
@@ -32,7 +32,7 @@
keyring = {}
for keytext in textring:
keyname = dns.name.from_text(keytext)
- secret = base64.decodestring(maybe_encode(textring[keytext]))
+ secret = base64.decodebytes(textring[keytext].encode())
keyring[keyname] = secret
return keyring
@@ -44,7 +44,8 @@
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 = base64.encodebytes(keyring[keyname]).decode().rstrip()
textring[keytext] = secret
return textring
diff -Naur dnspython-1.16.0-orig/tests/test_tsigkeyring.py dnspython-1.16.0/tests/test_tsigkeyring.py
--- dnspython-1.16.0-orig/tests/test_tsigkeyring.py 1969-12-31 19:00:00.000000000 -0500
+++ dnspython-1.16.0/tests/test_tsigkeyring.py 2020-04-15 15:26:16.884138201 -0400
@@ -0,0 +1,33 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+
+import base64
+import unittest
+
+import dns.tsigkeyring
+
+text_keyring = {
+ 'keyname.' : 'NjHwPsMKjdN++dOfE5iAiQ=='
+}
+
+rich_keyring = {
+ dns.name.from_text('keyname.') : \
+ base64.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)

View File

@ -1,12 +1,18 @@
%global pypi_name dnspython
%global py_package_name dns
# python2-dns exists because mailman and trac-spamfilter-plugin
# need it and both have fesco exception to stay in fedora for a while
# https://pagure.io/fesco/issue/2312
# https://pagure.io/fesco/issue/2266
%bcond_without python2
# Disable dependency generator until it has test code
%{?python_disable_dependency_generator}
Name: python-%{py_package_name}
Version: 1.16.0
Release: 9%{?dist}
Release: 10%{?dist}
Summary: DNS toolkit for Python
License: MIT
@ -22,12 +28,15 @@ BuildArch: noarch
Patch0: unicode_label_escapify.patch
Patch1: collections_abc.patch
Patch2: python-dns-1.16-base64.patch
Patch2: base64.patch
BuildRequires: python3-devel
BuildRequires: python3-setuptools
Recommends: python3-ecdsa
Recommends: python3-pycryptodomex
%if %{with python2}
BuildRequires: python2-devel
BuildRequires: python2-setuptools
%endif
%global _description %{expand:
dnspython is a DNS toolkit for Python. It supports almost all record
@ -43,11 +52,21 @@ manipulation of DNS zones, messages, names, and records.
%description %_description
%package -n python3-%{py_package_name}
Summary: %{summary}
BuildRequires: python3-devel
Recommends: python3-ecdsa
Recommends: python3-pycryptodomex
%{?python_provide:%python_provide python3-%{py_package_name}}
%description -n python3-%{py_package_name} %_description
%if %{with python2}
%package -n python2-%{py_package_name}
Summary: %{summary}
Recommends: python2-pycryptodomex
%{?python_provide:%python_provide python2-%{py_package_name}}
%description -n python2-%{py_package_name} %_description
%endif
%prep
%autosetup -p1 -n %{pypi_name}-%{version}
@ -56,12 +75,23 @@ find examples -type f | xargs chmod a-x
%build
%py3_build
%if %{with python2}
%py2_build
%endif
%install
%py3_install
%if %{with python2}
%py2_install
%endif
%check
%{python3} setup.py test
%if %{with python2}
cp %{SOURCE1} .
%{python2} setup.py test
rm typing.py{,?}
%endif
%files -n python3-%{py_package_name}
%license LICENSE
@ -69,7 +99,19 @@ find examples -type f | xargs chmod a-x
%{python3_sitelib}/%{py_package_name}
%{python3_sitelib}/%{pypi_name}-*.egg-info
%if %{with python2}
%files -n python2-%{py_package_name}
%license LICENSE
%doc README.md examples
%{python2_sitelib}/%{py_package_name}
%{python2_sitelib}/%{pypi_name}-*.egg-info
%endif
%changelog
* Fri Apr 17 2020 Lumír Balhar <lbalhar@redhat.com> - 1.16.0-10
- Bring python2 subpackage back
- Fix weak dependencies
* Wed Apr 15 2020 Paul Wouters <pwouters@redhat.com> - 1.16.0-9
- Remove python2 and "other_python3" support
- Resolves: rhbz#1802998 Make pycryptodomex and ecdsa weak dependencies of python-dns