From 838283cb4117b2f146249d2ed86865c2c4e5df34 Mon Sep 17 00:00:00 2001 From: Sandro Bonazzola Date: Thu, 23 Jan 2025 14:59:20 +0100 Subject: [PATCH] Avoid using deprecated FancyURLopener Fixes #298 Signed-off-by: Sandro Bonazzola --- did/plugins/gerrit.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/did/plugins/gerrit.py b/did/plugins/gerrit.py index e19c9f2c..85b01d53 100644 --- a/did/plugins/gerrit.py +++ b/did/plugins/gerrit.py @@ -63,7 +63,6 @@ class Gerrit(object): """ def __init__(self, baseurl, prefix): - self.opener = urllib.request.FancyURLopener() self.baseurl = baseurl self.prefix = prefix @@ -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 @@ -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,