Keep py3.X compatibility for urllib
Use six.moves.urllib.parse instead of urllib Partial-Bug: #1280105 Change-Id: Id08fd5b4dad35c888f302a69be56252fe8276bcb
This commit is contained in:
parent
4a02162a18
commit
6013c0b688
|
@ -14,9 +14,9 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from glance.api import policy
|
from glance.api import policy
|
||||||
|
@ -619,7 +619,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
||||||
def index(self, response, result):
|
def index(self, response, result):
|
||||||
params = dict(response.request.params)
|
params = dict(response.request.params)
|
||||||
params.pop('marker', None)
|
params.pop('marker', None)
|
||||||
query = urllib.urlencode(params)
|
query = urlparse.urlencode(params)
|
||||||
body = {
|
body = {
|
||||||
'images': [self._format_image(i) for i in result['images']],
|
'images': [self._format_image(i) for i in result['images']],
|
||||||
'first': '/v2/images',
|
'first': '/v2/images',
|
||||||
|
@ -629,7 +629,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
||||||
body['first'] = '%s?%s' % (body['first'], query)
|
body['first'] = '%s?%s' % (body['first'], query)
|
||||||
if 'next_marker' in result:
|
if 'next_marker' in result:
|
||||||
params['marker'] = result['next_marker']
|
params['marker'] = result['next_marker']
|
||||||
next_query = urllib.urlencode(params)
|
next_query = urlparse.urlencode(params)
|
||||||
body['next'] = '/v2/images?%s' % next_query
|
body['next'] = '/v2/images?%s' % next_query
|
||||||
response.unicode_body = unicode(json.dumps(body, ensure_ascii=False))
|
response.unicode_body = unicode(json.dumps(body, ensure_ascii=False))
|
||||||
response.content_type = 'application/json'
|
response.content_type = 'application/json'
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import urllib
|
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
|
|
||||||
from glance.api import policy
|
from glance.api import policy
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
|
@ -254,7 +254,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
||||||
def index(self, response, result):
|
def index(self, response, result):
|
||||||
params = dict(response.request.params)
|
params = dict(response.request.params)
|
||||||
params.pop('marker', None)
|
params.pop('marker', None)
|
||||||
query = urllib.urlencode(params)
|
query = urlparse.urlencode(params)
|
||||||
body = {
|
body = {
|
||||||
'tasks': [self._format_task(i, self.partial_task_schema)
|
'tasks': [self._format_task(i, self.partial_task_schema)
|
||||||
for i in result['tasks']],
|
for i in result['tasks']],
|
||||||
|
@ -265,7 +265,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
||||||
body['first'] = '%s?%s' % (body['first'], query)
|
body['first'] = '%s?%s' % (body['first'], query)
|
||||||
if 'next_marker' in result:
|
if 'next_marker' in result:
|
||||||
params['marker'] = result['next_marker']
|
params['marker'] = result['next_marker']
|
||||||
next_query = urllib.urlencode(params)
|
next_query = urlparse.urlencode(params)
|
||||||
body['next'] = '/v2/tasks?%s' % next_query
|
body['next'] = '/v2/tasks?%s' % next_query
|
||||||
response.unicode_body = unicode(json.dumps(body, ensure_ascii=False))
|
response.unicode_body = unicode(json.dumps(body, ensure_ascii=False))
|
||||||
response.content_type = 'application/json'
|
response.content_type = 'application/json'
|
||||||
|
|
|
@ -25,9 +25,10 @@ import optparse
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
|
|
||||||
from glance.openstack.common import jsonutils
|
from glance.openstack.common import jsonutils
|
||||||
|
|
||||||
# If ../glance/__init__.py exists, add ../ to Python search path, so that
|
# If ../glance/__init__.py exists, add ../ to Python search path, so that
|
||||||
|
@ -145,7 +146,7 @@ class ImageService(object):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
url = '/v1/images/detail'
|
url = '/v1/images/detail'
|
||||||
query = urllib.urlencode(params)
|
query = urlparse.urlencode(params)
|
||||||
if query:
|
if query:
|
||||||
url += '?%s' % query
|
url += '?%s' % query
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import functools
|
||||||
import httplib
|
import httplib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from eventlet.green import socket, ssl
|
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().
|
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('/')])
|
path = '/'.join([self.doc_root or '', action.lstrip('/')])
|
||||||
scheme = "https" if self.use_ssl else "http"
|
scheme = "https" if self.use_ssl else "http"
|
||||||
netloc = "%s:%d" % (self.host, self.port)
|
netloc = "%s:%d" % (self.host, self.port)
|
||||||
|
@ -400,7 +399,7 @@ class BaseClient(object):
|
||||||
if not isinstance(value, basestring):
|
if not isinstance(value, basestring):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
params[key] = strutils.safe_encode(value)
|
params[key] = strutils.safe_encode(value)
|
||||||
query = urllib.urlencode(params)
|
query = urlparse.urlencode(params)
|
||||||
else:
|
else:
|
||||||
query = None
|
query = None
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import urllib
|
|
||||||
|
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
|
@ -135,8 +133,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
|
||||||
LOG.debug(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
user, key = cred_parts
|
user, key = cred_parts
|
||||||
user = urllib.unquote(user)
|
user = urlparse.unquote(user)
|
||||||
key = urllib.unquote(key)
|
key = urlparse.unquote(key)
|
||||||
else:
|
else:
|
||||||
user = None
|
user = None
|
||||||
key = None
|
key = None
|
||||||
|
@ -161,8 +159,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
|
||||||
credstring = ''
|
credstring = ''
|
||||||
if user and key:
|
if user and key:
|
||||||
if to_quote:
|
if to_quote:
|
||||||
quote_user = urllib.quote(user)
|
quote_user = urlparse.quote(user)
|
||||||
quote_key = urllib.quote(key)
|
quote_key = urlparse.quote(key)
|
||||||
else:
|
else:
|
||||||
quote_user = user
|
quote_user = user
|
||||||
quote_key = key
|
quote_key = key
|
||||||
|
|
|
@ -27,7 +27,6 @@ migration performs the following steps for every entry in the images table:
|
||||||
Fixes bug #1081043
|
Fixes bug #1081043
|
||||||
"""
|
"""
|
||||||
import types # noqa
|
import types # noqa
|
||||||
import urllib
|
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
|
@ -198,8 +197,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
|
||||||
LOG.debug(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
user, key = cred_parts
|
user, key = cred_parts
|
||||||
user = urllib.unquote(user)
|
user = urlparse.unquote(user)
|
||||||
key = urllib.unquote(key)
|
key = urlparse.unquote(key)
|
||||||
else:
|
else:
|
||||||
user = None
|
user = None
|
||||||
key = None
|
key = None
|
||||||
|
@ -224,8 +223,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
|
||||||
credstring = ''
|
credstring = ''
|
||||||
if user and key:
|
if user and key:
|
||||||
if to_quote:
|
if to_quote:
|
||||||
quote_user = urllib.quote(user)
|
quote_user = urlparse.quote(user)
|
||||||
quote_key = urllib.quote(key)
|
quote_key = urlparse.quote(key)
|
||||||
else:
|
else:
|
||||||
quote_user = user
|
quote_user = user
|
||||||
quote_key = key
|
quote_key = key
|
||||||
|
|
|
@ -20,9 +20,9 @@ from __future__ import with_statement
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import math
|
import math
|
||||||
import urllib
|
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
|
@ -92,10 +92,10 @@ class StoreLocation(glance.store.location.StoreLocation):
|
||||||
def get_uri(self):
|
def get_uri(self):
|
||||||
if self.fsid and self.pool and self.snapshot:
|
if self.fsid and self.pool and self.snapshot:
|
||||||
# ensure nothing contains / or any other url-unsafe character
|
# ensure nothing contains / or any other url-unsafe character
|
||||||
safe_fsid = urllib.quote(self.fsid, '')
|
safe_fsid = urlparse.quote(self.fsid, '')
|
||||||
safe_pool = urllib.quote(self.pool, '')
|
safe_pool = urlparse.quote(self.pool, '')
|
||||||
safe_image = urllib.quote(self.image, '')
|
safe_image = urlparse.quote(self.image, '')
|
||||||
safe_snapshot = urllib.quote(self.snapshot, '')
|
safe_snapshot = urlparse.quote(self.snapshot, '')
|
||||||
return "rbd://%s/%s/%s/%s" % (safe_fsid, safe_pool,
|
return "rbd://%s/%s/%s/%s" % (safe_fsid, safe_pool,
|
||||||
safe_image, safe_snapshot)
|
safe_image, safe_snapshot)
|
||||||
else:
|
else:
|
||||||
|
@ -124,7 +124,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
||||||
(None, None, pieces[0], None)
|
(None, None, pieces[0], None)
|
||||||
elif len(pieces) == 4:
|
elif len(pieces) == 4:
|
||||||
self.fsid, self.pool, self.image, self.snapshot = \
|
self.fsid, self.pool, self.image, self.snapshot = \
|
||||||
map(urllib.unquote, pieces)
|
map(urlparse.unquote, pieces)
|
||||||
else:
|
else:
|
||||||
reason = _('URI must have exactly 1 or 4 components')
|
reason = _('URI must have exactly 1 or 4 components')
|
||||||
msg = (_("Invalid URI: %(uri)s: %(reason)s") % {'uri': uri,
|
msg = (_("Invalid URI: %(uri)s: %(reason)s") % {'uri': uri,
|
||||||
|
|
|
@ -20,7 +20,6 @@ from __future__ import absolute_import
|
||||||
import hashlib
|
import hashlib
|
||||||
import httplib
|
import httplib
|
||||||
import math
|
import math
|
||||||
import urllib
|
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
|
@ -180,7 +179,8 @@ class StoreLocation(glance.store.location.StoreLocation):
|
||||||
|
|
||||||
def _get_credstring(self):
|
def _get_credstring(self):
|
||||||
if self.user and self.key:
|
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 ''
|
return ''
|
||||||
|
|
||||||
def get_uri(self):
|
def get_uri(self):
|
||||||
|
@ -247,8 +247,8 @@ class StoreLocation(glance.store.location.StoreLocation):
|
||||||
LOG.debug(reason)
|
LOG.debug(reason)
|
||||||
raise exception.BadStoreUri()
|
raise exception.BadStoreUri()
|
||||||
user, key = cred_parts
|
user, key = cred_parts
|
||||||
self.user = urllib.unquote(user)
|
self.user = urlparse.unquote(user)
|
||||||
self.key = urllib.unquote(key)
|
self.key = urlparse.unquote(key)
|
||||||
else:
|
else:
|
||||||
self.user = None
|
self.user = None
|
||||||
self.key = None
|
self.key = None
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import httplib
|
import httplib
|
||||||
import urllib
|
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
@ -133,7 +132,7 @@ class StoreLocation(glance.store.location.StoreLocation):
|
||||||
'dsName': self.specs.get('datastore_name')}
|
'dsName': self.specs.get('datastore_name')}
|
||||||
else:
|
else:
|
||||||
param_list = {'dsName': self.specs.get('datastore_name')}
|
param_list = {'dsName': self.specs.get('datastore_name')}
|
||||||
self.query = urllib.urlencode(param_list)
|
self.query = urlparse.urlencode(param_list)
|
||||||
|
|
||||||
def get_uri(self):
|
def get_uri(self):
|
||||||
if is_valid_ipv6(self.server_host):
|
if is_valid_ipv6(self.server_host):
|
||||||
|
|
|
@ -23,7 +23,6 @@ S3 backend
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import urllib
|
|
||||||
|
|
||||||
import oslo.config.cfg
|
import oslo.config.cfg
|
||||||
import six.moves.urllib.parse as urlparse
|
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_put_object(self.s3_client, bucket_name, image_id, 'XXX')
|
||||||
|
|
||||||
s3_store_host = urlparse.urlparse(self.s3_config['s3_store_host'])
|
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']
|
secret_key = self.s3_config['s3_store_secret_key']
|
||||||
auth_chunk = '%s:%s' % (access_key, secret_key)
|
auth_chunk = '%s:%s' % (access_key, secret_key)
|
||||||
netloc = '%s@%s' % (auth_chunk, s3_store_host.netloc)
|
netloc = '%s@%s' % (auth_chunk, s3_store_host.netloc)
|
||||||
|
|
|
@ -27,7 +27,6 @@ import os.path
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import StringIO
|
import StringIO
|
||||||
import urllib
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import oslo.config.cfg
|
import oslo.config.cfg
|
||||||
|
@ -426,7 +425,7 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
|
||||||
# build this URL
|
# build this URL
|
||||||
auth_url = self.swift_config['swift_store_auth_address']
|
auth_url = self.swift_config['swift_store_auth_address']
|
||||||
auth_url = urlparse.urlparse(auth_url)
|
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']
|
key = self.swift_config['swift_store_key']
|
||||||
netloc = ''.join(('%s:%s' % (user, key), '@', auth_url.netloc))
|
netloc = ''.join(('%s:%s' % (user, key), '@', auth_url.netloc))
|
||||||
path = os.path.join(auth_url.path, container_name, image_id)
|
path = os.path.join(auth_url.path, container_name, image_id)
|
||||||
|
|
|
@ -24,9 +24,9 @@ VMware Datastore backend
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import httplib
|
import httplib
|
||||||
import os
|
import os
|
||||||
import urllib
|
|
||||||
|
|
||||||
import oslo.config.cfg
|
import oslo.config.cfg
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from glance.store.vmware import api
|
from glance.store.vmware import api
|
||||||
|
@ -125,7 +125,7 @@ class TestVMwareDatastoreStore(store_tests.BaseTestCase, testtools.TestCase):
|
||||||
'ha-datacenter')
|
'ha-datacenter')
|
||||||
param_list = {'dcPath': dc_path,
|
param_list = {'dcPath': dc_path,
|
||||||
'dsName': self.vmware_config['vmware_datastore_name']}
|
'dsName': self.vmware_config['vmware_datastore_name']}
|
||||||
query = urllib.urlencode(param_list)
|
query = urlparse.urlencode(param_list)
|
||||||
conn = (httplib.HTTPConnection(server_ip)
|
conn = (httplib.HTTPConnection(server_ip)
|
||||||
if self.vmware_config['vmware_api_insecure'] == 'True'
|
if self.vmware_config['vmware_api_insecure'] == 'True'
|
||||||
else httplib.HTTPSConnection(server_ip))
|
else httplib.HTTPSConnection(server_ip))
|
||||||
|
|
|
@ -20,10 +20,10 @@ import httplib
|
||||||
import mock
|
import mock
|
||||||
import StringIO
|
import StringIO
|
||||||
import tempfile
|
import tempfile
|
||||||
import urllib
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
import six.moves.urllib.parse as urlparse
|
||||||
import stubout
|
import stubout
|
||||||
import swiftclient
|
import swiftclient
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ class SwiftTests(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def swift_store_user(self):
|
def swift_store_user(self):
|
||||||
return urllib.quote(CONF.swift_store_user)
|
return urlparse.quote(CONF.swift_store_user)
|
||||||
|
|
||||||
def test_get_size(self):
|
def test_get_size(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue