代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/python-dns 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。