Browse Source

Address deprecations

pull/1542/head
Miguel Grinberg 5 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
from datetime import datetime, timezone
import functools
import inspect
import os
import socket
import time
@ -124,7 +125,7 @@ class InstrumentedAsyncServer:
elif isinstance(self.auth, list):
authenticated = client_auth in self.auth
else:
if asyncio.iscoroutinefunction(self.auth):
if inspect.iscoroutinefunction(self.auth):
authenticated = await self.auth(client_auth)
else:
authenticated = self.auth(client_auth)

7
src/socketio/async_client.py

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

3
src/socketio/async_manager.py

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

5
src/socketio/async_namespace.py

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

3
src/socketio/async_server.py

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

Loading…
Cancel
Save