Skip to content

Commit a9c03bd

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Run pyupgrade to clean up Python 2 syntaxes"
2 parents ff8b6d4 + 34fd61b commit a9c03bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+334
-356
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ repos:
2828
hooks:
2929
- id: bandit
3030
args: ['-x', 'tests,tools']
31+
- repo: https://github.com/asottile/pyupgrade
32+
rev: v3.18.0
33+
hooks:
34+
- id: pyupgrade
35+
args: [--py3-only]

doc/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright (C) 2020 Red Hat, Inc.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License"); you may

oslo_messaging/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Copyright 2013 Red Hat, Inc.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License"); you may

oslo_messaging/_drivers/amqp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RpcContext(rpc_common.CommonRpcContext):
4949
def __init__(self, **kwargs):
5050
self.msg_id = kwargs.pop('msg_id', None)
5151
self.reply_q = kwargs.pop('reply_q', None)
52-
super(RpcContext, self).__init__(**kwargs)
52+
super().__init__(**kwargs)
5353

5454
def deepcopy(self):
5555
values = self.to_dict()
@@ -91,7 +91,7 @@ def pack_context(msg, context):
9191
for (key, value) in context_d)
9292

9393

94-
class _MsgIdCache(object):
94+
class _MsgIdCache:
9595
"""This class checks any duplicate messages."""
9696

9797
# NOTE: This value is considered can be a configuration item, but

oslo_messaging/_drivers/amqp1_driver/addressing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def keyify(address, service=SERVICE_RPC):
6868
return "String:{%s}" % address
6969

7070

71-
class Addresser(object):
71+
class Addresser:
7272
"""Base class message bus address generator. Used to convert an
7373
oslo.messaging address into an AMQP 1.0 address string used over the
7474
connection to the message bus.
@@ -118,7 +118,7 @@ class LegacyAddresser(Addresser):
118118
"""
119119
def __init__(self, default_exchange, server_prefix, broadcast_prefix,
120120
group_prefix, vhost):
121-
super(LegacyAddresser, self).__init__(default_exchange)
121+
super().__init__(default_exchange)
122122
self._server_prefix = server_prefix
123123
self._broadcast_prefix = broadcast_prefix
124124
self._group_prefix = group_prefix
@@ -181,7 +181,7 @@ class RoutableAddresser(Addresser):
181181
def __init__(self, default_exchange, rpc_exchange, rpc_prefix,
182182
notify_exchange, notify_prefix, unicast_tag, multicast_tag,
183183
anycast_tag, vhost):
184-
super(RoutableAddresser, self).__init__(default_exchange)
184+
super().__init__(default_exchange)
185185
if not self._default_exchange:
186186
self._default_exchange = "openstack"
187187

@@ -260,7 +260,7 @@ def _is_service(self, address, service):
260260
else self._notify_prefix)
261261

262262

263-
class AddresserFactory(object):
263+
class AddresserFactory:
264264
"""Generates the proper Addresser based on configuration and the type of
265265
message bus the driver is connected to.
266266
"""

oslo_messaging/_drivers/amqp1_driver/controller.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
LOG = logging.getLogger(__name__)
5353

5454

55-
class Task(object):
55+
class Task:
5656
"""Run a command on the eventloop thread, wait until it completes
5757
"""
5858

@@ -74,7 +74,7 @@ class SubscribeTask(Task):
7474
arriving from the target are given to the listener.
7575
"""
7676
def __init__(self, target, listener, notifications=False):
77-
super(SubscribeTask, self).__init__()
77+
super().__init__()
7878
self._target = target() # mutable - need a copy
7979
self._subscriber_id = listener.id
8080
self._in_queue = listener.incoming
@@ -95,7 +95,7 @@ class SendTask(Task):
9595
"""
9696
def __init__(self, name, message, target, deadline, retry,
9797
wait_for_ack, notification=False):
98-
super(SendTask, self).__init__()
98+
super().__init__()
9999
self.name = name
100100
# note: target can be either a Target class or a string
101101
# target is mutable - make copy
@@ -195,18 +195,18 @@ class RPCCallTask(SendTask):
195195
the destination.
196196
"""
197197
def __init__(self, target, message, deadline, retry, wait_for_ack):
198-
super(RPCCallTask, self).__init__("RPC Call", message, target,
199-
deadline, retry, wait_for_ack)
198+
super().__init__("RPC Call", message, target,
199+
deadline, retry, wait_for_ack)
200200
self._reply_link = None
201201
self._reply_msg = None
202202
self._msg_id = None
203203

204204
def wait(self):
205-
error = super(RPCCallTask, self).wait()
205+
error = super().wait()
206206
return error or self._reply_msg
207207

208208
def _prepare(self, sender):
209-
super(RPCCallTask, self)._prepare(sender)
209+
super()._prepare(sender)
210210
# reserve a message id for mapping the received response
211211
if self._msg_id:
212212
# already set so this is a re-transmit. To be safe cancel the old
@@ -224,15 +224,15 @@ def _on_reply(self, message):
224224

225225
def _on_ack(self, state, info):
226226
if state != pyngus.SenderLink.ACCEPTED:
227-
super(RPCCallTask, self)._on_ack(state, info)
227+
super()._on_ack(state, info)
228228
# must wait for reply if ACCEPTED
229229

230230
def _cleanup(self):
231231
if self._msg_id:
232232
self._reply_link.cancel_response(self._msg_id)
233233
self._msg_id = None
234234
self._reply_link = None
235-
super(RPCCallTask, self)._cleanup()
235+
super()._cleanup()
236236

237237

238238
class RPCMonitoredCallTask(RPCCallTask):
@@ -243,8 +243,8 @@ class RPCMonitoredCallTask(RPCCallTask):
243243
"""
244244
def __init__(self, target, message, deadline, call_monitor_timeout,
245245
retry, wait_for_ack):
246-
super(RPCMonitoredCallTask, self).__init__(target, message, deadline,
247-
retry, wait_for_ack)
246+
super().__init__(target, message, deadline,
247+
retry, wait_for_ack)
248248
assert call_monitor_timeout is not None # nosec
249249
self._monitor_timeout = call_monitor_timeout
250250
self._monitor_timer = None
@@ -254,7 +254,7 @@ def _execute(self, controller):
254254
self._set_alarm = controller.processor.defer
255255
self._monitor_timer = self._set_alarm(self._call_timeout,
256256
self._monitor_timeout)
257-
super(RPCMonitoredCallTask, self)._execute(controller)
257+
super()._execute(controller)
258258

259259
def _call_timeout(self):
260260
# monitor_timeout expired
@@ -274,22 +274,22 @@ def _on_reply(self, message):
274274
self._monitor_timer = self._set_alarm(self._call_timeout,
275275
self._monitor_timeout)
276276
else:
277-
super(RPCMonitoredCallTask, self)._on_reply(message)
277+
super()._on_reply(message)
278278

279279
def _cleanup(self):
280280
self._set_alarm = None
281281
if self._monitor_timer:
282282
self._monitor_timer.cancel()
283283
self._monitor_timer = None
284-
super(RPCMonitoredCallTask, self)._cleanup()
284+
super()._cleanup()
285285

286286

287287
class MessageDispositionTask(Task):
288288
"""A task that updates the message disposition as accepted or released
289289
for a Server
290290
"""
291291
def __init__(self, disposition, released=False):
292-
super(MessageDispositionTask, self).__init__()
292+
super().__init__()
293293
self._disposition = disposition
294294
self._released = released
295295

@@ -311,7 +311,7 @@ class Sender(pyngus.SenderEventHandler):
311311
"""A link for sending to a particular destination on the message bus.
312312
"""
313313
def __init__(self, destination, scheduler, delay, service):
314-
super(Sender, self).__init__()
314+
super().__init__()
315315
self._destination = destination
316316
self._service = service
317317
self._address = None
@@ -537,8 +537,8 @@ def _send_pending(self):
537537
self._send(self._pending_sends.popleft())
538538

539539
def _open_link(self):
540-
name = "openstack.org/om/sender/[%s]/%s" % (self._address,
541-
uuid.uuid4().hex)
540+
name = "openstack.org/om/sender/[{}]/{}".format(self._address,
541+
uuid.uuid4().hex)
542542
link = self._connection.create_sender(name=name,
543543
source_address=self._address,
544544
target_address=self._address,
@@ -685,7 +685,8 @@ def attach(self, connection):
685685
"""
686686
self._connection = connection
687687
for a in self._addresses:
688-
name = "openstack.org/om/receiver/[%s]/%s" % (a, uuid.uuid4().hex)
688+
name = "openstack.org/om/receiver/[{}]/{}".format(
689+
a, uuid.uuid4().hex)
689690
r = self._open_link(a, name)
690691
self._receivers.append(r)
691692

@@ -786,8 +787,8 @@ def _reopen_links(self):
786787
class RPCServer(Server):
787788
"""Subscribes to RPC addresses"""
788789
def __init__(self, target, incoming, scheduler, delay, capacity):
789-
super(RPCServer, self).__init__(target, incoming, scheduler, delay,
790-
capacity)
790+
super().__init__(target, incoming, scheduler, delay,
791+
capacity)
791792

792793
def attach(self, connection, addresser):
793794
# Generate the AMQP 1.0 addresses for the base class
@@ -797,25 +798,25 @@ def attach(self, connection, addresser):
797798
addresser.anycast_address(self._target, SERVICE_RPC)
798799
]
799800
# now invoke the base class with the generated addresses
800-
super(RPCServer, self).attach(connection)
801+
super().attach(connection)
801802

802803

803804
class NotificationServer(Server):
804805
"""Subscribes to Notification addresses"""
805806
def __init__(self, target, incoming, scheduler, delay, capacity):
806-
super(NotificationServer, self).__init__(target, incoming, scheduler,
807-
delay, capacity)
807+
super().__init__(target, incoming, scheduler,
808+
delay, capacity)
808809

809810
def attach(self, connection, addresser):
810811
# Generate the AMQP 1.0 addresses for the base class
811812
self._addresses = [
812813
addresser.anycast_address(self._target, SERVICE_NOTIFY)
813814
]
814815
# now invoke the base class with the generated addresses
815-
super(NotificationServer, self).attach(connection)
816+
super().attach(connection)
816817

817818

818-
class Hosts(object):
819+
class Hosts:
819820
"""An order list of TransportHost addresses. Connection failover progresses
820821
from one host to the next. The default realm comes from the configuration
821822
and is only used if no realm is present in the URL.

oslo_messaging/_drivers/amqp1_driver/eventloop.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def compute_timeout(offset):
4444
return math.ceil(time.monotonic() + offset)
4545

4646

47-
class _SocketConnection(object):
47+
class _SocketConnection:
4848
"""Associates a pyngus Connection with a python network socket,
4949
and handles all connection-related I/O and timer events.
5050
"""
@@ -71,7 +71,7 @@ def read_socket(self):
7171
try:
7272
pyngus.read_socket_input(self.pyngus_conn, self.socket)
7373
self.pyngus_conn.process(time.monotonic())
74-
except (socket.timeout, socket.error) as e:
74+
except (socket.timeout, OSError) as e:
7575
# pyngus handles EAGAIN/EWOULDBLOCK and EINTER
7676
self.pyngus_conn.close_input()
7777
self.pyngus_conn.close_output()
@@ -83,7 +83,7 @@ def write_socket(self):
8383
try:
8484
pyngus.write_socket_output(self.pyngus_conn, self.socket)
8585
self.pyngus_conn.process(time.monotonic())
86-
except (socket.timeout, socket.error) as e:
86+
except (socket.timeout, OSError) as e:
8787
# pyngus handles EAGAIN/EWOULDBLOCK and EINTER
8888
self.pyngus_conn.close_output()
8989
self.pyngus_conn.close_input()
@@ -104,7 +104,7 @@ def connect(self, host):
104104
my_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
105105
try:
106106
my_socket.connect(addr[0][4])
107-
except socket.error as e:
107+
except OSError as e:
108108
if e.errno != errno.EINPROGRESS:
109109
error = "Socket connect failure '%s'" % str(e)
110110
LOG.error("Socket connect failure '%s'", str(e))
@@ -159,10 +159,10 @@ def close(self):
159159
self.socket = None
160160

161161

162-
class Scheduler(object):
162+
class Scheduler:
163163
"""Schedule callables to be run in the future.
164164
"""
165-
class Event(object):
165+
class Event:
166166
# simply hold a reference to a callback that can be set to None if the
167167
# alarm is canceled
168168
def __init__(self, callback):
@@ -229,7 +229,7 @@ def _process(self):
229229
pass
230230

231231

232-
class Requests(object):
232+
class Requests:
233233
"""A queue of callables to execute from the eventloop thread's main
234234
loop.
235235
"""
@@ -273,7 +273,7 @@ class Thread(threading.Thread):
273273
threads.
274274
"""
275275
def __init__(self, container_name, node, command, pid):
276-
super(Thread, self).__init__()
276+
super().__init__()
277277

278278
# callables from other threads:
279279
self._requests = Requests()
@@ -325,7 +325,8 @@ def alarm(self, request, deadline):
325325

326326
def connect(self, host, handler, properties):
327327
"""Get a _SocketConnection to a peer represented by url."""
328-
key = "openstack.org/om/connection/%s:%s/" % (host.hostname, host.port)
328+
key = "openstack.org/om/connection/{}:{}/".format(
329+
host.hostname, host.port)
329330
# return pre-existing
330331
conn = self._container.get_connection(key)
331332
if conn:
@@ -379,7 +380,7 @@ def _main_loop(self):
379380
# and now we wait...
380381
try:
381382
select.select(readfds, writefds, [], timeout)
382-
except select.error as serror:
383+
except OSError as serror:
383384
if serror[0] == errno.EINTR:
384385
LOG.warning("ignoring interrupt from select(): %s",
385386
str(serror))

0 commit comments

Comments
 (0)