From b98dada7f5fb8026d33d2743451e62af63240327 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 27 May 2020 12:07:25 +0200 Subject: [PATCH] dev-python/twisted: Fix 19.10.0 on py3.8 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- .../twisted/files/twisted-19.10.0-py38.patch | 110 ++++++++++++++++++ dev-python/twisted/twisted-19.10.0.ebuild | 8 +- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 dev-python/twisted/files/twisted-19.10.0-py38.patch diff --git a/dev-python/twisted/files/twisted-19.10.0-py38.patch b/dev-python/twisted/files/twisted-19.10.0-py38.patch new file mode 100644 index 000000000000..e787167d45b3 --- /dev/null +++ b/dev-python/twisted/files/twisted-19.10.0-py38.patch @@ -0,0 +1,110 @@ +From d33b90880b8eb024daa73bc3fd39aca0bc791ff1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lucas=20Treffenst=C3=A4dt?= +Date: Mon, 13 Jan 2020 13:54:08 +0100 +Subject: [PATCH 1/2] CramMD5ClientAuthenticator now specifies the digestmod + argument to hmac.HMAC constructor explicitly. + +--- + src/twisted/mail/_cred.py | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/twisted/mail/_cred.py b/src/twisted/mail/_cred.py +index 9d3646948..43c406f90 100644 +--- a/src/twisted/mail/_cred.py ++++ b/src/twisted/mail/_cred.py +@@ -8,6 +8,7 @@ Credential managers for L{twisted.mail}. + from __future__ import absolute_import, division + + import hmac ++import hashlib + + from zope.interface import implementer + +@@ -28,7 +29,7 @@ class CramMD5ClientAuthenticator: + + + def challengeResponse(self, secret, chal): +- response = hmac.HMAC(secret, chal).hexdigest().encode('ascii') ++ response = hmac.HMAC(secret, chal, digestmod = hashlib.md5).hexdigest().encode('ascii') + return self.user + b' ' + response + + +-- +2.26.2 + +From 694bc67f3cf7d36a6f512f0b76882e85d0966dd2 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Poisson?= +Date: Sun, 17 Nov 2019 19:48:53 +0100 +Subject: [PATCH 2/2] Fix parsing of namespaced attributes with Python 3.8 in + twisted.words.xish.domish.ExpatElementStream + +--- + src/twisted/words/newsfragments/9730.bugfix | 1 + + src/twisted/words/test/test_domish.py | 17 +++++++++++++++++ + src/twisted/words/xish/domish.py | 11 +++++++++-- + 3 files changed, 27 insertions(+), 2 deletions(-) + create mode 100644 src/twisted/words/newsfragments/9730.bugfix + +diff --git a/src/twisted/words/newsfragments/9730.bugfix b/src/twisted/words/newsfragments/9730.bugfix +new file mode 100644 +index 000000000..5c91305c8 +--- /dev/null ++++ b/src/twisted/words/newsfragments/9730.bugfix +@@ -0,0 +1 @@ ++Fixed parsing of streams with Python 3.8 when there are spaces in namespaces or namespaced attributes in twisted.words.xish.domish.ExpatElementStream +diff --git a/src/twisted/words/test/test_domish.py b/src/twisted/words/test/test_domish.py +index a8f8fa76b..cd16e3a4d 100644 +--- a/src/twisted/words/test/test_domish.py ++++ b/src/twisted/words/test/test_domish.py +@@ -350,6 +350,23 @@ class DomishStreamTestsMixin: + self.elements[0].attributes, {(" bar baz ", "baz"): "quux"}) + + ++ def test_attributesWithNamespaces(self): ++ """ ++ Attributes with namespace are parsed without Exception. ++ (https://twistedmatrix.com/trac/ticket/9730 regression test) ++ """ ++ ++ xml = b""" ++ test ++ """ ++ ++ # with Python 3.8 and without #9730 fix, the following error would ++ # happen at next line: ++ # ``RuntimeError: dictionary keys changed during iteration`` ++ self.stream.parse(xml) ++ self.assertEqual(self.elements[0].uri, "http://example.org") ++ ++ + def testChildPrefix(self): + xml = b"" + +diff --git a/src/twisted/words/xish/domish.py b/src/twisted/words/xish/domish.py +index 2063c410a..fc49285f5 100644 +--- a/src/twisted/words/xish/domish.py ++++ b/src/twisted/words/xish/domish.py +@@ -807,11 +807,18 @@ class ExpatElementStream: + qname = ('', name) + + # Process attributes ++ newAttrs = {} ++ toDelete = [] + for k, v in attrs.items(): + if " " in k: + aqname = k.rsplit(" ", 1) +- attrs[(aqname[0], aqname[1])] = v +- del attrs[k] ++ newAttrs[(aqname[0], aqname[1])] = v ++ toDelete.append(k) ++ ++ attrs.update(newAttrs) ++ ++ for k in toDelete: ++ del attrs[k] + + # Construct the new element + e = Element(qname, self.defaultNsStack[-1], attrs, self.localPrefixes) +-- +2.26.2 + diff --git a/dev-python/twisted/twisted-19.10.0.ebuild b/dev-python/twisted/twisted-19.10.0.ebuild index 53a20c32ca01..46a5d0dbc960 100644 --- a/dev-python/twisted/twisted-19.10.0.ebuild +++ b/dev-python/twisted/twisted-19.10.0.ebuild @@ -17,6 +17,7 @@ HOMEPAGE="https://www.twistedmatrix.com/trac/" SRC_URI="https://twistedmatrix.com/Releases/${TWISTED_PN}" SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2 https://dev.gentoo.org/~mgorny/dist/twisted-regen-cache.gz" +S=${WORKDIR}/${TWISTED_P} KEYWORDS="~alpha amd64 arm arm64 ~hppa ~ia64 ~mips ppc ppc64 s390 sparc x86 ~amd64-linux ~x86-linux" @@ -79,9 +80,14 @@ DEPEND=" ) " -S=${WORKDIR}/${TWISTED_P} python_prepare_all() { + local PATCHES=( + "${FILESDIR}"/${P}-py38.patch + "${FILESDIR}"/twisted-20.3.0-py38-cgi.patch + "${FILESDIR}"/twisted-20.3.0-py38-hmac.patch + ) + # upstream test for making releases; not very useful and requires # sphinx (including on py2) rm src/twisted/python/test/test_release.py || die -- 2.26.2