diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index 279e3d369f..850f140cad 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -14,9 +14,9 @@ # under the License. import re -import urllib from oslo.config import cfg +import six.moves.urllib.parse as urlparse import webob.exc from glance.api import policy @@ -619,7 +619,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def index(self, response, result): params = dict(response.request.params) params.pop('marker', None) - query = urllib.urlencode(params) + query = urlparse.urlencode(params) body = { 'images': [self._format_image(i) for i in result['images']], 'first': '/v2/images', @@ -629,7 +629,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): body['first'] = '%s?%s' % (body['first'], query) if 'next_marker' in result: params['marker'] = result['next_marker'] - next_query = urllib.urlencode(params) + next_query = urlparse.urlencode(params) body['next'] = '/v2/images?%s' % next_query response.unicode_body = unicode(json.dumps(body, ensure_ascii=False)) response.content_type = 'application/json' diff --git a/glance/api/v2/tasks.py b/glance/api/v2/tasks.py index 89f9898be8..8474f3f965 100644 --- a/glance/api/v2/tasks.py +++ b/glance/api/v2/tasks.py @@ -15,10 +15,10 @@ # under the License. import copy -import urllib import webob.exc from oslo.config import cfg +import six.moves.urllib.parse as urlparse from glance.api import policy from glance.common import exception @@ -254,7 +254,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def index(self, response, result): params = dict(response.request.params) params.pop('marker', None) - query = urllib.urlencode(params) + query = urlparse.urlencode(params) body = { 'tasks': [self._format_task(i, self.partial_task_schema) for i in result['tasks']], @@ -265,7 +265,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): body['first'] = '%s?%s' % (body['first'], query) if 'next_marker' in result: params['marker'] = result['next_marker'] - next_query = urllib.urlencode(params) + next_query = urlparse.urlencode(params) body['next'] = '/v2/tasks?%s' % next_query response.unicode_body = unicode(json.dumps(body, ensure_ascii=False)) response.content_type = 'application/json' diff --git a/glance/cmd/replicator.py b/glance/cmd/replicator.py index 0eb2322c2e..4ea377102f 100755 --- a/glance/cmd/replicator.py +++ b/glance/cmd/replicator.py @@ -25,9 +25,10 @@ import optparse import os import re import sys -import urllib import uuid +import six.moves.urllib.parse as urlparse + from glance.openstack.common import jsonutils # If ../glance/__init__.py exists, add ../ to Python search path, so that @@ -145,7 +146,7 @@ class ImageService(object): while True: url = '/v1/images/detail' - query = urllib.urlencode(params) + query = urlparse.urlencode(params) if query: url += '?%s' % query diff --git a/glance/common/client.py b/glance/common/client.py index 488cdc7638..1b9dfa3ad2 100644 --- a/glance/common/client.py +++ b/glance/common/client.py @@ -24,7 +24,6 @@ import functools import httplib import os import re -import urllib try: from eventlet.green import socket, ssl @@ -387,7 +386,7 @@ class BaseClient(object): """ Create a URL object we can use to pass to _do_request(). """ - action = urllib.quote(action) + action = urlparse.quote(action) path = '/'.join([self.doc_root or '', action.lstrip('/')]) scheme = "https" if self.use_ssl else "http" netloc = "%s:%d" % (self.host, self.port) @@ -400,7 +399,7 @@ class BaseClient(object): if not isinstance(value, basestring): value = str(value) params[key] = strutils.safe_encode(value) - query = urllib.urlencode(params) + query = urlparse.urlencode(params) else: query = None diff --git a/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py b/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py index d617361fa1..3fa8f237fc 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import urllib - import six.moves.urllib.parse as urlparse import sqlalchemy @@ -135,8 +133,8 @@ def legacy_parse_uri(uri, to_quote, image_id): LOG.debug(reason) raise exception.BadStoreUri() user, key = cred_parts - user = urllib.unquote(user) - key = urllib.unquote(key) + user = urlparse.unquote(user) + key = urlparse.unquote(key) else: user = None key = None @@ -161,8 +159,8 @@ def legacy_parse_uri(uri, to_quote, image_id): credstring = '' if user and key: if to_quote: - quote_user = urllib.quote(user) - quote_key = urllib.quote(key) + quote_user = urlparse.quote(user) + quote_key = urlparse.quote(key) else: quote_user = user quote_key = key diff --git a/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py b/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py index 0406ce9250..a7415050d4 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py @@ -27,7 +27,6 @@ migration performs the following steps for every entry in the images table: Fixes bug #1081043 """ import types # noqa -import urllib from oslo.config import cfg import six.moves.urllib.parse as urlparse @@ -198,8 +197,8 @@ def legacy_parse_uri(uri, to_quote, image_id): LOG.debug(reason) raise exception.BadStoreUri() user, key = cred_parts - user = urllib.unquote(user) - key = urllib.unquote(key) + user = urlparse.unquote(user) + key = urlparse.unquote(key) else: user = None key = None @@ -224,8 +223,8 @@ def legacy_parse_uri(uri, to_quote, image_id): credstring = '' if user and key: if to_quote: - quote_user = urllib.quote(user) - quote_key = urllib.quote(key) + quote_user = urlparse.quote(user) + quote_key = urlparse.quote(key) else: quote_user = user quote_key = key diff --git a/glance/store/rbd.py b/glance/store/rbd.py index 666aa8c558..75f0270397 100644 --- a/glance/store/rbd.py +++ b/glance/store/rbd.py @@ -20,9 +20,9 @@ from __future__ import with_statement import hashlib import math -import urllib from oslo.config import cfg +import six.moves.urllib.parse as urlparse from glance.common import exception from glance.common import utils @@ -92,10 +92,10 @@ class StoreLocation(glance.store.location.StoreLocation): def get_uri(self): if self.fsid and self.pool and self.snapshot: # ensure nothing contains / or any other url-unsafe character - safe_fsid = urllib.quote(self.fsid, '') - safe_pool = urllib.quote(self.pool, '') - safe_image = urllib.quote(self.image, '') - safe_snapshot = urllib.quote(self.snapshot, '') + safe_fsid = urlparse.quote(self.fsid, '') + safe_pool = urlparse.quote(self.pool, '') + safe_image = urlparse.quote(self.image, '') + safe_snapshot = urlparse.quote(self.snapshot, '') return "rbd://%s/%s/%s/%s" % (safe_fsid, safe_pool, safe_image, safe_snapshot) else: @@ -124,7 +124,7 @@ class StoreLocation(glance.store.location.StoreLocation): (None, None, pieces[0], None) elif len(pieces) == 4: self.fsid, self.pool, self.image, self.snapshot = \ - map(urllib.unquote, pieces) + map(urlparse.unquote, pieces) else: reason = _('URI must have exactly 1 or 4 components') msg = (_("Invalid URI: %(uri)s: %(reason)s") % {'uri': uri, diff --git a/glance/store/swift.py b/glance/store/swift.py index af3d8f8eae..64fd37a8e6 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -20,7 +20,6 @@ from __future__ import absolute_import import hashlib import httplib import math -import urllib from oslo.config import cfg import six.moves.urllib.parse as urlparse @@ -180,7 +179,8 @@ class StoreLocation(glance.store.location.StoreLocation): def _get_credstring(self): if self.user and self.key: - return '%s:%s@' % (urllib.quote(self.user), urllib.quote(self.key)) + return '%s:%s@' % (urlparse.quote(self.user), + urlparse.quote(self.key)) return '' def get_uri(self): @@ -247,8 +247,8 @@ class StoreLocation(glance.store.location.StoreLocation): LOG.debug(reason) raise exception.BadStoreUri() user, key = cred_parts - self.user = urllib.unquote(user) - self.key = urllib.unquote(key) + self.user = urlparse.unquote(user) + self.key = urlparse.unquote(key) else: self.user = None self.key = None diff --git a/glance/store/vmware_datastore.py b/glance/store/vmware_datastore.py index 22258e15b4..46f5f6e622 100644 --- a/glance/store/vmware_datastore.py +++ b/glance/store/vmware_datastore.py @@ -17,7 +17,6 @@ import hashlib import httplib -import urllib import netaddr from oslo.config import cfg @@ -133,7 +132,7 @@ class StoreLocation(glance.store.location.StoreLocation): 'dsName': self.specs.get('datastore_name')} else: param_list = {'dsName': self.specs.get('datastore_name')} - self.query = urllib.urlencode(param_list) + self.query = urlparse.urlencode(param_list) def get_uri(self): if is_valid_ipv6(self.server_host): diff --git a/glance/tests/functional/store/test_s3.py b/glance/tests/functional/store/test_s3.py index 1fcfee4995..cb16c4e829 100644 --- a/glance/tests/functional/store/test_s3.py +++ b/glance/tests/functional/store/test_s3.py @@ -23,7 +23,6 @@ S3 backend import ConfigParser import os import os.path -import urllib import oslo.config.cfg import six.moves.urllib.parse as urlparse @@ -115,7 +114,7 @@ class TestS3Store(store_tests.BaseTestCase, testtools.TestCase): s3_put_object(self.s3_client, bucket_name, image_id, 'XXX') s3_store_host = urlparse.urlparse(self.s3_config['s3_store_host']) - access_key = urllib.quote(self.s3_config['s3_store_access_key']) + access_key = urlparse.quote(self.s3_config['s3_store_access_key']) secret_key = self.s3_config['s3_store_secret_key'] auth_chunk = '%s:%s' % (access_key, secret_key) netloc = '%s@%s' % (auth_chunk, s3_store_host.netloc) diff --git a/glance/tests/functional/store/test_swift.py b/glance/tests/functional/store/test_swift.py index 39d030dd89..b38a3bbc97 100644 --- a/glance/tests/functional/store/test_swift.py +++ b/glance/tests/functional/store/test_swift.py @@ -27,7 +27,6 @@ import os.path import random import string import StringIO -import urllib import uuid import oslo.config.cfg @@ -426,7 +425,7 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase): # build this URL auth_url = self.swift_config['swift_store_auth_address'] auth_url = urlparse.urlparse(auth_url) - user = urllib.quote(self.swift_config['swift_store_user']) + user = urlparse.quote(self.swift_config['swift_store_user']) key = self.swift_config['swift_store_key'] netloc = ''.join(('%s:%s' % (user, key), '@', auth_url.netloc)) path = os.path.join(auth_url.path, container_name, image_id) diff --git a/glance/tests/functional/store/test_vmware_datastore.py b/glance/tests/functional/store/test_vmware_datastore.py index e8eb20f274..b46b73c34d 100644 --- a/glance/tests/functional/store/test_vmware_datastore.py +++ b/glance/tests/functional/store/test_vmware_datastore.py @@ -24,9 +24,9 @@ VMware Datastore backend import ConfigParser import httplib import os -import urllib import oslo.config.cfg +import six.moves.urllib.parse as urlparse import testtools from glance.store.vmware import api @@ -125,7 +125,7 @@ class TestVMwareDatastoreStore(store_tests.BaseTestCase, testtools.TestCase): 'ha-datacenter') param_list = {'dcPath': dc_path, 'dsName': self.vmware_config['vmware_datastore_name']} - query = urllib.urlencode(param_list) + query = urlparse.urlencode(param_list) conn = (httplib.HTTPConnection(server_ip) if self.vmware_config['vmware_api_insecure'] == 'True' else httplib.HTTPSConnection(server_ip)) diff --git a/glance/tests/unit/test_swift_store.py b/glance/tests/unit/test_swift_store.py index 6e1c8ed2ad..083b6abed7 100644 --- a/glance/tests/unit/test_swift_store.py +++ b/glance/tests/unit/test_swift_store.py @@ -20,10 +20,10 @@ import httplib import mock import StringIO import tempfile -import urllib import uuid from oslo.config import cfg +import six.moves.urllib.parse as urlparse import stubout import swiftclient @@ -222,7 +222,7 @@ class SwiftTests(object): @property def swift_store_user(self): - return urllib.quote(CONF.swift_store_user) + return urlparse.quote(CONF.swift_store_user) def test_get_size(self): """