From e91a3d73ad39385eb2eef3fc86072b308ce8f489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 23 Jun 2020 11:31:32 +0200 Subject: [PATCH] Remove lxml deprecated methods All our supported runtimes [1] are compatible with the recommended alternatives. The `getchildren` method is deprecated [2] since lxml 2.0 and will be removed in future versions, these changes switch usages to `list(elem)` as recommended in the official documentation [2]. [1] https://governance.openstack.org/tc/reference/runtimes/victoria.html#python-runtimes-for-train [2] https://lxml.de/api/lxml.etree._Element-class.html#getchildren Change-Id: I5264edb93532d90703ae7b59cd71520a2cd3518a --- swift/common/middleware/s3api/etree.py | 2 +- test/functional/s3api/test_versioning.py | 4 ++-- test/unit/common/middleware/s3api/test_versioning.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/swift/common/middleware/s3api/etree.py b/swift/common/middleware/s3api/etree.py index 29adbc38ed..987b84a144 100644 --- a/swift/common/middleware/s3api/etree.py +++ b/swift/common/middleware/s3api/etree.py @@ -92,7 +92,7 @@ def tostring(tree, use_s3ns=True, xml_declaration=True): root = Element(tree.tag, attrib=tree.attrib, nsmap=nsmap) root.text = tree.text - root.extend(deepcopy(tree.getchildren())) + root.extend(deepcopy(list(tree))) tree = root return lxml.etree.tostring(tree, xml_declaration=xml_declaration, diff --git a/test/functional/s3api/test_versioning.py b/test/functional/s3api/test_versioning.py index bbbb72a70b..bd80a95809 100644 --- a/test/functional/s3api/test_versioning.py +++ b/test/functional/s3api/test_versioning.py @@ -58,7 +58,7 @@ class TestS3ApiVersioning(S3ApiBase): 'GET', 'bucket', query='versioning') self.assertEqual(status, 200) elem = fromstring(body) - self.assertEqual(elem.getchildren(), []) + self.assertEqual(list(elem), []) # Enable versioning elem = Element('VersioningConfiguration') @@ -108,7 +108,7 @@ class TestS3ApiVersioning(S3ApiBase): 'GET', 'bucket', query='versioning') self.assertEqual(status, 200) elem = fromstring(body) - self.assertEqual(elem.getchildren(), []) + self.assertEqual(list(elem), []) # Suspend versioning elem = Element('VersioningConfiguration') diff --git a/test/unit/common/middleware/s3api/test_versioning.py b/test/unit/common/middleware/s3api/test_versioning.py index 33acd82b3c..ed485b9133 100644 --- a/test/unit/common/middleware/s3api/test_versioning.py +++ b/test/unit/common/middleware/s3api/test_versioning.py @@ -42,7 +42,7 @@ class TestS3ApiVersioning(S3ApiTestCase): status, headers, body = self._versioning_GET(path) self.assertEqual(status.split()[0], '200') elem = fromstring(body, 'VersioningConfiguration') - self.assertEqual(elem.getchildren(), []) + self.assertEqual(list(elem), []) def _versioning_GET_enabled(self, path): self.swift.register('HEAD', '/v1/AUTH_test/bucket', HTTPNoContent, {