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:
Fengqian Gao 2014-02-18 13:44:31 +08:00
parent 4a02162a18
commit 6013c0b688
13 changed files with 36 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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