It was removed urllib, urllib2 & urlparse modules

Those modules have been combined in python 3. Therefore,
implementing the six module helps to have support to both versions.

Change-Id: I164a0f19790ff066d16d0cf4f0daa6f1097c848e
Closes-Bug: #1267181
This commit is contained in:
Victor Morales
2014-01-15 13:34:09 -06:00
parent e4d1961c92
commit 29674c3f48
6 changed files with 25 additions and 23 deletions
+6 -6
View File
@@ -20,10 +20,10 @@ import logging
import posixpath
import socket
import struct
import urlparse
import six
from six.moves import http_client
from six.moves.urllib import parse
try:
import json
@@ -31,9 +31,9 @@ except ImportError:
import simplejson as json
# Python 2.5 compat fix
if not hasattr(urlparse, 'parse_qsl'):
if not hasattr(parse, 'parse_qsl'):
import cgi
urlparse.parse_qsl = cgi.parse_qsl
parse.parse_qsl = cgi.parse_qsl
import OpenSSL
@@ -85,7 +85,7 @@ class HTTPClient(object):
@staticmethod
def parse_endpoint(endpoint):
return urlparse.urlparse(endpoint)
return parse.urlparse(endpoint)
@staticmethod
def get_connection_class(scheme):
@@ -199,14 +199,14 @@ class HTTPClient(object):
# v1/images/detail' from recursion.
# See bug #1230032 and bug #1208618.
if url is not None:
all_parts = urlparse.urlparse(url)
all_parts = parse.urlparse(url)
if not (all_parts.scheme and all_parts.netloc):
norm_parse = posixpath.normpath
url = norm_parse('/'.join([self.endpoint_path, url]))
else:
url = self.endpoint_path
conn_url = urlparse.urlsplit(url).geturl()
conn_url = parse.urlsplit(url).geturl()
# Note(flaper87): Ditto, headers / url
# encoding to make httplib happy.
conn_url = strutils.safe_encode(conn_url)
+5 -4
View File
@@ -15,8 +15,9 @@
import copy
import json
import six
import urllib
from six.moves.urllib import parse
from glanceclient.common import base
from glanceclient.common import utils
@@ -112,7 +113,7 @@ class ImageManager(base.Manager):
image_id = base.getid(image)
resp, body = self.api.raw_request('HEAD', '/v1/images/%s'
% urllib.quote(str(image_id)))
% parse.quote(str(image_id)))
meta = self._image_meta_from_headers(dict(resp.getheaders()))
return Image(self, meta)
@@ -125,7 +126,7 @@ class ImageManager(base.Manager):
"""
image_id = base.getid(image)
resp, body = self.api.raw_request('GET', '/v1/images/%s'
% urllib.quote(str(image_id)))
% parse.quote(str(image_id)))
checksum = resp.getheader('x-image-meta-checksum', None)
if do_checksum and checksum is not None:
body.set_checksum(checksum)
@@ -171,7 +172,7 @@ class ImageManager(base.Manager):
# trying to encode them
qp[param] = strutils.safe_encode(value)
url = '/v1/images/detail?%s' % urllib.urlencode(qp)
url = '/v1/images/detail?%s' % parse.urlencode(qp)
images = self._list(url, "images")
for image in images:
if filter_owner(owner, image):
+3 -2
View File
@@ -22,7 +22,8 @@ from __future__ import print_function
import argparse
import sys
import urlparse
from six.moves.urllib import parse
from glanceclient.common import utils
@@ -75,7 +76,7 @@ def print_image_formatted(client, image):
:param client: The Glance client object
:param image: The image metadata
"""
uri_parts = urlparse.urlparse(client.http_client.endpoint)
uri_parts = parse.urlparse(client.http_client.endpoint)
if uri_parts.port:
hostbase = "%s:%s" % (uri_parts.hostname, uri_parts.port)
else:
+3 -3
View File
@@ -14,7 +14,7 @@
# under the License.
import six
import urllib
from six.moves.urllib import parse
import warlock
@@ -64,10 +64,10 @@ class Controller(object):
if isinstance(value, six.string_types):
filters[param] = strutils.safe_encode(value)
url = '/v2/images?%s' % urllib.urlencode(filters)
url = '/v2/images?%s' % parse.urlencode(filters)
for param in tags_url_params:
url = '%s&%s' % (url, urllib.urlencode(param))
url = '%s&%s' % (url, parse.urlencode(param))
for image in paginate(url):
#NOTE(bcwaldon): remove 'self' for now until we have an elegant