Skip to content

Commit

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

Signed-off-by: Sandro Bonazzola <sbonazzo@redhat.com>
  • Loading branch information
sandrobonazzola committed Jan 31, 2025
1 parent ef8331c commit 7d6380b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions did/plugins/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Gerrit():
"""

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

Expand All @@ -74,19 +73,18 @@ def join_URL_frags(base, query):

def get_query_result(self, url):
log.debug('url = %s', url)
res = self.opener.open(url)
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
res.close()
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 +244,7 @@ class SubmitedChanges(GerritUnit):
def fetch(self):
log.info("Searching for changes opened by %s", 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 7d6380b

Please # to comment.