diff options
Diffstat (limited to 'glanceclient/common')
-rw-r--r-- | glanceclient/common/http.py | 24 | ||||
-rw-r--r-- | glanceclient/common/https.py | 21 | ||||
-rw-r--r-- | glanceclient/common/progressbar.py | 4 | ||||
-rw-r--r-- | glanceclient/common/utils.py | 21 |
4 files changed, 24 insertions, 46 deletions
diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 247b92d..e24ba35 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -14,6 +14,7 @@ # under the License. import copy +import io import logging import socket @@ -23,8 +24,7 @@ import OpenSSL from oslo_utils import importutils from oslo_utils import netutils import requests -import six -import six.moves.urllib.parse as urlparse +import urllib.parse try: import json @@ -66,19 +66,13 @@ def encode_headers(headers): for h, v in headers.items(): if v is not None: # if the item is token, do not quote '+' as well. - # NOTE(imacdonn): urlparse.quote() is intended for quoting the + # NOTE(imacdonn): urllib.parse.quote() is intended for quoting the # path part of a URL, but headers like x-image-meta-location # include an entire URL. We should avoid encoding the colon in # this case (bug #1788942) safe = '=+/' if h in TOKEN_HEADERS else '/:' - if six.PY2: - # incoming items may be unicode, so get them into something - # the py2 version of urllib can handle before percent encoding - key = urlparse.quote(encodeutils.safe_encode(h), safe) - value = urlparse.quote(encodeutils.safe_encode(v), safe) - else: - key = urlparse.quote(h, safe) - value = urlparse.quote(v, safe) + key = urllib.parse.quote(h, safe) + value = urllib.parse.quote(v, safe) encoded_dict[key] = value return dict((encodeutils.safe_encode(h, encoding='ascii'), encodeutils.safe_encode(v, encoding='ascii')) @@ -105,7 +99,7 @@ class _BaseHTTPClient(object): # NOTE(jamielennox): remove this later. Managers should pass json= if # they want to send json data. data = kwargs.pop("data", None) - if data is not None and not isinstance(data, six.string_types): + if data is not None and not isinstance(data, str): try: data = json.dumps(data) content_type = 'application/json' @@ -143,7 +137,7 @@ class _BaseHTTPClient(object): # response encoding body_iter = resp.json() else: - body_iter = six.StringIO(content) + body_iter = io.StringIO(content) try: body_iter = json.loads(''.join([c for c in body_iter])) except ValueError: @@ -209,13 +203,13 @@ class HTTPClient(_BaseHTTPClient): if not self.session.verify: curl.append('-k') else: - if isinstance(self.session.verify, six.string_types): + if isinstance(self.session.verify, str): curl.append(' --cacert %s' % self.session.verify) if self.session.cert: curl.append(' --cert %s --key %s' % self.session.cert) - if data and isinstance(data, six.string_types): + if data and isinstance(data, str): curl.append('-d \'%s\'' % data) curl.append(url) diff --git a/glanceclient/common/https.py b/glanceclient/common/https.py index deb7eb0..94aeeb3 100644 --- a/glanceclient/common/https.py +++ b/glanceclient/common/https.py @@ -20,10 +20,6 @@ import struct import OpenSSL -import six -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range - try: from eventlet import patcher # Handle case where we are running in a monkey patched environment @@ -33,9 +29,9 @@ try: else: raise ImportError except ImportError: + import http.client from OpenSSL import SSL - from six.moves import http_client - HTTPSConnection = http_client.HTTPSConnection + HTTPSConnection = http.client.HTTPSConnection Connection = SSL.Connection @@ -120,8 +116,8 @@ def host_matches_cert(host, x509): def to_bytes(s): - if isinstance(s, six.string_types): - return six.b(s) + if isinstance(s, str): + return bytes(s, 'latin-1') else: return s @@ -161,14 +157,7 @@ class VerifiedHTTPSConnection(HTTPSConnection): ssl_compression=True): # List of exceptions reported by Python3 instead of # SSLConfigurationError - if six.PY3: - excp_lst = (TypeError, FileNotFoundError, ssl.SSLError) - else: - # NOTE(jamespage) - # Accommodate changes in behaviour for pep-0467, introduced - # in python 2.7.9. - # https://github.com/python/peps/blob/master/pep-0476.txt - excp_lst = (TypeError, IOError, ssl.SSLError) + excp_lst = (TypeError, FileNotFoundError, ssl.SSLError) try: HTTPSConnection.__init__(self, host, port, key_file=key_file, diff --git a/glanceclient/common/progressbar.py b/glanceclient/common/progressbar.py index 6cf0df3..bb8b21b 100644 --- a/glanceclient/common/progressbar.py +++ b/glanceclient/common/progressbar.py @@ -15,8 +15,6 @@ import sys -import six - class _ProgressBarBase(object): """A progress bar provider for a wrapped obect. @@ -83,7 +81,7 @@ class VerboseIteratorWrapper(_ProgressBarBase): def next(self): try: - data = six.next(self._wrapped) + data = next(self._wrapped) # NOTE(mouad): Assuming that data is a string b/c otherwise calling # len function will not make any sense. self._display_progress_bar(len(data)) diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index d6d2268..4084e0e 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -19,12 +19,11 @@ import hashlib import json import os import re -import six.moves.urllib.parse as urlparse import sys import threading +import urllib.parse import uuid -import six if os.name == 'nt': # noqa import msvcrt # noqa @@ -159,7 +158,7 @@ def schema_args(schema_getter, omit=None): # for the `join` to succeed. Enum types can also be `None` # therefore, join's call would fail without the following # list comprehension - vals = [six.text_type(val) for val in property.get('enum')] + vals = [str(val) for val in property.get('enum')] description += ('Valid values: ' + ', '.join(vals)) kwargs['help'] = description @@ -214,8 +213,6 @@ def print_list(objs, fields, formatters=None, field_settings=None): def _encode(src): """remove extra 'u' in PY2.""" - if six.PY2 and isinstance(src, unicode): - return src.encode('utf-8') return src @@ -343,7 +340,7 @@ def get_file_size(file_obj): :retval: The file's size or None if it cannot be determined. """ if (hasattr(file_obj, 'seek') and hasattr(file_obj, 'tell') and - (six.PY2 or six.PY3 and file_obj.seekable())): + file_obj.seekable()): try: curr = file_obj.tell() file_obj.seek(0, os.SEEK_END) @@ -399,13 +396,13 @@ def strip_version(endpoint): # we make endpoint the first argument. However, we # can't do that just yet because we need to keep # backwards compatibility. - if not isinstance(endpoint, six.string_types): + if not isinstance(endpoint, str): raise ValueError("Expected endpoint") version = None # Get rid of trailing '/' if present endpoint = endpoint.rstrip('/') - url_parts = urlparse.urlparse(endpoint) + url_parts = urllib.parse.urlparse(endpoint) (scheme, netloc, path, __, __, __) = url_parts path = path.lstrip('/') # regex to match 'v1' or 'v2.0' etc @@ -444,8 +441,8 @@ def integrity_iter(iter, checksum): for chunk in iter: yield chunk - if isinstance(chunk, six.string_types): - chunk = six.b(chunk) + if isinstance(chunk, str): + chunk = bytes(chunk, 'latin-1') md5sum.update(chunk) md5sum = md5sum.hexdigest() if md5sum != checksum: @@ -464,8 +461,8 @@ def serious_integrity_iter(iter, hasher, hash_value): """ for chunk in iter: yield chunk - if isinstance(chunk, six.string_types): - chunk = six.b(chunk) + if isinstance(chunk, str): + chunk = bytes(chunk, 'latin-1') hasher.update(chunk) computed = hasher.hexdigest() if computed != hash_value: |