Remove six usage

Remove six, the python 2/3 compatibility library. It's not needed
anymore since the repo is python3 only.

Remove a now unneeded hacking test.

Change-Id: I40522c4accb4aaf8115d11fee8b081e2d991cb4d
This commit is contained in:
Andreas Jaeger 2020-05-11 10:17:47 +02:00
parent c1768401f7
commit e44c988306
42 changed files with 102 additions and 161 deletions

View File

@ -26,7 +26,6 @@ import collections
import uuid import uuid
from oslo_config import cfg from oslo_config import cfg
import six
from oslo_messaging._drivers import common as rpc_common from oslo_messaging._drivers import common as rpc_common
@ -62,7 +61,7 @@ def unpack_context(msg):
"""Unpack context from msg.""" """Unpack context from msg."""
context_dict = {} context_dict = {}
for key in list(msg.keys()): for key in list(msg.keys()):
key = six.text_type(key) key = str(key)
if key.startswith('_context_'): if key.startswith('_context_'):
value = msg.pop(key) value = msg.pop(key)
context_dict[key[9:]] = value context_dict[key[9:]] = value

View File

@ -29,6 +29,7 @@ import collections
import logging import logging
import os import os
import platform import platform
import queue
import random import random
import sys import sys
import threading import threading
@ -38,9 +39,6 @@ import uuid
from oslo_utils import eventletutils from oslo_utils import eventletutils
import proton import proton
import pyngus import pyngus
from six import iteritems
from six import itervalues
from six import moves
from oslo_messaging._drivers.amqp1_driver.addressing import AddresserFactory from oslo_messaging._drivers.amqp1_driver.addressing import AddresserFactory
from oslo_messaging._drivers.amqp1_driver.addressing import keyify from oslo_messaging._drivers.amqp1_driver.addressing import keyify
@ -868,7 +866,7 @@ class Controller(pyngus.ConnectionEventHandler):
self._command = os.path.basename(sys.argv[0]) self._command = os.path.basename(sys.argv[0])
self._pid = os.getpid() self._pid = os.getpid()
# queue of drivertask objects to execute on the eventloop thread # queue of drivertask objects to execute on the eventloop thread
self._tasks = moves.queue.Queue(maxsize=500) self._tasks = queue.Queue(maxsize=500)
# limit the number of Task()'s to execute per call to _process_tasks(). # limit the number of Task()'s to execute per call to _process_tasks().
# This allows the eventloop main thread to return to servicing socket # This allows the eventloop main thread to return to servicing socket
# I/O in a timely manner # I/O in a timely manner
@ -961,7 +959,7 @@ class Controller(pyngus.ConnectionEventHandler):
LOG.debug("Waiting for eventloop to exit") LOG.debug("Waiting for eventloop to exit")
self.processor.join(timeout) self.processor.join(timeout)
self._hard_reset("Shutting down") self._hard_reset("Shutting down")
for sender in itervalues(self._all_senders): for sender in self._all_senders.values():
sender.destroy() sender.destroy()
self._all_senders.clear() self._all_senders.clear()
self._servers.clear() self._servers.clear()
@ -1134,7 +1132,7 @@ class Controller(pyngus.ConnectionEventHandler):
'vhost': ("/" + self.hosts.virtual_host 'vhost': ("/" + self.hosts.virtual_host
if self.hosts.virtual_host else "")}) if self.hosts.virtual_host else "")})
for sender in itervalues(self._all_senders): for sender in self._all_senders.values():
sender.attach(self._socket_connection.pyngus_conn, sender.attach(self._socket_connection.pyngus_conn,
self.reply_link, self.addresser) self.reply_link, self.addresser)
@ -1181,8 +1179,8 @@ class Controller(pyngus.ConnectionEventHandler):
self.addresser = self.addresser_factory(props, self.addresser = self.addresser_factory(props,
self.hosts.virtual_host self.hosts.virtual_host
if self.pseudo_vhost else None) if self.pseudo_vhost else None)
for servers in itervalues(self._servers): for servers in self._servers.values():
for server in itervalues(servers): for server in servers.values():
server.attach(self._socket_connection.pyngus_conn, server.attach(self._socket_connection.pyngus_conn,
self.addresser) self.addresser)
self.reply_link = Replies(self._socket_connection.pyngus_conn, self.reply_link = Replies(self._socket_connection.pyngus_conn,
@ -1279,7 +1277,7 @@ class Controller(pyngus.ConnectionEventHandler):
del self._purged_senders[:] del self._purged_senders[:]
self._active_senders.clear() self._active_senders.clear()
unused = [] unused = []
for key, sender in iteritems(self._all_senders): for key, sender in self._all_senders.items():
# clean up any sender links that no longer have messages to send # clean up any sender links that no longer have messages to send
if sender.pending_messages == 0: if sender.pending_messages == 0:
unused.append(key) unused.append(key)
@ -1289,8 +1287,8 @@ class Controller(pyngus.ConnectionEventHandler):
for key in unused: for key in unused:
self._all_senders[key].destroy(reason) self._all_senders[key].destroy(reason)
del self._all_senders[key] del self._all_senders[key]
for servers in itervalues(self._servers): for servers in self._servers.values():
for server in itervalues(servers): for server in servers.values():
server.reset() server.reset()
if self.reply_link: if self.reply_link:
self.reply_link.destroy() self.reply_link.destroy()
@ -1300,13 +1298,13 @@ class Controller(pyngus.ConnectionEventHandler):
def _detach_senders(self): def _detach_senders(self):
"""Close all sender links""" """Close all sender links"""
for sender in itervalues(self._all_senders): for sender in self._all_senders.values():
sender.detach() sender.detach()
def _detach_servers(self): def _detach_servers(self):
"""Close all listener links""" """Close all listener links"""
for servers in itervalues(self._servers): for servers in self._servers.values():
for server in itervalues(servers): for server in servers.values():
server.detach() server.detach()
def _purge_sender_links(self): def _purge_sender_links(self):

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import logging import logging
import queue
import threading import threading
import time import time
import uuid import uuid
@ -21,7 +22,6 @@ import uuid
import cachetools import cachetools
from oslo_utils import eventletutils from oslo_utils import eventletutils
from oslo_utils import timeutils from oslo_utils import timeutils
from six import moves
import oslo_messaging import oslo_messaging
from oslo_messaging._drivers import amqp as rpc_amqp from oslo_messaging._drivers import amqp as rpc_amqp
@ -48,7 +48,7 @@ class MessageOperationsHandler(object):
def __init__(self, name): def __init__(self, name):
self.name = "%s (%s)" % (name, hex(id(self))) self.name = "%s (%s)" % (name, hex(id(self)))
self._tasks = moves.queue.Queue() self._tasks = queue.Queue()
self._shutdown = eventletutils.Event() self._shutdown = eventletutils.Event()
self._shutdown_thread = threading.Thread( self._shutdown_thread = threading.Thread(
@ -75,7 +75,7 @@ class MessageOperationsHandler(object):
while True: while True:
try: try:
task = self._tasks.get(block=False) task = self._tasks.get(block=False)
except moves.queue.Empty: except queue.Empty:
break break
task() task()
@ -403,7 +403,7 @@ class ReplyWaiters(object):
def get(self, msg_id, timeout): def get(self, msg_id, timeout):
try: try:
return self._queues[msg_id].get(block=True, timeout=timeout) return self._queues[msg_id].get(block=True, timeout=timeout)
except moves.queue.Empty: except queue.Empty:
raise oslo_messaging.MessagingTimeout( raise oslo_messaging.MessagingTimeout(
'Timed out waiting for a reply ' 'Timed out waiting for a reply '
'to message ID %s' % msg_id) 'to message ID %s' % msg_id)
@ -418,7 +418,7 @@ class ReplyWaiters(object):
queue.put(message_data) queue.put(message_data)
def add(self, msg_id): def add(self, msg_id):
self._queues[msg_id] = moves.queue.Queue() self._queues[msg_id] = queue.Queue()
queues_length = len(self._queues) queues_length = len(self._queues)
if queues_length > self._wrn_threshold: if queues_length > self._wrn_threshold:
LOG.warning('Number of call queues is %(queues_length)s, ' LOG.warning('Number of call queues is %(queues_length)s, '
@ -529,7 +529,7 @@ class ReplyWaiter(object):
timeout = cm_timeout timeout = cm_timeout
try: try:
message = self.waiters.get(msg_id, timeout=timeout) message = self.waiters.get(msg_id, timeout=timeout)
except moves.queue.Empty: except queue.Empty:
self._raise_timeout_exception(msg_id) self._raise_timeout_exception(msg_id)
reply, ending = self._process_reply(message) reply, ending = self._process_reply(message)

View File

@ -18,7 +18,6 @@ import threading
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from oslo_messaging import exceptions from oslo_messaging import exceptions
@ -65,8 +64,7 @@ class TransportDriverError(exceptions.MessagingException):
"""Base class for transport driver specific exceptions.""" """Base class for transport driver specific exceptions."""
@six.add_metaclass(abc.ABCMeta) class IncomingMessage(object, metaclass=abc.ABCMeta):
class IncomingMessage(object):
"""The IncomingMessage class represents a single message received from the """The IncomingMessage class represents a single message received from the
messaging backend. Instances of this class are passed to up a server's messaging backend. Instances of this class are passed to up a server's
messaging processing logic. The backend driver must provide a concrete messaging processing logic. The backend driver must provide a concrete
@ -116,8 +114,7 @@ class IncomingMessage(object):
""" """
@six.add_metaclass(abc.ABCMeta) class RpcIncomingMessage(IncomingMessage, metaclass=abc.ABCMeta):
class RpcIncomingMessage(IncomingMessage):
"""The RpcIncomingMessage represents an RPC request message received from """The RpcIncomingMessage represents an RPC request message received from
the backend. This class must be used for RPC calls that return a value to the backend. This class must be used for RPC calls that return a value to
the caller. the caller.
@ -170,8 +167,7 @@ class RpcIncomingMessage(IncomingMessage):
""" """
@six.add_metaclass(abc.ABCMeta) class PollStyleListener(object, metaclass=abc.ABCMeta):
class PollStyleListener(object):
"""A PollStyleListener is used to transfer received messages to a server """A PollStyleListener is used to transfer received messages to a server
for processing. A polling pattern is used to retrieve messages. A for processing. A polling pattern is used to retrieve messages. A
PollStyleListener uses a separate thread to run the polling loop. A PollStyleListener uses a separate thread to run the polling loop. A
@ -227,8 +223,7 @@ class PollStyleListener(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class Listener(object, metaclass=abc.ABCMeta):
class Listener(object):
"""A Listener is used to transfer incoming messages from the driver to a """A Listener is used to transfer incoming messages from the driver to a
server for processing. A callback is used by the driver to transfer the server for processing. A callback is used by the driver to transfer the
messages. messages.
@ -328,8 +323,7 @@ class PollStyleListenerAdapter(Listener):
self._poll_style_listener.cleanup() self._poll_style_listener.cleanup()
@six.add_metaclass(abc.ABCMeta) class BaseDriver(object, metaclass=abc.ABCMeta):
class BaseDriver(object):
"""Defines the backend driver interface. Each backend driver implementation """Defines the backend driver interface. Each backend driver implementation
must provide a concrete derivation of this class implementing the backend must provide a concrete derivation of this class implementing the backend
specific logic for its public methods. specific logic for its public methods.

View File

@ -15,13 +15,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# TODO(smcginnis) update this once six has support for collections.abc from collections.abc import Mapping
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
import copy import copy
import logging import logging
import sys import sys
@ -29,14 +23,13 @@ import traceback
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import timeutils from oslo_utils import timeutils
import six
import oslo_messaging import oslo_messaging
from oslo_messaging import _utils as utils from oslo_messaging import _utils as utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
_EXCEPTIONS_MODULE = 'exceptions' if six.PY2 else 'builtins' _EXCEPTIONS_MODULE = 'builtins'
_EXCEPTIONS_MODULES = ['exceptions', 'builtins'] _EXCEPTIONS_MODULES = ['exceptions', 'builtins']
@ -184,8 +177,8 @@ def serialize_remote_exception(failure_info):
# NOTE(matiu): With cells, it's possible to re-raise remote, remote # NOTE(matiu): With cells, it's possible to re-raise remote, remote
# exceptions. Lets turn it back into the original exception type. # exceptions. Lets turn it back into the original exception type.
cls_name = six.text_type(failure.__class__.__name__) cls_name = str(failure.__class__.__name__)
mod_name = six.text_type(failure.__class__.__module__) mod_name = str(failure.__class__.__module__)
if (cls_name.endswith(_REMOTE_POSTFIX) and if (cls_name.endswith(_REMOTE_POSTFIX) and
mod_name.endswith(_REMOTE_POSTFIX)): mod_name.endswith(_REMOTE_POSTFIX)):
cls_name = cls_name[:-len(_REMOTE_POSTFIX)] cls_name = cls_name[:-len(_REMOTE_POSTFIX)]
@ -194,7 +187,7 @@ def serialize_remote_exception(failure_info):
data = { data = {
'class': cls_name, 'class': cls_name,
'module': mod_name, 'module': mod_name,
'message': six.text_type(failure), 'message': str(failure),
'tb': tb, 'tb': tb,
'args': failure.args, 'args': failure.args,
'kwargs': kwargs 'kwargs': kwargs
@ -206,7 +199,7 @@ def serialize_remote_exception(failure_info):
def deserialize_remote_exception(data, allowed_remote_exmods): def deserialize_remote_exception(data, allowed_remote_exmods):
failure = jsonutils.loads(six.text_type(data)) failure = jsonutils.loads(str(data))
trace = failure.get('tb', []) trace = failure.get('tb', [])
message = failure.get('message', "") + "\n" + "\n".join(trace) message = failure.get('message', "") + "\n" + "\n".join(trace)
@ -235,7 +228,7 @@ def deserialize_remote_exception(data, allowed_remote_exmods):
failure = klass(*failure.get('args', []), **failure.get('kwargs', {})) failure = klass(*failure.get('args', []), **failure.get('kwargs', {}))
except (AttributeError, TypeError, ImportError) as error: except (AttributeError, TypeError, ImportError) as error:
LOG.warning("Failed to rebuild remote exception due to error: %s", LOG.warning("Failed to rebuild remote exception due to error: %s",
six.text_type(error)) str(error))
return oslo_messaging.RemoteError(name, failure.get('message'), trace) return oslo_messaging.RemoteError(name, failure.get('message'), trace)
ex_type = type(failure) ex_type = type(failure)

View File

@ -14,12 +14,12 @@
# under the License. # under the License.
import copy import copy
import queue
import threading import threading
import time import time
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import eventletutils from oslo_utils import eventletutils
from six import moves
import oslo_messaging import oslo_messaging
from oslo_messaging._drivers import base from oslo_messaging._drivers import base
@ -133,8 +133,8 @@ class FakeExchange(object):
self.deliver_message(topic, ctxt, message, server=server, self.deliver_message(topic, ctxt, message, server=server,
fanout=fanout, reply_q=reply_q) fanout=fanout, reply_q=reply_q)
for queue in queues: for q in queues:
queue.append((ctxt, message, reply_q, requeue)) q.append((ctxt, message, reply_q, requeue))
def poll(self, target, pool): def poll(self, target, pool):
with self._queues_lock: with self._queues_lock:
@ -195,7 +195,7 @@ class FakeDriver(base.BaseDriver):
reply_q = None reply_q = None
if wait_for_reply: if wait_for_reply:
reply_q = moves.queue.Queue() reply_q = queue.Queue()
exchange.deliver_message(target.topic, ctxt, message, exchange.deliver_message(target.topic, ctxt, message,
server=target.server, server=target.server,
@ -209,7 +209,7 @@ class FakeDriver(base.BaseDriver):
raise failure raise failure
else: else:
return reply return reply
except moves.queue.Empty: except queue.Empty:
raise oslo_messaging.MessagingTimeout( raise oslo_messaging.MessagingTimeout(
'No reply on topic %s' % target.topic) 'No reply on topic %s' % target.topic)

View File

@ -24,6 +24,7 @@ import ssl
import sys import sys
import threading import threading
import time import time
from urllib import parse
import uuid import uuid
import kombu import kombu
@ -34,9 +35,6 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import eventletutils from oslo_utils import eventletutils
from oslo_utils import importutils from oslo_utils import importutils
import six
import six.moves
from six.moves.urllib import parse
import oslo_messaging import oslo_messaging
from oslo_messaging._drivers import amqp as rpc_amqp from oslo_messaging._drivers import amqp as rpc_amqp
@ -320,7 +318,7 @@ class Consumer(object):
self.declare(conn) self.declare(conn)
try: try:
self.queue.consume(callback=self._callback, self.queue.consume(callback=self._callback,
consumer_tag=six.text_type(tag), consumer_tag=str(tag),
nowait=self.nowait) nowait=self.nowait)
except conn.connection.channel_errors as exc: except conn.connection.channel_errors as exc:
# We retries once because of some races that we can # We retries once because of some races that we can
@ -340,14 +338,14 @@ class Consumer(object):
exc.method_name == 'Basic.ack'): exc.method_name == 'Basic.ack'):
self.declare(conn) self.declare(conn)
self.queue.consume(callback=self._callback, self.queue.consume(callback=self._callback,
consumer_tag=six.text_type(tag), consumer_tag=str(tag),
nowait=self.nowait) nowait=self.nowait)
else: else:
raise raise
def cancel(self, tag): def cancel(self, tag):
LOG.trace('ConsumerBase.cancel: canceling %s', tag) LOG.trace('ConsumerBase.cancel: canceling %s', tag)
self.queue.cancel(six.text_type(tag)) self.queue.cancel(str(tag))
def _callback(self, message): def _callback(self, message):
"""Call callback with deserialized message. """Call callback with deserialized message.
@ -753,7 +751,7 @@ class Connection(object):
info = {'err_str': exc, 'sleep_time': interval} info = {'err_str': exc, 'sleep_time': interval}
info.update(self._get_connection_info(conn_error=True)) info.update(self._get_connection_info(conn_error=True))
if 'Socket closed' in six.text_type(exc): if 'Socket closed' in str(exc):
LOG.error('[%(connection_id)s] AMQP server' LOG.error('[%(connection_id)s] AMQP server'
' %(hostname)s:%(port)s closed' ' %(hostname)s:%(port)s closed'
' the connection. Check login credentials:' ' the connection. Check login credentials:'
@ -867,8 +865,8 @@ class Connection(object):
"""Close/release this connection.""" """Close/release this connection."""
self._heartbeat_stop() self._heartbeat_stop()
if self.connection: if self.connection:
for consumer in six.moves.filter(lambda c: c.type == 'fanout', for consumer in filter(lambda c: c.type == 'fanout',
self._consumers): self._consumers):
LOG.debug('[connection close] Deleting fanout ' LOG.debug('[connection close] Deleting fanout '
'queue: %s ' % consumer.queue.name) 'queue: %s ' % consumer.queue.name)
consumer.queue.delete() consumer.queue.delete()

View File

@ -19,7 +19,6 @@ import threading
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from oslo_messaging._drivers import common from oslo_messaging._drivers import common
@ -36,8 +35,7 @@ else:
cond.wait() cond.wait()
@six.add_metaclass(abc.ABCMeta) class Pool(object, metaclass=abc.ABCMeta):
class Pool(object):
"""A thread-safe object pool. """A thread-safe object pool.
Modelled after the eventlet.pools.Pool interface, but designed to be safe Modelled after the eventlet.pools.Pool interface, but designed to be safe

View File

@ -13,16 +13,13 @@
import abc import abc
import six
__all__ = [ __all__ = [
"DispatcherBase" "DispatcherBase"
] ]
@six.add_metaclass(abc.ABCMeta) class DispatcherBase(object, metaclass=abc.ABCMeta):
class DispatcherBase(object):
"Base class for dispatcher" "Base class for dispatcher"
@abc.abstractmethod @abc.abstractmethod

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
__all__ = ['MessagingException', 'MessagingTimeout', 'MessageDeliveryFailure', __all__ = ['MessagingException', 'MessagingTimeout', 'MessageDeliveryFailure',
'InvalidTarget', 'MessageUndeliverable'] 'InvalidTarget', 'MessageUndeliverable']
@ -35,7 +33,7 @@ class InvalidTarget(MessagingException, ValueError):
"""Raised if a target does not meet certain pre-conditions.""" """Raised if a target does not meet certain pre-conditions."""
def __init__(self, msg, target): def __init__(self, msg, target):
msg = msg + ":" + six.text_type(target) msg = msg + ":" + str(target)
super(InvalidTarget, self).__init__(msg) super(InvalidTarget, self).__init__(msg)
self.target = target self.target = target

View File

@ -16,7 +16,6 @@ import re
import ast import ast
from hacking import core from hacking import core
import six
oslo_namespace_imports_dot = re.compile(r"import[\s]+oslo[.][^\s]+") oslo_namespace_imports_dot = re.compile(r"import[\s]+oslo[.][^\s]+")
@ -45,18 +44,6 @@ def check_oslo_namespace_imports(logical_line):
yield(0, msg) yield(0, msg)
@core.flake8ext
def check_mock_imports(logical_line):
if re.match(mock_imports_directly, logical_line):
msg = ("O322: '%s' must be used instead of '%s'.") % (
logical_line.replace('import mock', 'from six.moves import mock'),
logical_line)
yield(0, msg)
elif re.match(mock_imports_direclty_from, logical_line):
msg = "O322: Use mock from six.moves."
yield(0, msg)
class BaseASTChecker(ast.NodeVisitor): class BaseASTChecker(ast.NodeVisitor):
"""Provides a simple framework for writing AST-based checks. """Provides a simple framework for writing AST-based checks.
@ -152,7 +139,7 @@ class CheckForLoggingIssues(BaseASTChecker):
if obj_name is None: if obj_name is None:
return None return None
return obj_name + '.' + method_name return obj_name + '.' + method_name
elif isinstance(node, six.string_types): elif isinstance(node, str):
return node return node
else: # could be Subscript, Call or many more else: # could be Subscript, Call or many more
return None return None
@ -284,10 +271,7 @@ class CheckForLoggingIssues(BaseASTChecker):
peers = find_peers(node) peers = find_peers(node)
for peer in peers: for peer in peers:
if isinstance(peer, ast.Raise): if isinstance(peer, ast.Raise):
if six.PY3: exc = peer.exc
exc = peer.exc
else:
exc = peer.type
if (isinstance(exc, ast.Call) and if (isinstance(exc, ast.Call) and
len(exc.args) > 0 and len(exc.args) > 0 and
isinstance(exc.args[0], ast.Name) and isinstance(exc.args[0], ast.Name) and

View File

@ -18,8 +18,6 @@ import itertools
import logging import logging
import operator import operator
import six
from oslo_messaging import dispatcher from oslo_messaging import dispatcher
from oslo_messaging import serializer as msg_serializer from oslo_messaging import serializer as msg_serializer
@ -124,7 +122,7 @@ class BatchNotificationDispatcher(NotificationDispatcher):
requeues = set() requeues = set()
for priority, messages in messages_grouped: for priority, messages in messages_grouped:
__, raw_messages, messages = six.moves.zip(*messages) __, raw_messages, messages = zip(*messages)
if priority not in PRIORITIES: if priority not in PRIORITIES:
LOG.warning('Unknown priority "%s"', priority) LOG.warning('Unknown priority "%s"', priority)
continue continue

View File

@ -15,8 +15,6 @@
import re import re
import six
class NotificationFilter(object): class NotificationFilter(object):
@ -63,7 +61,7 @@ class NotificationFilter(object):
def _check_for_single_mismatch(data, regex): def _check_for_single_mismatch(data, regex):
if regex is None: if regex is None:
return False return False
if not isinstance(data, six.string_types): if not isinstance(data, str):
return True return True
if not regex.match(data): if not regex.match(data):
return True return True

View File

@ -22,7 +22,6 @@ import uuid
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from stevedore import extension from stevedore import extension
from stevedore import named from stevedore import named
@ -106,8 +105,7 @@ def _send_notification():
notifier._notify({}, args.event_type, args.payload, args.priority) notifier._notify({}, args.event_type, args.payload, args.priority)
@six.add_metaclass(abc.ABCMeta) class Driver(object, metaclass=abc.ABCMeta):
class Driver(object):
"""Base driver for Notifications""" """Base driver for Notifications"""
def __init__(self, conf, topics, transport): def __init__(self, conf, topics, transport):
@ -182,7 +180,7 @@ class Notifier(object):
Notification messages follow the following format:: Notification messages follow the following format::
{'message_id': six.text_type(uuid.uuid4()), {'message_id': str(uuid.uuid4()),
'publisher_id': 'compute.host1', 'publisher_id': 'compute.host1',
'timestamp': timeutils.utcnow(), 'timestamp': timeutils.utcnow(),
'priority': 'WARN', 'priority': 'WARN',
@ -300,12 +298,12 @@ class Notifier(object):
payload = self._serializer.serialize_entity(ctxt, payload) payload = self._serializer.serialize_entity(ctxt, payload)
ctxt = self._serializer.serialize_context(ctxt) ctxt = self._serializer.serialize_context(ctxt)
msg = dict(message_id=six.text_type(uuid.uuid4()), msg = dict(message_id=str(uuid.uuid4()),
publisher_id=publisher_id or self.publisher_id, publisher_id=publisher_id or self.publisher_id,
event_type=event_type, event_type=event_type,
priority=priority, priority=priority,
payload=payload, payload=payload,
timestamp=six.text_type(timeutils.utcnow())) timestamp=str(timeutils.utcnow()))
def do_notify(ext): def do_notify(ext):
try: try:

View File

@ -19,7 +19,6 @@ import abc
import logging import logging
from oslo_config import cfg from oslo_config import cfg
import six
from oslo_messaging._drivers import base as driver_base from oslo_messaging._drivers import base as driver_base
from oslo_messaging import _utils as utils from oslo_messaging import _utils as utils
@ -85,8 +84,7 @@ class ClientSendError(exceptions.MessagingException):
self.ex = ex self.ex = ex
@six.add_metaclass(abc.ABCMeta) class _BaseCallContext(object, metaclass=abc.ABCMeta):
class _BaseCallContext(object):
_marker = object() _marker = object()

View File

@ -22,8 +22,6 @@ import logging
import sys import sys
import threading import threading
import six
from oslo_utils import eventletutils from oslo_utils import eventletutils
from oslo_messaging import _utils as utils from oslo_messaging import _utils as utils
@ -83,8 +81,7 @@ class UnsupportedVersion(RPCDispatcherError):
self.method = method self.method = method
@six.add_metaclass(ABCMeta) class RPCAccessPolicyBase(object, metaclass=ABCMeta):
class RPCAccessPolicyBase(object):
"""Determines which endpoint methods may be invoked via RPC""" """Determines which endpoint methods may be invoked via RPC"""
@abstractmethod @abstractmethod

View File

@ -17,13 +17,11 @@
import abc import abc
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six
__all__ = ['Serializer', 'NoOpSerializer', 'JsonPayloadSerializer'] __all__ = ['Serializer', 'NoOpSerializer', 'JsonPayloadSerializer']
@six.add_metaclass(abc.ABCMeta) class Serializer(object, metaclass=abc.ABCMeta):
class Serializer(object):
"""Generic (de-)serialization definition base class.""" """Generic (de-)serialization definition base class."""
@abc.abstractmethod @abc.abstractmethod

View File

@ -27,7 +27,6 @@ from oslo_config import cfg
from oslo_service import service from oslo_service import service
from oslo_utils import eventletutils from oslo_utils import eventletutils
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from stevedore import driver from stevedore import driver
from oslo_messaging._drivers import base as driver_base from oslo_messaging._drivers import base as driver_base
@ -297,8 +296,8 @@ def ordered(after=None, reset_after=None):
return _ordered return _ordered
@six.add_metaclass(abc.ABCMeta) class MessageHandlingServer(service.ServiceBase, _OrderedTaskRunner,
class MessageHandlingServer(service.ServiceBase, _OrderedTaskRunner): metaclass=abc.ABCMeta):
"""Server for handling messages. """Server for handling messages.
Connect a transport to a dispatcher that knows how to process the Connect a transport to a dispatcher that knows how to process the

View File

@ -19,5 +19,5 @@ eventlet.monkey_patch()
# oslotest prepares mock for six in oslotest/__init__.py as follow: # oslotest prepares mock for six in oslotest/__init__.py as follow:
# six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock')) and # six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock')) and
# oslo.messaging imports oslotest before importing test submodules to # oslo.messaging imports oslotest before importing test submodules to
# setup six.moves for mock, then "from six.moves import mock" works well. # setup six.moves for mock, then "from unittest import mock" works well.
import oslotest import oslotest

View File

@ -15,21 +15,21 @@
import copy import copy
import logging import logging
import os import os
import queue
import select import select
import shlex import shlex
import shutil import shutil
from six.moves import mock
import socket import socket
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import threading import threading
import time import time
from unittest import mock
import uuid import uuid
from oslo_utils import eventletutils from oslo_utils import eventletutils
from oslo_utils import importutils from oslo_utils import importutils
from six import moves
from string import Template from string import Template
import testtools import testtools
@ -74,7 +74,7 @@ class _ListenerThread(threading.Thread):
self.listener = listener self.listener = listener
self.msg_count = msg_count self.msg_count = msg_count
self._msg_ack = msg_ack self._msg_ack = msg_ack
self.messages = moves.queue.Queue() self.messages = queue.Queue()
self.daemon = True self.daemon = True
self.started = eventletutils.Event() self.started = eventletutils.Event()
self._done = eventletutils.Event() self._done = eventletutils.Event()
@ -106,7 +106,7 @@ class _ListenerThread(threading.Thread):
while True: while True:
m = self.messages.get(False) m = self.messages.get(False)
msgs.append(m) msgs.append(m)
except moves.queue.Empty: except queue.Empty:
pass pass
return msgs return msgs

View File

@ -11,8 +11,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves import mock
import testscenarios import testscenarios
from unittest import mock
import oslo_messaging import oslo_messaging
from oslo_messaging._drivers import impl_kafka as kafka_driver from oslo_messaging._drivers import impl_kafka as kafka_driver

View File

@ -32,7 +32,7 @@ from oslo_messaging._drivers import common as driver_common
from oslo_messaging._drivers import impl_rabbit as rabbit_driver from oslo_messaging._drivers import impl_rabbit as rabbit_driver
from oslo_messaging.exceptions import MessageDeliveryFailure from oslo_messaging.exceptions import MessageDeliveryFailure
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -17,7 +17,6 @@ import uuid
import concurrent.futures import concurrent.futures
from oslo_config import cfg from oslo_config import cfg
import six.moves
from testtools import matchers from testtools import matchers
import oslo_messaging import oslo_messaging
@ -535,7 +534,7 @@ class NotifyTestCase(utils.SkipIfNoTransportURL):
batch_timeout=batch_timeout)) batch_timeout=batch_timeout))
notifier = listener.notifier('abc') notifier = listener.notifier('abc')
for i in six.moves.range(0, 205): for i in range(0, 205):
notifier.info({}, 'test%s' % i, 'Hello World!') notifier.info({}, 'test%s' % i, 'Hello World!')
events = listener.get_events(timeout=get_timeout) events = listener.get_events(timeout=get_timeout)
self.assertEqual(3, len(events)) self.assertEqual(3, len(events))

View File

@ -12,12 +12,12 @@
# under the License. # under the License.
import os import os
import queue
import time import time
import uuid import uuid
import fixtures import fixtures
from oslo_config import cfg from oslo_config import cfg
from six import moves
import oslo_messaging import oslo_messaging
from oslo_messaging._drivers.kafka_driver import kafka_options from oslo_messaging._drivers.kafka_driver import kafka_options
@ -102,7 +102,7 @@ class RpcServerFixture(fixtures.Fixture):
self.target = target self.target = target
self.endpoint = endpoint or TestServerEndpoint() self.endpoint = endpoint or TestServerEndpoint()
self.executor = executor self.executor = executor
self.syncq = moves.queue.Queue() self.syncq = queue.Queue()
self.ctrl_target = ctrl_target or self.target self.ctrl_target = ctrl_target or self.target
def setUp(self): def setUp(self):
@ -323,7 +323,7 @@ class NotificationFixture(fixtures.Fixture):
self.conf = conf self.conf = conf
self.url = url self.url = url
self.topics = topics self.topics = topics
self.events = moves.queue.Queue() self.events = queue.Queue()
self.name = str(id(self)) self.name = str(id(self))
self.batch = batch self.batch = batch
@ -395,7 +395,7 @@ class NotificationFixture(fixtures.Fixture):
try: try:
while True: while True:
results.append(self.events.get(timeout=timeout)) results.append(self.events.get(timeout=timeout))
except moves.queue.Empty: except queue.Empty:
pass pass
return results return results

View File

@ -19,7 +19,7 @@ import testscenarios
import oslo_messaging import oslo_messaging
from oslo_messaging.notify import dispatcher as notify_dispatcher from oslo_messaging.notify import dispatcher as notify_dispatcher
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -23,7 +23,7 @@ import oslo_messaging
from oslo_messaging.notify import dispatcher from oslo_messaging.notify import dispatcher
from oslo_messaging.notify import notifier as msg_notifier from oslo_messaging.notify import notifier as msg_notifier
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -17,7 +17,7 @@ import fixtures
import oslo_messaging import oslo_messaging
from oslo_messaging.notify import log_handler from oslo_messaging.notify import log_handler
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
class PublishErrorsHandlerTestCase(test_utils.BaseTestCase): class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):

View File

@ -23,7 +23,7 @@ import testscenarios
import oslo_messaging import oslo_messaging
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -19,7 +19,7 @@ import webob
from oslo_messaging.notify import middleware from oslo_messaging.notify import middleware
from oslo_messaging.tests import utils from oslo_messaging.tests import utils
from six.moves import mock from unittest import mock
class FakeApp(object): class FakeApp(object):

View File

@ -34,7 +34,7 @@ from oslo_messaging.notify import messaging
from oslo_messaging.notify import notifier as msg_notifier from oslo_messaging.notify import notifier as msg_notifier
from oslo_messaging import serializer as msg_serializer from oslo_messaging import serializer as msg_serializer
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -14,8 +14,8 @@
# under the License. # under the License.
from oslo_config import cfg from oslo_config import cfg
from six.moves import mock
import testscenarios import testscenarios
from unittest import mock
import oslo_messaging import oslo_messaging
from oslo_messaging import exceptions from oslo_messaging import exceptions

View File

@ -19,7 +19,7 @@ import oslo_messaging
from oslo_messaging import rpc from oslo_messaging import rpc
from oslo_messaging import serializer as msg_serializer from oslo_messaging import serializer as msg_serializer
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -14,12 +14,13 @@
# under the License. # under the License.
import threading import threading
from unittest import mock
import eventlet import eventlet
import fixtures import fixtures
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import eventletutils from oslo_utils import eventletutils
from six.moves import mock
import testscenarios import testscenarios
import oslo_messaging import oslo_messaging

View File

@ -16,7 +16,6 @@
import sys import sys
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six
import testscenarios import testscenarios
import oslo_messaging import oslo_messaging
@ -25,8 +24,8 @@ from oslo_messaging.tests import utils as test_utils
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios
EXCEPTIONS_MODULE = 'exceptions' if six.PY2 else 'builtins' EXCEPTIONS_MODULE = 'builtins'
OTHER_EXCEPTIONS_MODULE = 'builtins' if six.PY2 else 'exceptions' OTHER_EXCEPTIONS_MODULE = 'exceptions'
class NovaStyleException(Exception): class NovaStyleException(Exception):
@ -289,9 +288,9 @@ class DeserializeRemoteExceptionTestCase(test_utils.BaseTestCase):
self.assertIsInstance(ex, self.cls) self.assertIsInstance(ex, self.cls)
self.assertEqual(self.remote_name, ex.__class__.__name__) self.assertEqual(self.remote_name, ex.__class__.__name__)
self.assertEqual(self.str, six.text_type(ex)) self.assertEqual(self.str, str(ex))
if hasattr(self, 'msg'): if hasattr(self, 'msg'):
self.assertEqual(self.msg, six.text_type(ex)) self.assertEqual(self.msg, str(ex))
self.assertEqual((self.msg,) + self.remote_args, ex.args) self.assertEqual((self.msg,) + self.remote_args, ex.args)
else: else:
self.assertEqual(self.remote_args, ex.args) self.assertEqual(self.remote_args, ex.args)

View File

@ -12,7 +12,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves import mock
from unittest import mock
import stevedore import stevedore
import testtools import testtools

View File

@ -14,9 +14,9 @@
# under the License. # under the License.
import fixtures import fixtures
from unittest import mock
from oslo_config import cfg from oslo_config import cfg
import six
from six.moves import mock
from stevedore import driver from stevedore import driver
import testscenarios import testscenarios
@ -150,7 +150,7 @@ class GetTransportSadPathTestCase(test_utils.BaseTestCase):
ex_msg_contains = self.ex.pop('msg_contains') ex_msg_contains = self.ex.pop('msg_contains')
ex = self.assertRaises( ex = self.assertRaises(
ex_cls, oslo_messaging.get_transport, self.conf, url=self.url) ex_cls, oslo_messaging.get_transport, self.conf, url=self.url)
self.assertIn(ex_msg_contains, six.text_type(ex)) self.assertIn(ex_msg_contains, str(ex))
for k, v in self.ex.items(): for k, v in self.ex.items():
self.assertTrue(hasattr(ex, k)) self.assertTrue(hasattr(ex, k))
self.assertEqual(v, str(getattr(ex, k))) self.assertEqual(v, str(getattr(ex, k)))
@ -172,7 +172,7 @@ class _SetDefaultsFixture(fixtures.Fixture):
def first(seq, default=None, key=None): def first(seq, default=None, key=None):
if key is None: if key is None:
key = bool key = bool
return next(six.moves.filter(key, seq), default) return next(filter(key, seq), default)
def default(opts, name): def default(opts, name):
return first(opts, key=lambda o: o.name == name).default return first(opts, key=lambda o: o.name == name).default

View File

@ -16,7 +16,7 @@
from oslo_messaging._drivers import common from oslo_messaging._drivers import common
from oslo_messaging import _utils as utils from oslo_messaging import _utils as utils
from oslo_messaging.tests import utils as test_utils from oslo_messaging.tests import utils as test_utils
from six.moves import mock from unittest import mock
class VersionIsCompatibleTestCase(test_utils.BaseTestCase): class VersionIsCompatibleTestCase(test_utils.BaseTestCase):

View File

@ -21,9 +21,8 @@ import logging
from debtcollector import removals from debtcollector import removals
from oslo_config import cfg from oslo_config import cfg
import six
from six.moves.urllib import parse
from stevedore import driver from stevedore import driver
from urllib import parse
from oslo_messaging import exceptions from oslo_messaging import exceptions
@ -456,7 +455,7 @@ class TransportURL(object):
conf.register_opts(_transport_opts) conf.register_opts(_transport_opts)
url = url or conf.transport_url url = url or conf.transport_url
if not isinstance(url, six.string_types): if not isinstance(url, str):
raise InvalidTransportURL(url, 'Wrong URL type') raise InvalidTransportURL(url, 'Wrong URL type')
url = parse.urlparse(url) url = parse.urlparse(url)

View File

@ -14,7 +14,6 @@ stevedore>=1.20.0 # Apache-2.0
debtcollector>=1.2.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0
# for jsonutils # for jsonutils
six>=1.10.0 # MIT
cachetools>=2.0.0 # MIT License cachetools>=2.0.0 # MIT License
WebOb>=1.7.1 # MIT WebOb>=1.7.1 # MIT

View File

@ -6,7 +6,6 @@
hacking>=3.0,<3.1.0 # Apache-2.0 hacking>=3.0,<3.1.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD fixtures>=3.0.0 # Apache-2.0/BSD
mock>=2.0.0 # BSD
stestr>=2.0.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0
testscenarios>=0.4 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD
testtools>=2.2.0 # MIT testtools>=2.2.0 # MIT

View File

@ -23,7 +23,6 @@ import logging
import os import os
import random import random
import signal import signal
import six
import socket import socket
import string import string
import sys import sys
@ -139,7 +138,7 @@ class MessageStatsCollector(object):
max_latency = 0 max_latency = 0
sum_latencies = 0 sum_latencies = 0
for i in six.moves.range(count): for i in range(count):
p = self.buffer[i] p = self.buffer[i]
size += len(p.cargo) size += len(p.cargo)
@ -471,10 +470,10 @@ def generate_messages(messages_count):
messages_count = MESSAGES_LIMIT messages_count = MESSAGES_LIMIT
LOG.info("Generating %d random messages", messages_count) LOG.info("Generating %d random messages", messages_count)
generator = init_random_generator() generator = init_random_generator()
for i in six.moves.range(messages_count): for i in range(messages_count):
length = generator() length = generator()
msg = ''.join(random.choice( msg = ''.join(random.choice(
string.ascii_lowercase) for x in six.moves.range(length)) string.ascii_lowercase) for x in range(length))
MESSAGES.append(msg) MESSAGES.append(msg)
LOG.info("Messages has been prepared") LOG.info("Messages has been prepared")
@ -533,7 +532,7 @@ def spawn_rpc_clients(threads, transport, targets, wait_after_msg, timeout,
p = eventlet.GreenPool(size=threads) p = eventlet.GreenPool(size=threads)
targets = itertools.cycle(targets) targets = itertools.cycle(targets)
for i in six.moves.range(threads): for i in range(threads):
target = next(targets) target = next(targets)
LOG.debug("starting RPC client for target %s", target) LOG.debug("starting RPC client for target %s", target)
client_builder = functools.partial(RPCClient, i, transport, target, client_builder = functools.partial(RPCClient, i, transport, target,
@ -548,7 +547,7 @@ def spawn_rpc_clients(threads, transport, targets, wait_after_msg, timeout,
def spawn_notify_clients(threads, topic, transport, message_count, def spawn_notify_clients(threads, topic, transport, message_count,
wait_after_msg, timeout, duration): wait_after_msg, timeout, duration):
p = eventlet.GreenPool(size=threads) p = eventlet.GreenPool(size=threads)
for i in six.moves.range(threads): for i in range(threads):
client_builder = functools.partial(NotifyClient, i, transport, [topic], client_builder = functools.partial(NotifyClient, i, transport, [topic],
wait_after_msg) wait_after_msg)
p.spawn_n(send_messages, i, client_builder, message_count, duration) p.spawn_n(send_messages, i, client_builder, message_count, duration)
@ -574,7 +573,7 @@ def send_messages(client_id, client_builder, messages_count, duration):
else: else:
LOG.debug("Sending %d messages using client %d", LOG.debug("Sending %d messages using client %d",
messages_count, client_id) messages_count, client_id)
for _ in six.moves.range(messages_count): for _ in range(messages_count):
client.send_msg() client.send_msg()
eventlet.sleep() eventlet.sleep()
if not IS_RUNNING: if not IS_RUNNING:

View File

@ -101,12 +101,10 @@ exclude = .tox,dist,doc,*.egg,build,__init__.py
[hacking] [hacking]
import_exceptions = import_exceptions =
six.moves
[flake8:local-plugins] [flake8:local-plugins]
extension = extension =
O321 = checks:check_oslo_namespace_imports O321 = checks:check_oslo_namespace_imports
O322 = checks:check_mock_imports
O324 = checks:CheckForLoggingIssues O324 = checks:CheckForLoggingIssues
paths = ./oslo_messaging/hacking paths = ./oslo_messaging/hacking