Skip to content

Commit 6cfe8c5

Browse files
committed
Remove compatimports file
We don't need this after dropping python2 support Signed-off-by: Cole Robinson <crobinso@redhat.com>
1 parent f4e9805 commit 6cfe8c5

7 files changed

Lines changed: 31 additions & 38 deletions

File tree

bugzilla/_authfiles.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# This work is licensed under the GNU GPLv2 or later.
22
# See the COPYING file in the top-level directory.
33

4+
import configparser
5+
import http.cookiejar
46
import os
57
from logging import getLogger
8+
import urllib.parse
69

7-
from ._compatimports import (ConfigParser, LoadError,
8-
MozillaCookieJar, urlparse)
910
from .exceptions import BugzillaError
1011
from ._util import listify
1112

@@ -15,7 +16,7 @@
1516
def _parse_hostname(url):
1617
# If http://example.com is passed, netloc=example.com path=""
1718
# If just example.com is passed, netloc="" path=example.com
18-
parsedbits = urlparse(url)
19+
parsedbits = urllib.parse.urlparse(url)
1920
return parsedbits.netloc or parsedbits.path
2021

2122

@@ -60,7 +61,7 @@ def set_configpaths(self, configpaths):
6061
configpaths = [os.path.expanduser(p) for p in
6162
listify(configpaths or [])]
6263

63-
cfg = ConfigParser()
64+
cfg = configparser.ConfigParser()
6465
read_files = cfg.read(configpaths)
6566
if read_files:
6667
log.info("Found bugzillarc files: %s", read_files)
@@ -118,7 +119,7 @@ def save_api_key(self, url, api_key):
118119

119120
config_filename = configpaths[-1]
120121
section = _parse_hostname(url)
121-
cfg = ConfigParser()
122+
cfg = configparser.ConfigParser()
122123
cfg.read(config_filename)
123124

124125
if section not in cfg.sections():
@@ -146,7 +147,7 @@ def __init__(self):
146147
self._cfg = None
147148

148149
def _get_domain(self, url):
149-
domain = urlparse(url)[1]
150+
domain = urllib.parse.urlparse(url)[1]
150151
if domain and domain not in self._cfg.sections():
151152
self._cfg.add_section(domain)
152153
return domain
@@ -178,7 +179,7 @@ def get_filename(self):
178179

179180
def set_filename(self, filename):
180181
log.debug("Using tokenfile=%s", filename)
181-
cfg = ConfigParser()
182+
cfg = configparser.ConfigParser()
182183
if filename:
183184
cfg.read(filename)
184185
self._filename = filename
@@ -194,15 +195,15 @@ def __init__(self):
194195
self._cookiejar = None
195196

196197
def _build_cookiejar(self, cookiefile):
197-
cj = MozillaCookieJar(cookiefile)
198+
cj = http.cookiejar.MozillaCookieJar(cookiefile)
198199
if (cookiefile is None or
199200
not os.path.exists(cookiefile)):
200201
return cj
201202

202203
try:
203204
cj.load()
204205
return cj
205-
except LoadError:
206+
except http.cookiejar.LoadError:
206207
msg = "cookiefile=%s not in Mozilla format" % cookiefile
207208
raise BugzillaError(msg) from None
208209

bugzilla/_backendxmlrpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
from logging import getLogger
55
import sys
6+
from xmlrpc.client import (Binary, Fault, ProtocolError,
7+
ServerProxy, Transport)
68

79
from requests import RequestException
810

911
from ._backendbase import _BackendBase
10-
from ._compatimports import (Binary, Fault, ProtocolError,
11-
ServerProxy, Transport)
1212
from .exceptions import BugzillaError
1313
from ._util import listify
1414

bugzilla/_cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
import socket
2222
import sys
2323
import tempfile
24+
import urllib.parse
25+
import xmlrpc.client
2426

2527
import requests.exceptions
2628

2729
import bugzilla
28-
from bugzilla._compatimports import Fault, ProtocolError, urlparse
2930

3031

3132
DEFAULT_BZ = 'https://bugzilla.redhat.com'
@@ -1212,7 +1213,7 @@ def _handle_login(opt, action, bz):
12121213
print("You already have an API key configured for %s" % bz.url)
12131214
print("There is no need to cache a login token. Exiting.")
12141215
sys.exit(0)
1215-
print("Logging into %s" % urlparse(bz.url)[1])
1216+
print("Logging into %s" % urllib.parse.urlparse(bz.url)[1])
12161217
bz.interactive_login(username, password,
12171218
restrict_login=opt.restrict_login)
12181219
except bugzilla.BugzillaError as e:
@@ -1293,7 +1294,7 @@ def main(unittest_bz_instance=None):
12931294
except KeyboardInterrupt:
12941295
print("\nExited at user request.")
12951296
sys.exit(1)
1296-
except (Fault, bugzilla.BugzillaError) as e:
1297+
except (xmlrpc.client.Fault, bugzilla.BugzillaError) as e:
12971298
print("\nServer error: %s" % str(e))
12981299
sys.exit(3)
12991300
except requests.exceptions.SSLError as e:
@@ -1307,7 +1308,7 @@ def main(unittest_bz_instance=None):
13071308
requests.exceptions.HTTPError,
13081309
requests.exceptions.ConnectionError,
13091310
requests.exceptions.InvalidURL,
1310-
ProtocolError) as e:
1311+
xmlrpc.client.ProtocolError) as e:
13111312
print("\nConnection lost/failed: %s" % str(e))
13121313
sys.exit(2)
13131314

bugzilla/_compatimports.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

bugzilla/_session.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
import os
77
import sys
8+
import urllib.parse
89

910
import requests
1011

11-
from ._compatimports import urlparse
12-
1312

1413
log = getLogger(__name__)
1514

@@ -23,7 +22,7 @@ def __init__(self, url, user_agent,
2322
tokencache, api_key, requests_session=None):
2423
self._url = url
2524
self._user_agent = user_agent
26-
self._scheme = urlparse(url)[0]
25+
self._scheme = urllib.parse.urlparse(url)[0]
2726
self._cookiecache = cookiecache
2827
self._tokencache = tokencache
2928
self._api_key = api_key

bugzilla/base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# This work is licensed under the GNU GPLv2 or later.
77
# See the COPYING file in the top-level directory.
88

9+
import collections
910
import getpass
1011
import locale
1112
from logging import getLogger
1213
import mimetypes
1314
import os
1415
import sys
16+
import urllib.parse
1517

1618
from io import BytesIO
1719

@@ -20,7 +22,6 @@
2022
from .apiversion import __version__
2123
from ._backendrest import _BackendREST
2224
from ._backendxmlrpc import _BackendXMLRPC
23-
from ._compatimports import Mapping, urlparse, urlunparse, parse_qsl
2425
from .bug import Bug, Group, User
2526
from .exceptions import BugzillaError
2627
from ._rhconverters import _RHBugzillaConverters
@@ -34,7 +35,7 @@
3435
def _nested_update(d, u):
3536
# Helper for nested dict update()
3637
for k, v in list(u.items()):
37-
if isinstance(v, Mapping):
38+
if isinstance(v, collections.abc.Mapping):
3839
d[k] = _nested_update(d.get(k, {}), v)
3940
else:
4041
d[k] = v
@@ -110,13 +111,13 @@ def url_to_query(url):
110111

111112
# pylint: disable=unpacking-non-sequence
112113
(ignore1, ignore2, path,
113-
ignore, query, ignore3) = urlparse(url)
114+
ignore, query, ignore3) = urllib.parse.urlparse(url)
114115

115116
base = os.path.basename(path)
116117
if base not in ('buglist.cgi', 'query.cgi'):
117118
return {}
118119

119-
for (k, v) in parse_qsl(query):
120+
for (k, v) in urllib.parse.parse_qsl(query):
120121
if k not in q:
121122
q[k] = v
122123
elif isinstance(q[k], list):
@@ -141,7 +142,8 @@ def fix_url(url, force_rest=False):
141142
142143
:param force_rest: If True, generate a REST API url
143144
"""
144-
scheme, netloc, path, params, query, fragment = urlparse(url)
145+
(scheme, netloc, path,
146+
params, query, fragment) = urllib.parse.urlparse(url)
145147
if not scheme:
146148
scheme = 'https'
147149

@@ -154,7 +156,8 @@ def fix_url(url, force_rest=False):
154156
if force_rest:
155157
path = "rest/"
156158

157-
newurl = urlunparse((scheme, netloc, path, params, query, fragment))
159+
newurl = urllib.parse.urlunparse(
160+
(scheme, netloc, path, params, query, fragment))
158161
return newurl
159162

160163
@staticmethod

tests/test_cli_misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import base64
1313
import datetime
1414
import json
15+
import xmlrpc.client
1516

1617
import pytest
1718
import requests
1819

1920
import bugzilla
20-
from bugzilla._compatimports import Binary, DateTime
2121

2222
import tests
2323
import tests.mockbackend
@@ -111,8 +111,8 @@ def test_json_xmlrpc(run_cli):
111111
bugid = 1165434
112112
data = {"bugs": [{
113113
'id': bugid,
114-
'timetest': DateTime(dateobj),
115-
'binarytest': Binary(attachdata),
114+
'timetest': xmlrpc.client.DateTime(dateobj),
115+
'binarytest': xmlrpc.client.Binary(attachdata),
116116
}]}
117117

118118
fakebz = tests.mockbackend.make_bz(

0 commit comments

Comments
 (0)