From ee1252df2d7b64aea7fce31623c2a52f77b78021 Mon Sep 17 00:00:00 2001 From: Gautham Velchuru Date: Mon, 2 Dec 2019 19:59:07 +0000 Subject: [PATCH] Bug 1532427 - Fix tox errors in mozharness/mozharness/mozilla when running python 3.5 r=egao Differential Revision: https://phabricator.services.mozilla.com/D55188 --HG-- extra : moz-landing-system : lando --- testing/mozharness/mozharness/mozilla/secrets.py | 4 ++-- .../mozharness/mozilla/structuredlog.py | 4 ++-- .../mozharness/mozilla/testing/testbase.py | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/testing/mozharness/mozharness/mozilla/secrets.py b/testing/mozharness/mozharness/mozilla/secrets.py index 1f20fd738999..1889bcdb7a97 100644 --- a/testing/mozharness/mozharness/mozilla/secrets.py +++ b/testing/mozharness/mozharness/mozilla/secrets.py @@ -8,7 +8,7 @@ """ import os -import urllib2 +from six.moves import urllib import json @@ -20,7 +20,7 @@ class SecretsMixin(object): # within a taskcluster task. Outside of that environment, do not # use this action. url = "http://taskcluster/secrets/v1/secret/" + secret_name - res = urllib2.urlopen(url) + res = urllib.request.urlopen(url) if res.getcode() != 200: self.fatal("Error fetching from secrets API:" + res.read()) diff --git a/testing/mozharness/mozharness/mozilla/structuredlog.py b/testing/mozharness/mozharness/mozilla/structuredlog.py index 0d21e6995f74..2ca7ec412c1b 100644 --- a/testing/mozharness/mozharness/mozilla/structuredlog.py +++ b/testing/mozharness/mozharness/mozilla/structuredlog.py @@ -121,7 +121,7 @@ class StructuredOutputParser(OutputParser): self.update_levels(tbpl_level, level) def _subtract_tuples(self, old, new): - items = set(old.keys() + new.keys()) + items = set(list(old.keys()) + list(new.keys())) merged = defaultdict(int) for item in items: merged[item] = new.get(item, 0) - old.get(item, 0) @@ -210,7 +210,7 @@ class StructuredOutputParser(OutputParser): 'suite_end': 'No suite end message was emitted by this harness.', 'test_end': 'No checks run.', } - for action, diagnostic_message in required_actions.iteritems(): + for action, diagnostic_message in required_actions.items(): if action not in summary.action_counts: self.log(diagnostic_message, ERROR) self.update_levels(*error_pair) diff --git a/testing/mozharness/mozharness/mozilla/testing/testbase.py b/testing/mozharness/mozharness/mozilla/testing/testbase.py index 7edfa1f12bb3..a2192441adf3 100755 --- a/testing/mozharness/mozharness/mozilla/testing/testbase.py +++ b/testing/mozharness/mozharness/mozilla/testing/testbase.py @@ -8,9 +8,9 @@ import copy import os import platform -import urllib2 +from six.moves import urllib import json -from urlparse import urlparse, ParseResult +from six.moves.urllib.parse import urlparse, ParseResult from mozharness.base.errors import BaseErrorList from mozharness.base.log import FATAL, WARNING @@ -132,7 +132,7 @@ class TestingMixin(VirtualenvMixin, AutomationMixin, ResourceMonitoringMixin, self.fatal("Can't figure out build directory urls without an installer_url " "or test_packages_url!") - reference_url = urllib2.unquote(reference_url) + reference_url = urllib.parse.unquote(reference_url) parts = list(urlparse(reference_url)) last_slash = parts[2].rfind('/') @@ -230,7 +230,7 @@ class TestingMixin(VirtualenvMixin, AutomationMixin, ResourceMonitoringMixin, if c.get("test_packages_url"): c["test_packages_url"] = _replace_url(c["test_packages_url"], c["replace_urls"]) - for key, value in self.config.iteritems(): + for key, value in self.config.items(): if type(value) == str and value.startswith("http"): self.config[key] = _replace_url(value, c["replace_urls"]) @@ -253,20 +253,20 @@ class TestingMixin(VirtualenvMixin, AutomationMixin, ResourceMonitoringMixin, self.https_username, self.https_password = get_credentials() # This creates a password manager - passman = urllib2.HTTPPasswordMgrWithDefaultRealm() + passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() # Because we have put None at the start it will use this username/password # combination from here on passman.add_password(None, url, self.https_username, self.https_password) - authhandler = urllib2.HTTPBasicAuthHandler(passman) + authhandler = urllib.request.HTTPBasicAuthHandler(passman) - return urllib2.build_opener(authhandler).open(url, **kwargs) + return urllib.request.build_opener(authhandler).open(url, **kwargs) # If we have the developer_run flag enabled then we will switch # URLs to the right place and enable http authentication if "developer_config.py" in self.config["config_files"]: return _urlopen_basic_auth(url, **kwargs) else: - return urllib2.urlopen(url, **kwargs) + return urllib.request.urlopen(url, **kwargs) def _query_binary_version(self, regex, cmd): output = self.get_output_from_command(cmd, silent=False)