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 b5d242b..e7711d8 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 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 9184d02..b41d894 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -366,7 +366,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 91a14d0..b0c2c14 100644 --- a/src/socketio/async_server.py +++ b/src/socketio/async_server.py @@ -382,7 +382,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 905bb1e..1c3809a 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -344,7 +344,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 1830769..8091db2 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 c8bcaa3..246a138 100644 --- a/src/socketio/server.py +++ b/src/socketio/server.py @@ -360,7 +360,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 90d4ad1..9144ba4 100644 --- a/tests/async/test_manager.py +++ b/tests/async/test_manager.py @@ -393,7 +393,7 @@ class TestAsyncManager(unittest.TestCase): 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 471e562..337caac 100644 --- a/tests/async/test_server.py +++ b/tests/async/test_server.py @@ -966,7 +966,7 @@ class TestAsyncServer(unittest.TestCase): 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 @@ class TestAsyncServer(unittest.TestCase): # 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 d1fcf8e..430f20d 100644 --- a/tests/common/test_client.py +++ b/tests/common/test_client.py @@ -145,7 +145,7 @@ class TestClient(unittest.TestCase): 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 8bb826a..d15b563 100644 --- a/tests/common/test_manager.py +++ b/tests/common/test_manager.py @@ -342,7 +342,7 @@ class TestBaseManager(unittest.TestCase): 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 b568c68..25715cb 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -877,7 +877,7 @@ class TestServer(unittest.TestCase): 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 @@ class TestServer(unittest.TestCase): # 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 ***'