Skip to content

Commit

Permalink
Avoid using deprecated FancyURLopener
Browse files Browse the repository at this point in the history
Fixes #298

Signed-off-by: Sandro Bonazzola <[email protected]>
  • Loading branch information
sandrobonazzola committed Jan 23, 2025
1 parent bb23ea5 commit 838283c
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 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 Expand Up @@ -246,7 +243,7 @@ class SubmitedChanges(GerritUnit):
def fetch(self):
log.info("Searching for changes opened by {0}".format(self.user))
if 'wip' in self.server_features:
query_string = 'status:open -is:wip'
query_string = 'status:open+-is:wip'
else:
query_string = 'status:open'
self.stats = GerritUnit.fetch(self, query_string,
Expand Down

0 comments on commit 838283c

Please sign in to comment.