From 38aff62f7433e07874a791123a8b046db2332fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Fri, 15 Mar 2024 18:35:25 +0000 Subject: [PATCH] really from python<=3.7 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Filter all module code over `pyupgrade --py36`. Signed-off-by: Tomasz Kłoczko --- docs/conf.py | 1 - examples/client/async/latency_client.py | 2 +- examples/client/sync/latency_client.py | 2 +- examples/simple-client/async/latency_client.py | 2 +- examples/simple-client/sync/latency_client.py | 2 +- src/socketio/admin.py | 2 +- src/socketio/async_client.py | 2 +- src/socketio/async_server.py | 2 +- src/socketio/base_manager.py | 3 +-- src/socketio/base_namespace.py | 2 +- src/socketio/client.py | 2 +- src/socketio/kafka_manager.py | 3 +-- src/socketio/packet.py | 2 +- src/socketio/redis_manager.py | 3 +-- src/socketio/server.py | 2 +- src/socketio/zmq_manager.py | 2 +- tests/async/test_manager.py | 2 +- tests/async/test_server.py | 4 ++-- tests/common/test_client.py | 2 +- tests/common/test_manager.py | 2 +- tests/common/test_server.py | 4 ++-- 21 files changed, 22 insertions(+), 26 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b5d242bc..e7711d8b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # diff --git a/examples/client/async/latency_client.py b/examples/client/async/latency_client.py index 00d25392..8f39549b 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 0328d100..240d214c 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 96387c65..8d69a850 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 d5cd853e..c4dea110 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 f317ea26..58c8aff9 100644 --- a/src/socketio/admin.py +++ b/src/socketio/admin.py @@ -16,7 +16,7 @@ def __init__(self): 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 9184d029..b41d894c 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -366,7 +366,7 @@ async def _send_packet(self, pkt): 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 91a14d06..b0c2c148 100644 --- a/src/socketio/async_server.py +++ b/src/socketio/async_server.py @@ -382,7 +382,7 @@ def on_message(sid, msg): 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 ca4b0b95..dafa60ac 100644 --- a/src/socketio/base_manager.py +++ b/src/socketio/base_manager.py @@ -37,8 +37,7 @@ def get_participants(self, namespace, room): 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 354f75ac..14b5d8fb 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 905bb1e2..1c3809ab 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -344,7 +344,7 @@ def _send_packet(self, pkt): 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 4d87d46f..11b87ad8 100644 --- a/src/socketio/kafka_manager.py +++ b/src/socketio/kafka_manager.py @@ -57,8 +57,7 @@ def _publish(self, data): 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 18307694..8091db24 100644 --- a/src/socketio/packet.py +++ b/src/socketio/packet.py @@ -7,7 +7,7 @@ '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 ae9fa292..a16fb2c7 100644 --- a/src/socketio/redis_manager.py +++ b/src/socketio/redis_manager.py @@ -94,8 +94,7 @@ def _redis_listen_with_retries(self): 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 c8bcaa33..246a138d 100644 --- a/src/socketio/server.py +++ b/src/socketio/server.py @@ -360,7 +360,7 @@ def on_message(sid, msg): 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 760fbc38..468dc268 100644 --- a/src/socketio/zmq_manager.py +++ b/src/socketio/zmq_manager.py @@ -66,7 +66,7 @@ def __init__(self, url='zmq+tcp://localhost:5555+5556', 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 90d4ad1d..9144ba48 100644 --- a/tests/async/test_manager.py +++ b/tests/async/test_manager.py @@ -393,7 +393,7 @@ def test_emit_binary(self): 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.mock.call_count == 2 diff --git a/tests/async/test_server.py b/tests/async/test_server.py index 471e562a..337caac6 100644 --- a/tests/async/test_server.py +++ b/tests/async/test_server.py @@ -966,7 +966,7 @@ async def on_baz(self, ns, sid, data1, data2): assert result['result'] == ('disconnect', '1', '/foo') def test_bad_namespace_handler(self, eio): - class Dummy(object): + class Dummy: pass class SyncNS(namespace.Namespace): @@ -1007,7 +1007,7 @@ def test_custom_json(self, eio): # 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 d1fcf8e3..430f20de 100644 --- a/tests/common/test_client.py +++ b/tests/common/test_client.py @@ -145,7 +145,7 @@ class MyNamespace(namespace.ClientNamespace): 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 8bb826a5..d15b5638 100644 --- a/tests/common/test_manager.py +++ b/tests/common/test_manager.py @@ -342,7 +342,7 @@ def test_emit_with_none(self): 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 b568c683..25715cb4 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -877,7 +877,7 @@ def on_baz(self, ns, sid, data1, data2): assert result['result'] == ('disconnect', '1', '/foo') def test_bad_namespace_handler(self, eio): - class Dummy(object): + class Dummy: pass class AsyncNS(namespace.Namespace): @@ -939,7 +939,7 @@ def test_custom_json(self, eio): # 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 ***'