py3: use six.moves.urllib.parse instead of urlparse

six is the canonical compatibility library for supporting
Python 2 and 3 in a single codebase.

The urlparse module  was removed in Python 3 and we should
use 'six.moves.urllib.parse' instead of 'urlparse' to make
code compatible with py 2 and 3 as well.

Partially-implements blueprint py3-compatibility

Change-Id: Ib27244d0583e81e307d5e4236cbf85d29566dde9
This commit is contained in:
chen-li 2014-12-26 20:36:27 +08:00
parent 67ccd12e42
commit a6a76d6821
4 changed files with 16 additions and 13 deletions

View File

@ -15,10 +15,10 @@
import os
import re
import urlparse
from oslo.config import cfg
import six
from six.moves.urllib import parse
import webob
from manila.api.openstack import wsgi
@ -159,7 +159,7 @@ def remove_version_from_href(href):
Returns: 'http://www.manila.com'
"""
parsed_url = urlparse.urlsplit(href)
parsed_url = parse.urlsplit(href)
url_parts = parsed_url.path.split('/', 2)
# NOTE: this should match vX.X or vX
@ -176,7 +176,7 @@ def remove_version_from_href(href):
parsed_url = list(parsed_url)
parsed_url[2] = new_path
return urlparse.urlunsplit(parsed_url)
return parse.urlunsplit(parsed_url)
def dict_to_query_str(params):
@ -249,10 +249,10 @@ class ViewBuilder(object):
def _update_link_prefix(self, orig_url, prefix):
if not prefix:
return orig_url
url_parts = list(urlparse.urlsplit(orig_url))
prefix_parts = list(urlparse.urlsplit(prefix))
url_parts = list(parse.urlsplit(orig_url))
prefix_parts = list(parse.urlsplit(prefix))
url_parts[0:2] = prefix_parts[0:2]
return urlparse.urlunsplit(url_parts)
return parse.urlunsplit(url_parts)
class MetadataDeserializer(wsgi.MetadataXMLDeserializer):

View File

@ -13,9 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import urlparse
from oslo.utils import strutils
from six.moves.urllib import parse
import webob
from manila.api import extensions
@ -95,7 +95,7 @@ class QuotaSetsController(object):
def show(self, req, id):
context = req.environ['manila.context']
authorize_show(context)
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
params = parse.parse_qs(req.environ.get('QUERY_STRING', ''))
user_id = None
if self.ext_mgr.is_loaded('os-user-quotas'):
user_id = params.get('user_id', [None])[0]
@ -127,7 +127,7 @@ class QuotaSetsController(object):
user_id = None
if self.ext_mgr.is_loaded('os-user-quotas'):
# Update user quotas only if the extended is loaded
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
params = parse.parse_qs(req.environ.get('QUERY_STRING', ''))
user_id = params.get('user_id', [None])[0]
try:
@ -220,7 +220,7 @@ class QuotaSetsController(object):
if self.ext_mgr.is_loaded('os-extended-quotas'):
context = req.environ['manila.context']
authorize_delete(context)
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
params = parse.parse_qs(req.environ.get('QUERY_STRING', ''))
user_id = params.get('user_id', [None])[0]
if user_id and not self.ext_mgr.is_loaded('os-user-quotas'):
raise webob.exc.HTTPNotFound()

View File

@ -13,9 +13,9 @@
# under the License.
import httplib
import urlparse
from oslo.serialization import jsonutils
from six.moves.urllib import parse
from manila.openstack.common import log as logging
@ -87,7 +87,7 @@ class TestOpenStackClient(object):
_headers = {'Content-Type': 'application/json'}
_headers.update(headers or {})
parsed_url = urlparse.urlparse(url)
parsed_url = parse.urlparse(url)
port = parsed_url.port
hostname = parsed_url.hostname
scheme = parsed_url.scheme

View File

@ -31,7 +31,10 @@ from pylint.reporters import text
ignore_codes = ["E1103"]
# Note(maoy): the error message is the pattern of E0202. It should be ignored
# for manila.tests modules
ignore_messages = ["An attribute affected in manila.tests"]
# Note(chen): the second error message is the pattern of [E0611]
# It should be ignored because use six module to keep py3.X compatibility.
ignore_messages = ["An attribute affected in manila.tests",
"No name 'urllib' in module '_MovedItems'"]
# Note(maoy): we ignore all errors in openstack.common because it should be
# checked elsewhere. We also ignore manila.tests for now due to high false
# positive rate.