diff options
Diffstat (limited to 'taskflow/utils')
-rw-r--r-- | taskflow/utils/banner.py | 6 | ||||
-rw-r--r-- | taskflow/utils/iter_utils.py | 8 | ||||
-rw-r--r-- | taskflow/utils/kazoo_utils.py | 10 | ||||
-rw-r--r-- | taskflow/utils/misc.py | 27 | ||||
-rw-r--r-- | taskflow/utils/mixins.py | 35 | ||||
-rw-r--r-- | taskflow/utils/redis_utils.py | 4 | ||||
-rw-r--r-- | taskflow/utils/threading_utils.py | 6 |
7 files changed, 27 insertions, 69 deletions
diff --git a/taskflow/utils/banner.py b/taskflow/utils/banner.py index a40eea6..0c2adb3 100644 --- a/taskflow/utils/banner.py +++ b/taskflow/utils/banner.py @@ -17,8 +17,6 @@ import os import string -import six - from taskflow.utils import misc from taskflow import version @@ -62,7 +60,7 @@ def make_banner(what, chapters): buf.write_nl(BANNER_HEADER) if chapters: buf.write_nl("*%s*" % what) - chapter_names = sorted(six.iterkeys(chapters)) + chapter_names = sorted(chapters.keys()) else: buf.write("*%s*" % what) chapter_names = [] @@ -73,7 +71,7 @@ def make_banner(what, chapters): else: buf.write("%s:" % (chapter_name)) if isinstance(chapter_contents, dict): - section_names = sorted(six.iterkeys(chapter_contents)) + section_names = sorted(chapter_contents.keys()) for j, section_name in enumerate(section_names): if j + 1 < len(section_names): buf.write_nl(" %s => %s" diff --git a/taskflow/utils/iter_utils.py b/taskflow/utils/iter_utils.py index 8591d23..ebf4107 100644 --- a/taskflow/utils/iter_utils.py +++ b/taskflow/utils/iter_utils.py @@ -15,15 +15,13 @@ # under the License. from collections import abc +import functools import itertools -import six -from six.moves import range as compat_range - def _ensure_iterable(func): - @six.wraps(func) + @functools.wraps(func) def wrapper(it, *args, **kwargs): if not isinstance(it, abc.Iterable): raise ValueError("Iterable expected, but '%s' is not" @@ -147,5 +145,5 @@ def iter_forever(limit): while True: yield next(i) else: - for i in compat_range(0, limit): + for i in range(0, limit): yield i diff --git a/taskflow/utils/kazoo_utils.py b/taskflow/utils/kazoo_utils.py index 2d856bd..505c101 100644 --- a/taskflow/utils/kazoo_utils.py +++ b/taskflow/utils/kazoo_utils.py @@ -17,8 +17,6 @@ from kazoo import client from kazoo import exceptions as k_exc from oslo_utils import reflection -import six -from six.moves import zip as compat_zip from taskflow import exceptions as exc from taskflow import logging @@ -28,11 +26,11 @@ LOG = logging.getLogger(__name__) def _parse_hosts(hosts): - if isinstance(hosts, six.string_types): + if isinstance(hosts, str): return hosts.strip() if isinstance(hosts, (dict)): host_ports = [] - for (k, v) in six.iteritems(hosts): + for (k, v) in hosts.items(): host_ports.append("%s:%s" % (k, v)) hosts = host_ports if isinstance(hosts, (list, set, tuple)): @@ -89,7 +87,7 @@ def checked_commit(txn): return [] results = txn.commit() failures = [] - for op, result in compat_zip(txn.operations, results): + for op, result in zip(txn.operations, results): if isinstance(result, k_exc.KazooException): failures.append((op, result)) if len(results) < len(txn.operations): @@ -211,7 +209,7 @@ def make_client(conf): if 'connection_retry' in conf: client_kwargs['connection_retry'] = conf['connection_retry'] hosts = _parse_hosts(conf.get("hosts", "localhost:2181")) - if not hosts or not isinstance(hosts, six.string_types): + if not hosts or not isinstance(hosts, str): raise TypeError("Invalid hosts format, expected " "non-empty string/list, not '%s' (%s)" % (hosts, type(hosts))) diff --git a/taskflow/utils/misc.py b/taskflow/utils/misc.py index 65a93e2..8c0f904 100644 --- a/taskflow/utils/misc.py +++ b/taskflow/utils/misc.py @@ -18,7 +18,9 @@ import collections.abc import contextlib import datetime +import functools import inspect +import io import os import re import socket @@ -33,13 +35,12 @@ from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import netutils from oslo_utils import reflection -import six from taskflow.types import failure UNKNOWN_HOSTNAME = "<unknown>" -NUMERIC_TYPES = six.integer_types + (float,) +NUMERIC_TYPES = (int, float) # NOTE(imelnikov): regular expression to get scheme from URI, # see RFC 3986 section 3.1 @@ -57,7 +58,7 @@ class StrEnum(str, enum.Enum): return super(StrEnum, cls).__new__(cls, *args, **kwargs) -class StringIO(six.StringIO): +class StringIO(io.StringIO): """String buffer with some small additions.""" def write_nl(self, value, linesep=os.linesep): @@ -65,7 +66,7 @@ class StringIO(six.StringIO): self.write(linesep) -class BytesIO(six.BytesIO): +class BytesIO(io.BytesIO): """Byte buffer with some small additions.""" def reset(self): @@ -118,7 +119,7 @@ def countdown_iter(start_at, decr=1): def extract_driver_and_conf(conf, conf_key): """Common function to get a driver name and its configuration.""" - if isinstance(conf, six.string_types): + if isinstance(conf, str): conf = {conf_key: conf} maybe_uri = conf[conf_key] try: @@ -161,7 +162,7 @@ def merge_uri(uri, conf): for (k, v, is_not_empty_value_func) in specials: if is_not_empty_value_func(v): conf.setdefault(k, v) - for (k, v) in six.iteritems(uri.params()): + for (k, v) in uri.params().items(): conf.setdefault(k, v) return conf @@ -182,7 +183,7 @@ def find_subclasses(locations, base_cls, exclude_hidden=True): derived = set() for item in locations: module = None - if isinstance(item, six.string_types): + if isinstance(item, str): try: pkg, cls = item.split(':') except ValueError: @@ -221,7 +222,7 @@ def pick_first_not_none(*values): def parse_uri(uri): """Parses a uri into its components.""" # Do some basic validation before continuing... - if not isinstance(uri, six.string_types): + if not isinstance(uri, str): raise TypeError("Can only parse string types to uri data, " "and not '%s' (%s)" % (uri, type(uri))) match = _SCHEME_REGEX.match(uri) @@ -236,7 +237,7 @@ def disallow_when_frozen(excp_cls): def decorator(f): - @six.wraps(f) + @functools.wraps(f) def wrapper(self, *args, **kwargs): if self.frozen: raise excp_cls() @@ -274,7 +275,7 @@ def binary_encode(text, encoding='utf-8', errors='strict'): Does nothing if data is already a binary string (raises on unknown types). """ - if isinstance(text, six.binary_type): + if isinstance(text, bytes): return text else: return encodeutils.safe_encode(text, encoding=encoding, @@ -286,7 +287,7 @@ def binary_decode(data, encoding='utf-8', errors='strict'): Does nothing if data is already a text string (raises on unknown types). """ - if isinstance(data, six.text_type): + if isinstance(data, str): return data else: return encodeutils.safe_decode(data, incoming=encoding, @@ -426,7 +427,7 @@ def get_version_string(obj): if isinstance(obj_version, (list, tuple)): obj_version = '.'.join(str(item) for item in obj_version) if obj_version is not None and not isinstance(obj_version, - six.string_types): + str): obj_version = str(obj_version) return obj_version @@ -524,7 +525,7 @@ def is_iterable(obj): :param obj: object to be tested for iterable :return: True if object is iterable and is not a string """ - return (not isinstance(obj, six.string_types) and + return (not isinstance(obj, str) and isinstance(obj, collections.abc.Iterable)) diff --git a/taskflow/utils/mixins.py b/taskflow/utils/mixins.py deleted file mode 100644 index 5bb0fa4..0000000 --- a/taskflow/utils/mixins.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright (C) 2015 Yahoo! Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import six - - -class StrMixin(object): - """Mixin that helps deal with the PY2 and PY3 method differences. - - http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ explains - why this is quite useful... - """ - - if six.PY2: - def __str__(self): - try: - return self.__bytes__() - except AttributeError: - return self.__unicode__().encode('utf-8') - else: - def __str__(self): - return self.__unicode__() diff --git a/taskflow/utils/redis_utils.py b/taskflow/utils/redis_utils.py index 0d04073..373ab2d 100644 --- a/taskflow/utils/redis_utils.py +++ b/taskflow/utils/redis_utils.py @@ -15,15 +15,15 @@ # under the License. import enum +import functools import redis from redis import exceptions as redis_exceptions -import six def _raise_on_closed(meth): - @six.wraps(meth) + @functools.wraps(meth) def wrapper(self, *args, **kwargs): if self.closed: raise redis_exceptions.ConnectionError("Connection has been" diff --git a/taskflow/utils/threading_utils.py b/taskflow/utils/threading_utils.py index ed55468..74b4ebb 100644 --- a/taskflow/utils/threading_utils.py +++ b/taskflow/utils/threading_utils.py @@ -14,13 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +import _thread import collections import multiprocessing import threading -import six -from six.moves import _thread - from taskflow.utils import misc @@ -106,7 +104,7 @@ class ThreadBundle(object): before_join, after_join) for attr_name in builder.fields: cb = getattr(builder, attr_name) - if not six.callable(cb): + if not callable(cb): raise ValueError("Provided callback for argument" " '%s' must be callable" % attr_name) with self._lock: |