From a31867f5e68f57394b1e376962d6e1f544e516ba Mon Sep 17 00:00:00 2001 From: "Swapnil Kulkarni (coolsvap)" Date: Thu, 24 Dec 2015 11:14:16 +0530 Subject: [PATCH] Keep py3.X compatibility for urllib Change-Id: I40edeea4f8320d52472466c6f6832f19f8bd79f0 Partial-Bug:#1280105 --- trove/common/pagination.py | 19 +++++++++---------- trove/tests/api/users.py | 5 +++-- .../scenario/runners/user_actions_runners.py | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/trove/common/pagination.py b/trove/common/pagination.py index a7e80b0817..d9534a328c 100644 --- a/trove/common/pagination.py +++ b/trove/common/pagination.py @@ -18,14 +18,13 @@ try: from collections import OrderedDict except ImportError: from ordereddict import OrderedDict -import six.moves.urllib.parse as urlparse -import urllib +import six.moves.urllib.parse as urllib_parse def url_quote(s): if s is None: return s - return urllib.quote(str(s)) + return urllib_parse.quote(str(s)) def paginate_list(li, limit=None, marker=None, include_marker=False): @@ -112,18 +111,18 @@ class AppUrl(object): # from the kwargs given. So change_query_params(foo='bar') # would remove from the URL any old instance of foo=something and # then add &foo=bar to the URL. - parsed_url = urlparse.urlparse(self.url) + parsed_url = urllib_parse.urlparse(self.url) # Build a dictionary out of the query parameters in the URL # with an OrderedDict to preserve the order of the URL. - query_params = OrderedDict(urlparse.parse_qsl(parsed_url.query)) + query_params = OrderedDict(urllib_parse.parse_qsl(parsed_url.query)) # Use kwargs to change or update any values in the query dict. query_params.update(kwargs) # Build a new query based on the updated query dict. - new_query_params = urllib.urlencode(query_params) + new_query_params = urllib_parse.urlencode(query_params) return self.__class__( # Force HTTPS. - urlparse.ParseResult('https', - parsed_url.netloc, parsed_url.path, - parsed_url.params, new_query_params, - parsed_url.fragment).geturl()) + urllib_parse.ParseResult('https', + parsed_url.netloc, parsed_url.path, + parsed_url.params, new_query_params, + parsed_url.fragment).geturl()) diff --git a/trove/tests/api/users.py b/trove/tests/api/users.py index 0d30cec7d0..c92703228a 100644 --- a/trove/tests/api/users.py +++ b/trove/tests/api/users.py @@ -13,7 +13,8 @@ # under the License. import time -import urllib + +from six.moves.urllib import parse as urllib_parse from proboscis import after_class from proboscis.asserts import assert_equal @@ -443,7 +444,7 @@ class TestUsers(object): assert_true(len(users) <= limit) assert_true(users.next is not None) expected_marker = "%s@%s" % (users[-1].name, users[-1].host) - expected_marker = urllib.quote(expected_marker) + expected_marker = urllib_parse.quote(expected_marker) assert_equal(marker, expected_marker) marker = users.next diff --git a/trove/tests/scenario/runners/user_actions_runners.py b/trove/tests/scenario/runners/user_actions_runners.py index 472c75b04c..cfc128598f 100644 --- a/trove/tests/scenario/runners/user_actions_runners.py +++ b/trove/tests/scenario/runners/user_actions_runners.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import urllib +from six.moves.urllib import parse as urllib_parse from trove.tests.scenario.runners.test_runners import TestRunner from troveclient.compat import exceptions @@ -101,7 +101,7 @@ class UserActionsRunner(TestRunner): self.assert_pagination_match(list_page, full_list, 0, limit) if marker: last_user = list_page[-1] - expected_marker = urllib.quote( + expected_marker = urllib_parse.quote( '%s@%s' % (last_user.name, last_user.host)) self.assert_equal(expected_marker, marker, "Pagination marker should be the last element "