Browse Source

Upgrade the code to more recent Python versions

pull/1426/head
Miguel Grinberg 4 months ago
parent
commit
db642bb2bd
Failed to extract signature
  1. 2
      examples/client/async/latency_client.py
  2. 2
      examples/client/sync/latency_client.py
  3. 2
      examples/simple-client/async/latency_client.py
  4. 2
      examples/simple-client/sync/latency_client.py
  5. 2
      src/socketio/admin.py
  6. 2
      src/socketio/async_client.py
  7. 2
      src/socketio/async_server.py
  8. 3
      src/socketio/base_manager.py
  9. 2
      src/socketio/base_namespace.py
  10. 2
      src/socketio/client.py
  11. 3
      src/socketio/kafka_manager.py
  12. 2
      src/socketio/packet.py
  13. 3
      src/socketio/redis_manager.py
  14. 2
      src/socketio/server.py
  15. 2
      src/socketio/zmq_manager.py
  16. 2
      tests/async/test_manager.py
  17. 4
      tests/async/test_server.py
  18. 2
      tests/common/test_client.py
  19. 2
      tests/common/test_manager.py
  20. 4
      tests/common/test_server.py

2
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()

2
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()

2
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)

2
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)

2
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,

2
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()

2
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

3
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."""

2
src/socketio/base_namespace.py

@ -1,4 +1,4 @@
class BaseNamespace(object):
class BaseNamespace:
def __init__(self, namespace=None):
self.namespace = namespace or '/'

2
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()

3
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():

2
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:

3
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))

2
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

2
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

2
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

4
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 ***'

2
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

2
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]

4
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 ***'

Loading…
Cancel
Save