summaryrefslogtreecommitdiff
path: root/swiftclient
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2022-02-17 11:37:13 +0000
committerStephen Finucane <stephenfin@redhat.com>2022-03-21 18:31:10 +0000
commitfa137a5bf1f2a86cc15ebc4d973f245e1543105d (patch)
tree1aa5f0d23479ead227f319d2751df2372215a6ce /swiftclient
parent4983b909831b72b5361aadf573cadd3afaaf8976 (diff)
downloadpython-swiftclient-fa137a5bf1f2a86cc15ebc4d973f245e1543105d.tar.gz
Remove six
This mostly affects tests. Nothing too complicated Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Change-Id: Iabc78f651e1d48db35638280722f8019798eccd6
Diffstat (limited to 'swiftclient')
-rw-r--r--swiftclient/authv1.py2
-rw-r--r--swiftclient/client.py59
-rw-r--r--swiftclient/exceptions.py2
-rw-r--r--swiftclient/multithreading.py13
-rw-r--r--swiftclient/service.py30
-rwxr-xr-xswiftclient/shell.py9
-rw-r--r--swiftclient/utils.py24
7 files changed, 53 insertions, 86 deletions
diff --git a/swiftclient/authv1.py b/swiftclient/authv1.py
index d70acac..705dcb4 100644
--- a/swiftclient/authv1.py
+++ b/swiftclient/authv1.py
@@ -40,7 +40,7 @@ import datetime
import json
import time
-from six.moves.urllib.parse import urljoin
+from urllib.parse import urljoin
# Note that while we import keystoneauth1 here, we *don't* need to add it to
# requirements.txt -- this entire module only makes sense (and should only be
diff --git a/swiftclient/client.py b/swiftclient/client.py
index ddcf63a..df5344d 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -22,11 +22,10 @@ import logging
import warnings
from requests.exceptions import RequestException, SSLError
-from six.moves import http_client
-from six.moves.urllib.parse import quote as _quote, unquote
-from six.moves.urllib.parse import urljoin, urlparse, urlunparse
+import http.client as http_client
+from urllib.parse import quote as _quote, unquote
+from urllib.parse import urljoin, urlparse, urlunparse
from time import sleep, time
-import six
from swiftclient import version as swiftclient_version
from swiftclient.exceptions import ClientException
@@ -165,34 +164,20 @@ def http_log(args, kwargs, resp, body):
def parse_header_string(data):
- if not isinstance(data, (six.text_type, six.binary_type)):
+ if not isinstance(data, (str, bytes)):
data = str(data)
- if six.PY2:
- if isinstance(data, six.text_type):
- # Under Python2 requests only returns binary_type, but if we get
- # some stray text_type input, this should prevent unquote from
- # interpreting %-encoded data as raw code-points.
- data = data.encode('utf8')
+ if isinstance(data, bytes):
+ # Under Python3 requests only returns text_type and tosses (!) the
+ # rest of the headers. If that ever changes, this should be a sane
+ # approach.
try:
- unquoted = unquote(data).decode('utf8')
+ data = data.decode('ascii')
except UnicodeDecodeError:
- try:
- return data.decode('utf8')
- except UnicodeDecodeError:
- return quote(data).decode('utf8')
- else:
- if isinstance(data, six.binary_type):
- # Under Python3 requests only returns text_type and tosses (!) the
- # rest of the headers. If that ever changes, this should be a sane
- # approach.
- try:
- data = data.decode('ascii')
- except UnicodeDecodeError:
- data = quote(data)
- try:
- unquoted = unquote(data, errors='strict')
- except UnicodeDecodeError:
- return data
+ data = quote(data)
+ try:
+ unquoted = unquote(data, errors='strict')
+ except UnicodeDecodeError:
+ return data
return unquoted
@@ -201,20 +186,18 @@ def quote(value, safe='/'):
Patched version of urllib.quote that encodes utf8 strings before quoting.
On Python 3, call directly urllib.parse.quote().
"""
- if six.PY3:
- return _quote(value, safe=safe)
- return _quote(encode_utf8(value), safe)
+ return _quote(value, safe=safe)
def encode_utf8(value):
- if type(value) in six.integer_types + (float, bool):
+ if type(value) in (int, float, bool):
# As of requests 2.11.0, headers must be byte- or unicode-strings.
# Convert some known-good types as a convenience for developers.
# Note that we *don't* convert subclasses, as they may have overriddden
# __str__ or __repr__.
# See https://github.com/kennethreitz/requests/pull/3366 for more info
value = str(value)
- if isinstance(value, six.text_type):
+ if isinstance(value, str):
value = value.encode('utf8')
return value
@@ -226,7 +209,7 @@ def encode_meta_headers(headers):
value = encode_utf8(value)
header = header.lower()
- if (isinstance(header, six.string_types) and
+ if (isinstance(header, str) and
header.startswith(USER_METADATA_TYPE)):
header = encode_utf8(header)
@@ -457,12 +440,12 @@ class HTTPConnection(object):
old_getheader = self.resp.raw.getheader
def _decode_header(string):
- if string is None or six.PY2:
+ if string is None:
return string
return string.encode('iso-8859-1').decode('utf-8')
def _encode_header(string):
- if string is None or six.PY2:
+ if string is None:
return string
return string.encode('utf-8').decode('iso-8859-1')
@@ -1441,7 +1424,7 @@ def put_object(url, token=None, container=None, name=None, contents=None,
warnings.warn(warn_msg, stacklevel=2)
# Match requests's is_stream test
if hasattr(contents, '__iter__') and not isinstance(contents, (
- six.text_type, six.binary_type, list, tuple, dict)):
+ str, bytes, list, tuple, dict)):
contents = iter_wrapper(contents)
conn.request('PUT', path, contents, headers)
diff --git a/swiftclient/exceptions.py b/swiftclient/exceptions.py
index a9b993c..f0d1b5d 100644
--- a/swiftclient/exceptions.py
+++ b/swiftclient/exceptions.py
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from six.moves import urllib
+import urllib
class ClientException(Exception):
diff --git a/swiftclient/multithreading.py b/swiftclient/multithreading.py
index 665ba63..cf72360 100644
--- a/swiftclient/multithreading.py
+++ b/swiftclient/multithreading.py
@@ -13,11 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import six
import sys
from concurrent.futures import ThreadPoolExecutor
-from six.moves.queue import PriorityQueue
+from queue import PriorityQueue
class OutputManager(object):
@@ -70,12 +69,8 @@ class OutputManager(object):
self.print_pool.submit(self._write, data, self.print_stream)
def _write(self, data, stream):
- if six.PY3:
- stream.buffer.write(data)
- stream.flush()
- if six.PY2:
- stream.write(data)
- stream.flush()
+ stream.buffer.write(data)
+ stream.flush()
def print_msg(self, msg, *fmt_args):
if fmt_args:
@@ -100,8 +95,6 @@ class OutputManager(object):
def _print(self, item, stream=None):
if stream is None:
stream = self.print_stream
- if six.PY2 and isinstance(item, six.text_type):
- item = item.encode('utf8')
print(item, file=stream)
def _print_error(self, item, count=1):
diff --git a/swiftclient/service.py b/swiftclient/service.py
index 6b8f73d..289e29e 100644
--- a/swiftclient/service.py
+++ b/swiftclient/service.py
@@ -21,6 +21,7 @@ from concurrent.futures import as_completed, CancelledError, TimeoutError
from copy import deepcopy
from errno import EEXIST, ENOENT
from hashlib import md5
+from io import StringIO
from os import environ, makedirs, stat, utime
from os.path import (
basename, dirname, getmtime, getsize, isdir, join, sep as os_path_sep
@@ -29,10 +30,9 @@ from posixpath import join as urljoin
from random import shuffle
from time import time
from threading import Thread
-from six import Iterator, StringIO, string_types, text_type
-from six.moves.queue import Queue
-from six.moves.queue import Empty as QueueEmpty
-from six.moves.urllib.parse import quote
+from queue import Queue
+from queue import Empty as QueueEmpty
+from urllib.parse import quote
import json
@@ -54,7 +54,7 @@ DISK_BUFFER = 2 ** 16
logger = logging.getLogger("swiftclient.service")
-class ResultsIterator(Iterator):
+class ResultsIterator:
def __init__(self, futures):
self.futures = interruptable_as_completed(futures)
@@ -321,10 +321,10 @@ class SwiftUploadObject(object):
options to be specified separately for each individual object.
"""
def __init__(self, source, object_name=None, options=None):
- if isinstance(source, string_types):
+ if isinstance(source, str):
self.object_name = object_name or source
elif source is None or hasattr(source, 'read'):
- if not object_name or not isinstance(object_name, string_types):
+ if not object_name or not isinstance(object_name, str):
raise SwiftError('Object names must be specified as '
'strings for uploads from None or file '
'like objects.')
@@ -347,7 +347,7 @@ class SwiftPostObject(object):
specified separately for each individual object.
"""
def __init__(self, object_name, options=None):
- if not (isinstance(object_name, string_types) and object_name):
+ if not (isinstance(object_name, str) and object_name):
raise SwiftError(
"Object names must be specified as non-empty strings"
)
@@ -361,7 +361,7 @@ class SwiftDeleteObject(object):
specified separately for each individual object.
"""
def __init__(self, object_name, options=None):
- if not (isinstance(object_name, string_types) and object_name):
+ if not (isinstance(object_name, str) and object_name):
raise SwiftError(
"Object names must be specified as non-empty strings"
)
@@ -377,7 +377,7 @@ class SwiftCopyObject(object):
destination and fresh_metadata should be set in options
"""
def __init__(self, object_name, options=None):
- if not (isinstance(object_name, string_types) and object_name):
+ if not (isinstance(object_name, str) and object_name):
raise SwiftError(
"Object names must be specified as non-empty strings"
)
@@ -835,7 +835,7 @@ class SwiftService(object):
post_objects = []
for o in objects:
- if isinstance(o, string_types):
+ if isinstance(o, str):
obj = SwiftPostObject(o)
post_objects.append(obj)
elif isinstance(o, SwiftPostObject):
@@ -1637,7 +1637,7 @@ class SwiftService(object):
upload_objects = []
for o in objects:
- if isinstance(o, string_types):
+ if isinstance(o, str):
obj = SwiftUploadObject(o, urljoin(pseudo_folder,
o.lstrip('/')))
upload_objects.append(obj)
@@ -2035,7 +2035,7 @@ class SwiftService(object):
segment_results.sort(key=lambda di: di['segment_index'])
for seg in segment_results:
seg_loc = seg['segment_location'].lstrip('/')
- if isinstance(seg_loc, text_type):
+ if isinstance(seg_loc, str):
seg_loc = seg_loc.encode('utf-8')
manifest_data = json.dumps([
@@ -2578,7 +2578,7 @@ class SwiftService(object):
delete_objects = []
for o in objects:
- if isinstance(o, string_types):
+ if isinstance(o, str):
obj = SwiftDeleteObject(o)
delete_objects.append(obj)
elif isinstance(o, SwiftDeleteObject):
@@ -2933,7 +2933,7 @@ class SwiftService(object):
copy_objects = []
for o in objects:
- if isinstance(o, string_types):
+ if isinstance(o, str):
obj = SwiftCopyObject(o, options)
copy_objects.append(obj)
elif isinstance(o, SwiftCopyObject):
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 36d0757..a16de88 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -25,8 +25,7 @@ import warnings
from os import environ, walk, _exit as os_exit
from os.path import isfile, isdir, join
-from six import text_type, PY2
-from six.moves.urllib.parse import unquote, urlparse
+from urllib.parse import unquote, urlparse
from sys import argv as sys_argv, exit, stderr, stdin
from time import gmtime, strftime
@@ -191,10 +190,6 @@ def st_delete(parser, args, output_manager, return_parser=False):
for o, err in r.get('result', {}).get('Errors', []):
# o will be of the form quote("/<cont>/<obj>")
o = unquote(o)
- if PY2:
- # In PY3, unquote(unicode) uses utf-8 like we
- # want, but PY2 uses latin-1
- o = o.encode('latin-1').decode('utf-8')
output_manager.error('Error Deleting: {0}: {1}'
.format(o[1:], err))
try:
@@ -1931,7 +1926,7 @@ def add_default_args(parser):
def main(arguments=None):
argv = sys_argv if arguments is None else arguments
- argv = [a if isinstance(a, text_type) else a.decode('utf-8') for a in argv]
+ argv = [a if isinstance(a, str) else a.decode('utf-8') for a in argv]
parser = argparse.ArgumentParser(
add_help=False, formatter_class=HelpFormatter, usage='''
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
index 656acad..03e5e7b 100644
--- a/swiftclient/utils.py
+++ b/swiftclient/utils.py
@@ -13,17 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Miscellaneous utility functions for use with Swift."""
+
from calendar import timegm
-try:
- from collections.abc import Mapping
-except ImportError:
- from collections import Mapping
+from collections.abc import Mapping
import gzip
import hashlib
import hmac
+import io
import json
import logging
-import six
import time
import traceback
@@ -42,7 +40,7 @@ def config_true_value(value):
This function comes from swift.common.utils.config_true_value()
"""
return value is True or \
- (isinstance(value, six.string_types) and value.lower() in TRUE_VALUES)
+ (isinstance(value, str) and value.lower() in TRUE_VALUES)
def prt_bytes(num_bytes, human_flag):
@@ -134,7 +132,7 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
except ValueError:
raise ValueError(TIME_ERRMSG)
- if isinstance(path, six.binary_type):
+ if isinstance(path, bytes):
try:
path_for_body = path.decode('utf-8')
except UnicodeDecodeError:
@@ -165,7 +163,7 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
('prefix:' if prefix else '') + path_for_body]
if ip_range:
- if isinstance(ip_range, six.binary_type):
+ if isinstance(ip_range, bytes):
try:
ip_range = ip_range.decode('utf-8')
except UnicodeDecodeError:
@@ -177,7 +175,7 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
hmac_body = u'\n'.join(hmac_parts)
# Encode to UTF-8 for py3 compatibility
- if not isinstance(key, six.binary_type):
+ if not isinstance(key, bytes):
key = key.encode('utf-8')
sig = hmac.new(key, hmac_body.encode('utf-8'), hashlib.sha1).hexdigest()
@@ -194,7 +192,7 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
if prefix:
temp_url += u'&temp_url_prefix={}'.format(parts[4])
# Have return type match path from caller
- if isinstance(path, six.binary_type):
+ if isinstance(path, bytes):
return temp_url.encode('utf-8')
else:
return temp_url
@@ -202,7 +200,7 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
def get_body(headers, body):
if headers.get('content-encoding') == 'gzip':
- with gzip.GzipFile(fileobj=six.BytesIO(body), mode='r') as gz:
+ with gzip.GzipFile(fileobj=io.BytesIO(body), mode='r') as gz:
nbody = gz.read()
return nbody
return body
@@ -224,7 +222,7 @@ def split_request_headers(options, prefix=''):
if isinstance(options, Mapping):
options = options.items()
for item in options:
- if isinstance(item, six.string_types):
+ if isinstance(item, str):
if ':' not in item:
raise ValueError(
"Metadata parameter %s must contain a ':'.\n"
@@ -401,8 +399,6 @@ def n_groups(seq, n):
def normalize_manifest_path(path):
- if six.PY2 and isinstance(path, six.text_type):
- path = path.encode('utf-8')
if path.startswith('/'):
return path[1:]
return path