Do not use the six library.
Change-Id: I3dbfcfa0f5f590a41ed549afd44537d8ed41433a
This commit is contained in:
committed by
Cyril Roelandt
parent
928935e5c0
commit
b513c8db4b
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -21,12 +21,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
|
||||
@@ -161,7 +160,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
|
||||
|
||||
@@ -216,8 +215,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
|
||||
|
||||
|
||||
@@ -345,7 +342,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)
|
||||
@@ -401,13 +398,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
|
||||
@@ -446,8 +443,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:
|
||||
@@ -466,8 +463,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:
|
||||
|
||||
Reference in New Issue
Block a user