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:
parent
67ccd12e42
commit
a6a76d6821
@ -15,10 +15,10 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import urlparse
|
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import six
|
import six
|
||||||
|
from six.moves.urllib import parse
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from manila.api.openstack import wsgi
|
from manila.api.openstack import wsgi
|
||||||
@ -159,7 +159,7 @@ def remove_version_from_href(href):
|
|||||||
Returns: 'http://www.manila.com'
|
Returns: 'http://www.manila.com'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
parsed_url = urlparse.urlsplit(href)
|
parsed_url = parse.urlsplit(href)
|
||||||
url_parts = parsed_url.path.split('/', 2)
|
url_parts = parsed_url.path.split('/', 2)
|
||||||
|
|
||||||
# NOTE: this should match vX.X or vX
|
# 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 = list(parsed_url)
|
||||||
parsed_url[2] = new_path
|
parsed_url[2] = new_path
|
||||||
return urlparse.urlunsplit(parsed_url)
|
return parse.urlunsplit(parsed_url)
|
||||||
|
|
||||||
|
|
||||||
def dict_to_query_str(params):
|
def dict_to_query_str(params):
|
||||||
@ -249,10 +249,10 @@ class ViewBuilder(object):
|
|||||||
def _update_link_prefix(self, orig_url, prefix):
|
def _update_link_prefix(self, orig_url, prefix):
|
||||||
if not prefix:
|
if not prefix:
|
||||||
return orig_url
|
return orig_url
|
||||||
url_parts = list(urlparse.urlsplit(orig_url))
|
url_parts = list(parse.urlsplit(orig_url))
|
||||||
prefix_parts = list(urlparse.urlsplit(prefix))
|
prefix_parts = list(parse.urlsplit(prefix))
|
||||||
url_parts[0:2] = prefix_parts[0:2]
|
url_parts[0:2] = prefix_parts[0:2]
|
||||||
return urlparse.urlunsplit(url_parts)
|
return parse.urlunsplit(url_parts)
|
||||||
|
|
||||||
|
|
||||||
class MetadataDeserializer(wsgi.MetadataXMLDeserializer):
|
class MetadataDeserializer(wsgi.MetadataXMLDeserializer):
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
# 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 urlparse
|
|
||||||
|
|
||||||
from oslo.utils import strutils
|
from oslo.utils import strutils
|
||||||
|
from six.moves.urllib import parse
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from manila.api import extensions
|
from manila.api import extensions
|
||||||
@ -95,7 +95,7 @@ class QuotaSetsController(object):
|
|||||||
def show(self, req, id):
|
def show(self, req, id):
|
||||||
context = req.environ['manila.context']
|
context = req.environ['manila.context']
|
||||||
authorize_show(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
|
user_id = None
|
||||||
if self.ext_mgr.is_loaded('os-user-quotas'):
|
if self.ext_mgr.is_loaded('os-user-quotas'):
|
||||||
user_id = params.get('user_id', [None])[0]
|
user_id = params.get('user_id', [None])[0]
|
||||||
@ -127,7 +127,7 @@ class QuotaSetsController(object):
|
|||||||
user_id = None
|
user_id = None
|
||||||
if self.ext_mgr.is_loaded('os-user-quotas'):
|
if self.ext_mgr.is_loaded('os-user-quotas'):
|
||||||
# Update user quotas only if the extended is loaded
|
# 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]
|
user_id = params.get('user_id', [None])[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -220,7 +220,7 @@ class QuotaSetsController(object):
|
|||||||
if self.ext_mgr.is_loaded('os-extended-quotas'):
|
if self.ext_mgr.is_loaded('os-extended-quotas'):
|
||||||
context = req.environ['manila.context']
|
context = req.environ['manila.context']
|
||||||
authorize_delete(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]
|
user_id = params.get('user_id', [None])[0]
|
||||||
if user_id and not self.ext_mgr.is_loaded('os-user-quotas'):
|
if user_id and not self.ext_mgr.is_loaded('os-user-quotas'):
|
||||||
raise webob.exc.HTTPNotFound()
|
raise webob.exc.HTTPNotFound()
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httplib
|
import httplib
|
||||||
import urlparse
|
|
||||||
|
|
||||||
from oslo.serialization import jsonutils
|
from oslo.serialization import jsonutils
|
||||||
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
from manila.openstack.common import log as logging
|
from manila.openstack.common import log as logging
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class TestOpenStackClient(object):
|
|||||||
_headers = {'Content-Type': 'application/json'}
|
_headers = {'Content-Type': 'application/json'}
|
||||||
_headers.update(headers or {})
|
_headers.update(headers or {})
|
||||||
|
|
||||||
parsed_url = urlparse.urlparse(url)
|
parsed_url = parse.urlparse(url)
|
||||||
port = parsed_url.port
|
port = parsed_url.port
|
||||||
hostname = parsed_url.hostname
|
hostname = parsed_url.hostname
|
||||||
scheme = parsed_url.scheme
|
scheme = parsed_url.scheme
|
||||||
|
@ -31,7 +31,10 @@ from pylint.reporters import text
|
|||||||
ignore_codes = ["E1103"]
|
ignore_codes = ["E1103"]
|
||||||
# Note(maoy): the error message is the pattern of E0202. It should be ignored
|
# Note(maoy): the error message is the pattern of E0202. It should be ignored
|
||||||
# for manila.tests modules
|
# 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
|
# 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
|
# checked elsewhere. We also ignore manila.tests for now due to high false
|
||||||
# positive rate.
|
# positive rate.
|
||||||
|
Loading…
Reference in New Issue
Block a user