diff --git a/examples/client/async/latency_client.py b/examples/client/async/latency_client.py index 00d2539..8f39549 100644 --- a/examples/client/async/latency_client.py +++ b/examples/client/async/latency_client.py @@ -23,7 +23,7 @@ async def connect(): async def pong_from_server(): global start_timer latency = time.time() - start_timer - print('latency is {0:.2f} ms'.format(latency * 1000)) + print(f'latency is {latency * 1000:.2f} ms') await sio.sleep(1) if sio.connected: await send_ping() diff --git a/examples/client/sync/latency_client.py b/examples/client/sync/latency_client.py index 0328d10..240d214 100644 --- a/examples/client/sync/latency_client.py +++ b/examples/client/sync/latency_client.py @@ -21,7 +21,7 @@ def connect(): def pong_from_server(): global start_timer latency = time.time() - start_timer - print('latency is {0:.2f} ms'.format(latency * 1000)) + print(f'latency is {latency * 1000:.2f} ms') sio.sleep(1) if sio.connected: send_ping() diff --git a/examples/simple-client/async/latency_client.py b/examples/simple-client/async/latency_client.py index 96387c6..8d69a85 100644 --- a/examples/simple-client/async/latency_client.py +++ b/examples/simple-client/async/latency_client.py @@ -12,7 +12,7 @@ async def main(): while (await sio.receive()) != ['pong_from_server']: pass latency = time.time() - start_timer - print('latency is {0:.2f} ms'.format(latency * 1000)) + print(f'latency is {latency * 1000:.2f} ms') await asyncio.sleep(1) diff --git a/examples/simple-client/sync/latency_client.py b/examples/simple-client/sync/latency_client.py index d5cd853..c4dea11 100644 --- a/examples/simple-client/sync/latency_client.py +++ b/examples/simple-client/sync/latency_client.py @@ -11,7 +11,7 @@ def main(): while sio.receive() != ['pong_from_server']: pass latency = time.time() - start_timer - print('latency is {0:.2f} ms'.format(latency * 1000)) + print(f'latency is {latency * 1000:.2f} ms') time.sleep(1) diff --git a/src/socketio/admin.py b/src/socketio/admin.py index f317ea2..58c8aff 100644 --- a/src/socketio/admin.py +++ b/src/socketio/admin.py @@ -16,7 +16,7 @@ class EventBuffer: def push(self, type, count=1): timestamp = int(time.time()) * 1000 - key = '{};{}'.format(timestamp, type) + key = f'{timestamp};{type}' if key not in self.buffer: self.buffer[key] = { 'timestamp': timestamp, diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index e79fce0..7bfd1ac 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -386,7 +386,7 @@ class AsyncClient(base_client.BaseClient): async def _handle_connect(self, namespace, data): namespace = namespace or '/' if namespace not in self.namespaces: - self.logger.info('Namespace {} is connected'.format(namespace)) + self.logger.info(f'Namespace {namespace} is connected') self.namespaces[namespace] = (data or {}).get('sid', self.sid) await self._trigger_event('connect', namespace=namespace) self._connect_event.set() diff --git a/src/socketio/async_server.py b/src/socketio/async_server.py index 1e523ff..9b0e977 100644 --- a/src/socketio/async_server.py +++ b/src/socketio/async_server.py @@ -385,7 +385,7 @@ class AsyncServer(base_server.BaseServer): async with eio.session(sid) as session: print('received message from ', session['username']) """ - class _session_context_manager(object): + class _session_context_manager: def __init__(self, server, sid, namespace): self.server = server self.sid = sid diff --git a/src/socketio/base_manager.py b/src/socketio/base_manager.py index ca4b0b9..dafa60a 100644 --- a/src/socketio/base_manager.py +++ b/src/socketio/base_manager.py @@ -37,8 +37,7 @@ class BaseManager: participants.update(ns[r]._fwdm if r in ns else {}) else: participants = ns[room]._fwdm.copy() if room in ns else {} - for sid, eio_sid in participants.items(): - yield sid, eio_sid + yield from participants.items() def connect(self, eio_sid, namespace): """Register a client connection to a namespace.""" diff --git a/src/socketio/base_namespace.py b/src/socketio/base_namespace.py index 354f75a..14b5d8f 100644 --- a/src/socketio/base_namespace.py +++ b/src/socketio/base_namespace.py @@ -1,4 +1,4 @@ -class BaseNamespace(object): +class BaseNamespace: def __init__(self, namespace=None): self.namespace = namespace or '/' diff --git a/src/socketio/client.py b/src/socketio/client.py index d7af407..b5fa0b4 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -363,7 +363,7 @@ class Client(base_client.BaseClient): def _handle_connect(self, namespace, data): namespace = namespace or '/' if namespace not in self.namespaces: - self.logger.info('Namespace {} is connected'.format(namespace)) + self.logger.info(f'Namespace {namespace} is connected') self.namespaces[namespace] = (data or {}).get('sid', self.sid) self._trigger_event('connect', namespace=namespace) self._connect_event.set() diff --git a/src/socketio/kafka_manager.py b/src/socketio/kafka_manager.py index 4d87d46..11b87ad 100644 --- a/src/socketio/kafka_manager.py +++ b/src/socketio/kafka_manager.py @@ -57,8 +57,7 @@ class KafkaManager(PubSubManager): # pragma: no cover self.producer.flush() def _kafka_listen(self): - for message in self.consumer: - yield message + yield from self.consumer def _listen(self): for message in self._kafka_listen(): diff --git a/src/socketio/packet.py b/src/socketio/packet.py index ec1b364..f7ad87e 100644 --- a/src/socketio/packet.py +++ b/src/socketio/packet.py @@ -7,7 +7,7 @@ packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERROR', 'BINARY_EVENT', 'BINARY_ACK'] -class Packet(object): +class Packet: """Socket.IO packet.""" # the format of the Socket.IO packet is as follows: diff --git a/src/socketio/redis_manager.py b/src/socketio/redis_manager.py index ae9fa29..a16fb2c 100644 --- a/src/socketio/redis_manager.py +++ b/src/socketio/redis_manager.py @@ -94,8 +94,7 @@ class RedisManager(PubSubManager): # pragma: no cover self._redis_connect() self.pubsub.subscribe(self.channel) retry_sleep = 1 - for message in self.pubsub.listen(): - yield message + yield from self.pubsub.listen() except redis.exceptions.RedisError: logger.error('Cannot receive from redis... ' 'retrying in {} secs'.format(retry_sleep)) diff --git a/src/socketio/server.py b/src/socketio/server.py index 883b37a..ae73df6 100644 --- a/src/socketio/server.py +++ b/src/socketio/server.py @@ -363,7 +363,7 @@ class Server(base_server.BaseServer): with sio.session(sid) as session: print('received message from ', session['username']) """ - class _session_context_manager(object): + class _session_context_manager: def __init__(self, server, sid, namespace): self.server = server self.sid = sid diff --git a/src/socketio/zmq_manager.py b/src/socketio/zmq_manager.py index 760fbc3..468dc26 100644 --- a/src/socketio/zmq_manager.py +++ b/src/socketio/zmq_manager.py @@ -66,7 +66,7 @@ class ZmqManager(PubSubManager): # pragma: no cover sink.connect(sink_url) sub = zmq.Context().socket(zmq.SUB) - sub.setsockopt_string(zmq.SUBSCRIBE, u'') + sub.setsockopt_string(zmq.SUBSCRIBE, '') sub.connect(sub_url) self.sink = sink diff --git a/tests/async/test_manager.py b/tests/async/test_manager.py index 5d60e03..77b9bdb 100644 --- a/tests/async/test_manager.py +++ b/tests/async/test_manager.py @@ -392,7 +392,7 @@ class TestAsyncManager: sid = _run(self.bm.connect('123', '/')) _run( self.bm.emit( - u'my event', b'my binary data', namespace='/', room=sid + 'my event', b'my binary data', namespace='/', room=sid ) ) assert self.bm.server._send_eio_packet.await_count == 2 diff --git a/tests/async/test_server.py b/tests/async/test_server.py index 704982b..b2de48a 100644 --- a/tests/async/test_server.py +++ b/tests/async/test_server.py @@ -963,7 +963,7 @@ class TestAsyncServer: assert result['result'] == ('disconnect', '1', '/foo') def test_bad_namespace_handler(self, eio): - class Dummy(object): + class Dummy: pass class SyncNS(namespace.Namespace): @@ -1004,7 +1004,7 @@ class TestAsyncServer: # Warning: this test cannot run in parallel with other tests, as it # changes the JSON encoding/decoding functions - class CustomJSON(object): + class CustomJSON: @staticmethod def dumps(*args, **kwargs): return '*** encoded ***' diff --git a/tests/common/test_client.py b/tests/common/test_client.py index c7de4b9..c7399dc 100644 --- a/tests/common/test_client.py +++ b/tests/common/test_client.py @@ -145,7 +145,7 @@ class TestClient: assert c.namespace_handlers['/foo'] == n def test_namespace_handler_wrong_class(self): - class MyNamespace(object): + class MyNamespace: def __init__(self, n): pass diff --git a/tests/common/test_manager.py b/tests/common/test_manager.py index 65ed1cb..5634c8a 100644 --- a/tests/common/test_manager.py +++ b/tests/common/test_manager.py @@ -341,7 +341,7 @@ class TestBaseManager: def test_emit_binary(self): sid = self.bm.connect('123', '/') - self.bm.emit(u'my event', b'my binary data', namespace='/', room=sid) + self.bm.emit('my event', b'my binary data', namespace='/', room=sid) assert self.bm.server._send_eio_packet.call_count == 2 assert self.bm.server._send_eio_packet.call_args_list[0][0][0] == '123' pkt = self.bm.server._send_eio_packet.call_args_list[0][0][1] diff --git a/tests/common/test_server.py b/tests/common/test_server.py index e6b02e5..57ddc2f 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -885,7 +885,7 @@ class TestServer: assert result['result'] == ('disconnect', '1', '/foo') def test_bad_namespace_handler(self, eio): - class Dummy(object): + class Dummy: pass class AsyncNS(namespace.Namespace): @@ -947,7 +947,7 @@ class TestServer: # Warning: this test cannot run in parallel with other tests, as it # changes the JSON encoding/decoding functions - class CustomJSON(object): + class CustomJSON: @staticmethod def dumps(*args, **kwargs): return '*** encoded ***'