mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-21 05:58:52 +02:00
Fix ElementTree imports for Python 3.9
Importing `cElementTree` has been deprecated since Python 3.3 - importing `ElementTree` automatically uses the fastest implementation available - and is finally removed in Python 3.9. Importing cElementTree directly (not as part of xml) is an even older relic, it's for Ye Time Before ElementTree Was Added To Python and it was instead an external module...which was before Python 2.5. We still need to work with Python 2.7 for now, so we use a try/ except to handle both 2.7 and 3.9 cases. Also, let's not repeat this import 12 times in one file for some reason. Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
@@ -3,7 +3,13 @@ import osc.oscerr
|
||||
import os
|
||||
import sys
|
||||
from common import GET, PUT, POST, DELETE, OscTestCase
|
||||
from xml.etree import cElementTree as ET
|
||||
try:
|
||||
# Works up to Python 3.8, needed for Python < 3.3 (inc 2.7)
|
||||
from xml.etree import cElementTree as ET
|
||||
except ImportError:
|
||||
# will import a fast implementation from 3.3 onwards, needed
|
||||
# for 3.9+
|
||||
from xml.etree import ElementTree as ET
|
||||
try:
|
||||
from urllib.error import HTTPError
|
||||
except ImportError:
|
||||
|
Reference in New Issue
Block a user