1 Star 0 Fork 26

kkz/python-dns

forked from src-openEuler/python-dns 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
base64.patch 3.01 KB
一键复制 编辑 原始数据 按行查看 历史
王玺源 提交于 2021-07-13 08:05 . Revert "update to 2.1.0"
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kkzhs_admin/python-dns.git
git@gitee.com:kkzhs_admin/python-dns.git
kkzhs_admin
python-dns
python-dns
master

搜索帮助