Browse Source

Address deprecations

pull/1542/head
Miguel Grinberg 6 months ago
parent
commit
b235699d9b
Failed to extract signature
  1. 3
      src/socketio/async_admin.py
  2. 7
      src/socketio/async_client.py
  3. 3
      src/socketio/async_manager.py
  4. 5
      src/socketio/async_namespace.py
  5. 3
      src/socketio/async_server.py

3
src/socketio/async_admin.py

@ -1,6 +1,7 @@
import asyncio import asyncio
from datetime import datetime, timezone from datetime import datetime, timezone
import functools import functools
import inspect
import os import os
import socket import socket
import time import time
@ -124,7 +125,7 @@ class InstrumentedAsyncServer:
elif isinstance(self.auth, list): elif isinstance(self.auth, list):
authenticated = client_auth in self.auth authenticated = client_auth in self.auth
else: else:
if asyncio.iscoroutinefunction(self.auth): if inspect.iscoroutinefunction(self.auth):
authenticated = await self.auth(client_auth) authenticated = await self.auth(client_auth)
else: else:
authenticated = self.auth(client_auth) authenticated = self.auth(client_auth)

7
src/socketio/async_client.py

@ -1,4 +1,5 @@
import asyncio import asyncio
import inspect
import logging import logging
import random import random
@ -375,7 +376,7 @@ class AsyncClient(base_client.BaseClient):
callables.""" callables."""
if not callable(value): if not callable(value):
return value return value
if asyncio.iscoroutinefunction(value): if inspect.iscoroutinefunction(value):
return await value() return await value()
return value() return value()
@ -437,7 +438,7 @@ class AsyncClient(base_client.BaseClient):
else: else:
del self.callbacks[namespace][id] del self.callbacks[namespace][id]
if callback is not None: if callback is not None:
if asyncio.iscoroutinefunction(callback): if inspect.iscoroutinefunction(callback):
await callback(*data) await callback(*data)
else: else:
callback(*data) callback(*data)
@ -464,7 +465,7 @@ class AsyncClient(base_client.BaseClient):
# first see if we have an explicit handler for the event # first see if we have an explicit handler for the event
handler, args = self._get_event_handler(event, namespace, args) handler, args = self._get_event_handler(event, namespace, args)
if handler: if handler:
if asyncio.iscoroutinefunction(handler): if inspect.iscoroutinefunction(handler):
try: try:
try: try:
ret = await handler(*args) ret = await handler(*args)

3
src/socketio/async_manager.py

@ -1,4 +1,5 @@
import asyncio import asyncio
import inspect
from engineio import packet as eio_packet from engineio import packet as eio_packet
from socketio import packet from socketio import packet
@ -113,7 +114,7 @@ class AsyncManager(BaseManager):
del self.callbacks[sid][id] del self.callbacks[sid][id]
if callback is not None: if callback is not None:
ret = callback(*data) ret = callback(*data)
if asyncio.iscoroutine(ret): if inspect.iscoroutine(ret):
try: try:
await ret await ret
except asyncio.CancelledError: # pragma: no cover except asyncio.CancelledError: # pragma: no cover

5
src/socketio/async_namespace.py

@ -1,4 +1,5 @@
import asyncio import asyncio
import inspect
from socketio import base_namespace from socketio import base_namespace
@ -32,7 +33,7 @@ class AsyncNamespace(base_namespace.BaseServerNamespace):
handler_name = 'on_' + (event or '') handler_name = 'on_' + (event or '')
if hasattr(self, handler_name): if hasattr(self, handler_name):
handler = getattr(self, handler_name) handler = getattr(self, handler_name)
if asyncio.iscoroutinefunction(handler) is True: if inspect.iscoroutinefunction(handler) is True:
try: try:
try: try:
ret = await handler(*args) ret = await handler(*args)
@ -213,7 +214,7 @@ class AsyncClientNamespace(base_namespace.BaseClientNamespace):
handler_name = 'on_' + (event or '') handler_name = 'on_' + (event or '')
if hasattr(self, handler_name): if hasattr(self, handler_name):
handler = getattr(self, handler_name) handler = getattr(self, handler_name)
if asyncio.iscoroutinefunction(handler) is True: if inspect.iscoroutinefunction(handler) is True:
try: try:
try: try:
ret = await handler(*args) ret = await handler(*args)

3
src/socketio/async_server.py

@ -1,4 +1,5 @@
import asyncio import asyncio
import inspect
import engineio import engineio
@ -637,7 +638,7 @@ class AsyncServer(base_server.BaseServer):
# first see if we have an explicit handler for the event # first see if we have an explicit handler for the event
handler, args = self._get_event_handler(event, namespace, args) handler, args = self._get_event_handler(event, namespace, args)
if handler: if handler:
if asyncio.iscoroutinefunction(handler): if inspect.iscoroutinefunction(handler):
try: try:
try: try:
ret = await handler(*args) ret = await handler(*args)

Loading…
Cancel
Save