|
|
2131388 |
From f58bdd01487af85f669abcb15d3b0dc72b6b976c Mon Sep 17 00:00:00 2001
|
|
|
2131388 |
From: Adam Williamson <awilliam@redhat.com>
|
|
|
2131388 |
Date: Tue, 2 Jun 2020 13:22:17 -0700
|
|
|
2131388 |
Subject: [PATCH] Fix and standardize ElementTree imports for Python 3.9
|
|
|
2131388 |
|
|
|
2131388 |
Importing `cElementTree` has been deprecated since Python 3.3 -
|
|
|
2131388 |
importing `ElementTree` automatically uses the fastest
|
|
|
2131388 |
implementation available - and is finally removed in Python 3.9.
|
|
|
2131388 |
Importing cElementTree directly (not as part of xml) is an even
|
|
|
2131388 |
older relic, it's for Ye Time Before ElementTree Was Added To
|
|
|
2131388 |
Python and it was instead an external module...which was before
|
|
|
2131388 |
Python 2.5. So let's just standardize on importing ElementTree
|
|
|
2131388 |
from xml.etree. Also, let's not repeat this import 12 times in
|
|
|
2131388 |
one file for some reason.
|
|
|
2131388 |
|
|
|
2131388 |
Signed-off-by: Adam Williamson <awilliam@redhat.com>
|
|
|
2131388 |
---
|
|
|
2131388 |
README | 4 ----
|
|
|
2131388 |
osc/build.py | 5 +----
|
|
|
2131388 |
osc/core.py | 7 ++-----
|
|
|
2131388 |
osc/util/repodata.py | 6 +-----
|
|
|
2131388 |
tests/common.py | 2 +-
|
|
|
2131388 |
tests/test_commit.py | 2 +-
|
|
|
2131388 |
tests/test_repairwc.py | 2 +-
|
|
|
2131388 |
tests/test_request.py | 15 ++-------------
|
|
|
2131388 |
8 files changed, 9 insertions(+), 34 deletions(-)
|
|
|
2131388 |
|
|
|
2131388 |
diff --git a/README b/README
|
|
|
2131388 |
index 9aa4c70d..7b77c7d7 100644
|
|
|
2131388 |
--- a/README
|
|
|
2131388 |
+++ b/README
|
|
|
2131388 |
@@ -24,10 +24,6 @@ Alternatively, you can directly use osc-wrapper.py from the source dir
|
|
|
2131388 |
(which is easier if you develop on osc).
|
|
|
2131388 |
|
|
|
2131388 |
|
|
|
2131388 |
-The program needs the cElementTree python module installed. On SUSE, the
|
|
|
2131388 |
-respective package is called python-elementtree (before 10.2: python-xml).
|
|
|
2131388 |
-
|
|
|
2131388 |
-
|
|
|
2131388 |
|
|
|
2131388 |
CONFIGURATION:
|
|
|
2131388 |
|
|
|
2131388 |
diff --git a/osc/build.py b/osc/build.py
|
|
|
2131388 |
index 14d54564..5f26b001 100644
|
|
|
2131388 |
--- a/osc/build.py
|
|
|
2131388 |
+++ b/osc/build.py
|
|
|
2131388 |
@@ -27,10 +27,7 @@ from osc.util.helper import decode_it
|
|
|
2131388 |
import osc.conf
|
|
|
2131388 |
from . import oscerr
|
|
|
2131388 |
import subprocess
|
|
|
2131388 |
-try:
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
-except ImportError:
|
|
|
2131388 |
- import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
|
|
|
2131388 |
from .conf import config, cookiejar
|
|
|
2131388 |
|
|
|
2131388 |
diff --git a/osc/core.py b/osc/core.py
|
|
|
2131388 |
index e0cbe8a4..1fd33cee 100644
|
|
|
2131388 |
--- a/osc/core.py
|
|
|
2131388 |
+++ b/osc/core.py
|
|
|
2131388 |
@@ -48,10 +48,7 @@ except ImportError:
|
|
|
2131388 |
from httplib import IncompleteRead
|
|
|
2131388 |
|
|
|
2131388 |
|
|
|
2131388 |
-try:
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
-except ImportError:
|
|
|
2131388 |
- import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
|
|
|
2131388 |
from . import oscerr
|
|
|
2131388 |
from . import conf
|
|
|
2131388 |
@@ -816,7 +813,7 @@ class Project:
|
|
|
2131388 |
|
|
|
2131388 |
def read_packages(self):
|
|
|
2131388 |
"""
|
|
|
2131388 |
- Returns an ``xml.etree.cElementTree`` object representing the
|
|
|
2131388 |
+ Returns an ``xml.etree.ElementTree`` object representing the
|
|
|
2131388 |
parsed contents of the project's ``.osc/_packages`` XML file.
|
|
|
2131388 |
"""
|
|
|
2131388 |
global store
|
|
|
2131388 |
diff --git a/osc/util/repodata.py b/osc/util/repodata.py
|
|
|
2131388 |
index ac46455a..09ce1339 100644
|
|
|
2131388 |
--- a/osc/util/repodata.py
|
|
|
2131388 |
+++ b/osc/util/repodata.py
|
|
|
2131388 |
@@ -5,11 +5,7 @@ information instead of scanning individual rpms."""
|
|
|
2131388 |
import gzip
|
|
|
2131388 |
import os.path
|
|
|
2131388 |
|
|
|
2131388 |
-# cElementTree can be standard or 3rd-party depending on python version
|
|
|
2131388 |
-try:
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
-except ImportError:
|
|
|
2131388 |
- import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
|
|
|
2131388 |
# project modules
|
|
|
2131388 |
import osc.util.rpmquery
|
|
|
2131388 |
diff --git a/tests/common.py b/tests/common.py
|
|
|
2131388 |
index 211cc63f..d0c2cb17 100644
|
|
|
2131388 |
--- a/tests/common.py
|
|
|
2131388 |
+++ b/tests/common.py
|
|
|
2131388 |
@@ -4,7 +4,7 @@ import shutil
|
|
|
2131388 |
import tempfile
|
|
|
2131388 |
import os
|
|
|
2131388 |
import sys
|
|
|
2131388 |
-from xml.etree import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
EXPECTED_REQUESTS = []
|
|
|
2131388 |
|
|
|
2131388 |
if sys.version_info[0:2] in ((2, 6), (2, 7)):
|
|
|
2131388 |
diff --git a/tests/test_commit.py b/tests/test_commit.py
|
|
|
2131388 |
index 3eb27406..4fe11967 100644
|
|
|
2131388 |
--- a/tests/test_commit.py
|
|
|
2131388 |
+++ b/tests/test_commit.py
|
|
|
2131388 |
@@ -3,7 +3,7 @@ import osc.oscerr
|
|
|
2131388 |
import os
|
|
|
2131388 |
import sys
|
|
|
2131388 |
from common import GET, PUT, POST, DELETE, OscTestCase
|
|
|
2131388 |
-from xml.etree import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
try:
|
|
|
2131388 |
from urllib.error import HTTPError
|
|
|
2131388 |
except ImportError:
|
|
|
2131388 |
diff --git a/tests/test_repairwc.py b/tests/test_repairwc.py
|
|
|
2131388 |
index f2b090b8..267bc371 100644
|
|
|
2131388 |
--- a/tests/test_repairwc.py
|
|
|
2131388 |
+++ b/tests/test_repairwc.py
|
|
|
2131388 |
@@ -3,7 +3,7 @@ import osc.oscerr
|
|
|
2131388 |
import os
|
|
|
2131388 |
import sys
|
|
|
2131388 |
from common import GET, PUT, POST, DELETE, OscTestCase
|
|
|
2131388 |
-from xml.etree import cElementTree as ET
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
FIXTURES_DIR = os.path.join(os.getcwd(), 'repairwc_fixtures')
|
|
|
2131388 |
|
|
|
2131388 |
def suite():
|
|
|
2131388 |
diff --git a/tests/test_request.py b/tests/test_request.py
|
|
|
2131388 |
index 96b5ba40..90d2441e 100644
|
|
|
2131388 |
--- a/tests/test_request.py
|
|
|
2131388 |
+++ b/tests/test_request.py
|
|
|
2131388 |
@@ -1,3 +1,5 @@
|
|
|
2131388 |
+from xml.etree import ElementTree as ET
|
|
|
2131388 |
+
|
|
|
2131388 |
import osc.core
|
|
|
2131388 |
import osc.oscerr
|
|
|
2131388 |
import os
|
|
|
2131388 |
@@ -252,7 +254,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_action_from_xml1(self):
|
|
|
2131388 |
"""create action from xml"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """<action type="add_role">
|
|
|
2131388 |
<target package="bar" project="foo" />
|
|
|
2131388 |
<person name="user" role="reader" />
|
|
|
2131388 |
@@ -270,7 +271,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_action_from_xml2(self):
|
|
|
2131388 |
"""create action from xml"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """<action type="submit">
|
|
|
2131388 |
<source package="bar" project="foo" />
|
|
|
2131388 |
<target package="bar" project="foobar" />
|
|
|
2131388 |
@@ -292,7 +292,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_action_from_xml3(self):
|
|
|
2131388 |
"""create action from xml (with acceptinfo element)"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """<action type="submit">
|
|
|
2131388 |
<source package="bar" project="testprj" />
|
|
|
2131388 |
<target package="baz" project="foobar" />
|
|
|
2131388 |
@@ -316,13 +315,11 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_action_from_xml_unknown_type(self):
|
|
|
2131388 |
"""try to create action from xml with unknown type"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = '<action type="foo"><source package="bar" project="foo" /></action>'
|
|
|
2131388 |
self.assertRaises(osc.oscerr.WrongArgs, osc.core.Action.from_xml, ET.fromstring(xml))
|
|
|
2131388 |
|
|
|
2131388 |
def test_read_request1(self):
|
|
|
2131388 |
"""read in a request"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml'), 'r').read().strip()
|
|
|
2131388 |
r = osc.core.Request()
|
|
|
2131388 |
r.read(ET.fromstring(xml))
|
|
|
2131388 |
@@ -354,7 +351,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_read_request2(self):
|
|
|
2131388 |
"""read in a request (with reviews)"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml'), 'r').read().strip()
|
|
|
2131388 |
r = osc.core.Request()
|
|
|
2131388 |
r.read(ET.fromstring(xml))
|
|
|
2131388 |
@@ -393,7 +389,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_read_request3(self):
|
|
|
2131388 |
"""read in a request (with an "empty" comment+description)"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """<request creator="xyz" id="2">
|
|
|
2131388 |
<action type="set_bugowner">
|
|
|
2131388 |
<target project="foo" />
|
|
|
2131388 |
@@ -430,7 +425,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_request_list_view1(self):
|
|
|
2131388 |
"""test the list_view method"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
|
|
|
2131388 |
exp = """\
|
|
|
2131388 |
62 State:new By:Admin When:2010-12-29T14:57:25
|
|
|
2131388 |
@@ -448,7 +442,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
|
|
|
2131388 |
def test_request_list_view2(self):
|
|
|
2131388 |
"""test the list_view method (with history elements and description)"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml'), 'r').read().strip()
|
|
|
2131388 |
r = osc.core.Request()
|
|
|
2131388 |
r.read(ET.fromstring(xml))
|
|
|
2131388 |
@@ -462,7 +455,6 @@ class TestRequest(OscTestCase):
|
|
|
2131388 |
self.assertEqual(exp, r.list_view())
|
|
|
2131388 |
|
|
|
2131388 |
def test_request_str1(self):
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
"""test the __str__ method"""
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml'), 'r').read().strip()
|
|
|
2131388 |
r = osc.core.Request()
|
|
|
2131388 |
@@ -496,7 +488,6 @@ History: 2010-12-12T00:00:00 creator revoked
|
|
|
2131388 |
|
|
|
2131388 |
def test_request_str2(self):
|
|
|
2131388 |
"""test the __str__ method"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """\
|
|
|
2131388 |
<request creator="creator" id="98765">
|
|
|
2131388 |
<action type="change_devel">
|
|
|
2131388 |
@@ -527,7 +518,6 @@ Comment: <no comment>"""
|
|
|
2131388 |
|
|
|
2131388 |
def test_legacy_request(self):
|
|
|
2131388 |
"""load old-style submitrequest"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = """\
|
|
|
2131388 |
<request creator="olduser" id="1234" type="submit">
|
|
|
2131388 |
<submit>
|
|
|
2131388 |
@@ -563,7 +553,6 @@ Comment: <no comment>"""
|
|
|
2131388 |
|
|
|
2131388 |
def test_get_actions(self):
|
|
|
2131388 |
"""test get_actions method"""
|
|
|
2131388 |
- from xml.etree import cElementTree as ET
|
|
|
2131388 |
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
|
|
|
2131388 |
r = osc.core.Request()
|
|
|
2131388 |
r.read(ET.fromstring(xml))
|
|
|
2131388 |
--
|
|
|
2131388 |
2.26.2
|
|
|
2131388 |
|