Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using deprecated FancyURLopener #384

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions did/plugins/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class Gerrit(object):
"""

def __init__(self, baseurl, prefix):
self.opener = urllib.request.FancyURLopener()
self.baseurl = baseurl
self.prefix = prefix

Expand All @@ -74,21 +73,19 @@ def join_URL_frags(base, query):
return urllib.parse.urlunsplit(split)

def get_query_result(self, url):
log.debug('url = {0}'.format(url))
res = self.opener.open(url)
if res.getcode() != 200:
raise IOError(
'Cannot retrieve list of changes ({0})'.format(res.getcode()))

# see https://code.google.com/p/gerrit/issues/detail?id=2006
# for explanation of skipping first four characters
json_str = res.read()[4:].strip()
try:
data = json.loads(json_str)
except ValueError:
log.exception('Cannot parse JSON data:\n%s', json_str)
raise
res.close()
log.debug('url = %s', url)
with urllib.request.urlopen(url) as res:
if res.getcode() != 200:
raise IOError(f'Cannot retrieve list of changes ({res.getcode()})')

# see https://code.google.com/p/gerrit/issues/detail?id=2006
# for explanation of skipping first four characters
json_str = res.read()[4:].strip()
try:
data = json.loads(json_str)
except ValueError:
log.exception('Cannot parse JSON data:\n%s', json_str)
raise

return data

Expand Down
Loading