Use python3 compatible urllib

urllib, urlparse, urlencode have been merged together in python 3.

Change-Id: Iec54be4f716096511c2702bdb3ba637a42607ee2
This commit is contained in:
Gregory Haynes 2015-02-11 17:19:29 -08:00 committed by greghaynes
parent 8fbd839995
commit dffd4f7fdc
8 changed files with 30 additions and 28 deletions

View File

@ -14,11 +14,11 @@
# limitations under the License.
import six
import urllib
import six.moves.urllib.parse as urlparse
def join_params(params, encode=True):
return '&'.join(
["%s=%s" % (urllib.quote(key, safe='') if encode else key,
urllib.quote(val, safe='') if encode else val)
["%s=%s" % (urlparse.quote(key, safe='') if encode else key,
urlparse.quote(val, safe='') if encode else val)
for key, val in six.iteritems(params)])

View File

@ -14,14 +14,13 @@
# limitations under the License.
import json
from urllib import urlencode
from urlparse import parse_qsl
import functools
from pecan import abort
from pecan import redirect
from pecan import response
import rfc3987
import six.moves.urllib.parse as urlparse
from storyboard.common import exception as exc
from storyboard.openstack.common.gettextutils import _ # noqa
@ -55,12 +54,15 @@ def oauth_exceptions(func):
parts = rfc3987.parse(o_exc.redirect_uri, 'URI')
# Add the error and error_description
params = parse_qsl(parts['query']) if parts['query'] else []
if parts['query']:
params = urlparse.parse_qsl(parts['query'])
else:
params = []
params.append(('error', error))
params.append(('error_description', error_description))
# Overwrite the old query params and reconstruct the URL
parts['query'] = urlencode(params)
parts['query'] = urlparse.urlencode(params)
location = rfc3987.compose(**parts)
redirect(location)

View File

@ -14,13 +14,12 @@
import datetime
import requests
from urlparse import parse_qs
from urlparse import urlparse
import uuid
from mock import patch
from oslo.config import cfg
import six
import six.moves.urllib.parse as urlparse
from storyboard.api.auth import ErrorMessages as e_msg
from storyboard.db.api import access_tokens as token_api
@ -51,12 +50,12 @@ class BaseOAuthTest(base.FunctionalTest):
self.assertEqual(expected_status_code, response.status_code)
# Split the url into parts.
location = response.headers.get('Location')
location_url = urlparse(location)
parameters = parse_qs(location_url[4])
location_url = urlparse.urlparse(location)
parameters = urlparse.parse_qs(location_url[4])
# Break out the redirect uri to compare and make sure we're headed
# back to the redirect URI with the appropriate error codes.
configured_url = urlparse(redirect_uri)
configured_url = urlparse.urlparse(redirect_uri)
self.assertEqual(configured_url[0], location_url[0])
self.assertEqual(configured_url[1], location_url[1])
self.assertEqual(configured_url[2], location_url[2])
@ -109,8 +108,8 @@ class TestOAuthAuthorize(BaseOAuthTest):
# Assert that the redirect request goes to launchpad.
location = response.headers.get('Location')
location_url = urlparse(location)
parameters = parse_qs(location_url[4])
location_url = urlparse.urlparse(location)
parameters = urlparse.parse_qs(location_url[4])
# Check the URL
conf_openid_url = CONF.oauth.openid_url
@ -123,8 +122,8 @@ class TestOAuthAuthorize(BaseOAuthTest):
# Check redirect URL
redirect = parameters['openid.return_to'][0]
redirect_url = urlparse(redirect)
redirect_params = parse_qs(redirect_url[4])
redirect_url = urlparse.urlparse(redirect)
redirect_params = urlparse.parse_qs(redirect_url[4])
self.assertIn('/openid/authorize_return', redirect)
self.assertEqual(random_state,
@ -385,8 +384,8 @@ class TestOAuthAuthorizeReturn(BaseOAuthTest):
# Try to pull the code out of the response
location = response.headers.get('Location')
location_url = urlparse(location)
parameters = parse_qs(location_url[4])
location_url = urlparse.urlparse(location)
parameters = urlparse.parse_qs(location_url[4])
token = auth_api.authorization_code_get(parameters['code'])
# Validate the redirect response

View File

@ -13,8 +13,8 @@
# under the License.
import json
from urllib import urlencode
import six.moves.urllib.parse as urlparse
from webtest.app import AppError
from storyboard.tests import base
@ -137,7 +137,7 @@ class TestProjectGroupSearch(base.FunctionalTest):
self.resource = '/project_groups'
def build_search_url(self, params):
return '/project_groups?%s' % (urlencode(params))
return '/project_groups?%s' % (urlparse.urlencode(params))
def test_search_by_name(self):
url = self.build_search_url({

View File

@ -14,8 +14,8 @@
# under the License.
import json
from urllib import urlencode
import six.moves.urllib.parse as urlparse
from webtest.app import AppError
from storyboard.tests import base
@ -120,7 +120,7 @@ class TestProjectSearch(base.FunctionalTest):
super(TestProjectSearch, self).setUp()
def build_search_url(self, params):
return '/projects?%s' % (urlencode(params))
return '/projects?%s' % (urlparse.urlencode(params))
def test_search(self):
url = self.build_search_url({

View File

@ -13,7 +13,8 @@
# under the License.
import json
from urllib import urlencode
import six.moves.urllib.parse as urlparse
from storyboard.db.api import tasks
from storyboard.tests import base
@ -113,7 +114,7 @@ class TestStorySearch(base.FunctionalTest):
def build_search_url(self, params=None, raw=''):
if params:
raw = urlencode(params)
raw = urlparse.urlencode(params)
return '/stories?%s' % raw
def test_search(self):

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import urlencode
import six.moves.urllib.parse as urlparse
from storyboard.tests import base
@ -25,7 +25,7 @@ class TestTaskStatusesSearch(base.FunctionalTest):
def build_search_url(self, params=None, raw=''):
if params:
raw = urlencode(params)
raw = urlparse.urlencode(params)
return '/task_statuses?%s' % raw
def test_search(self):

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import urlencode
import six.moves.urllib.parse as urlparse
from storyboard.tests import base
@ -55,7 +55,7 @@ class TestTaskSearch(base.FunctionalTest):
def build_search_url(self, params=None, raw=''):
if params:
raw = urlencode(params)
raw = urlparse.urlencode(params)
return '/tasks?%s' % raw
def test_search(self):