Keep py3.X compatibility for urllib

Change-Id: I40edeea4f8320d52472466c6f6832f19f8bd79f0
Partial-Bug:#1280105
This commit is contained in:
Swapnil Kulkarni (coolsvap) 2015-12-24 11:14:16 +05:30
parent 2b98c53862
commit a31867f5e6
3 changed files with 14 additions and 14 deletions

View File

@ -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())

View File

@ -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

View File

@ -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 "