Skip to content

Commit

Permalink
Internal code restructure (no functional changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 4, 2023
1 parent d222f4c commit ef0f88f
Show file tree
Hide file tree
Showing 32 changed files with 864 additions and 838 deletions.
79 changes: 12 additions & 67 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,141 +6,86 @@ API Reference

.. module:: socketio

``SimpleClient`` class
----------------------

.. autoclass:: SimpleClient
:members:

``AsyncSimpleClient`` class
---------------------------
:inherited-members:

.. autoclass:: AsyncSimpleClient
:members:

``Client`` class
----------------
:inherited-members:

.. autoclass:: Client
:members:

``AsyncClient`` class
---------------------
:inherited-members:

.. autoclass:: AsyncClient
:members:
:inherited-members:

``Server`` class
----------------

.. autoclass:: Server
:members:

``AsyncServer`` class
---------------------
:inherited-members:

.. autoclass:: AsyncServer
:members:
:inherited-members:

``ConnectionRefusedError`` class
--------------------------------

.. autoclass:: socketio.exceptions.ConnectionRefusedError
:members:

``WSGIApp`` class
-----------------

.. autoclass:: WSGIApp
:members:

``ASGIApp`` class
-----------------

.. autoclass:: ASGIApp
:members:

``Middleware`` class (deprecated)
---------------------------------

.. autoclass:: Middleware
:members:

``ClientNamespace`` class
-------------------------

.. autoclass:: ClientNamespace
:members:
:inherited-members:

``Namespace`` class
-------------------

.. autoclass:: Namespace
:members:
:inherited-members:

``AsyncClientNamespace`` class
------------------------------

.. autoclass:: AsyncClientNamespace
:members:
:inherited-members:

``AsyncNamespace`` class
------------------------

.. autoclass:: AsyncNamespace
:members:
:inherited-members:

``BaseManager`` class
---------------------

.. autoclass:: BaseManager
.. autoclass:: Manager
:members:

``PubSubManager`` class
-----------------------
:inherited-members:

.. autoclass:: PubSubManager
:members:

``KombuManager`` class
----------------------
:inherited-members:

.. autoclass:: KombuManager
:members:

``RedisManager`` class
----------------------
:inherited-members:

.. autoclass:: RedisManager
:members:

``KafkaManager`` class
----------------------
:inherited-members:

.. autoclass:: KafkaManager
:members:

``AsyncManager`` class
----------------------
:inherited-members:

.. autoclass:: AsyncManager
:members:
:inherited-members:

``AsyncRedisManager`` class
---------------------------

.. autoclass:: AsyncRedisManager
:members:

``AsyncAioPikaManager`` class
-----------------------------
:inherited-members:

.. autoclass:: AsyncAioPikaManager
:members:
:inherited-members:
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'sphinx.ext.autodoc',
]

autodoc_member_order = 'bysource'
autodoc_member_order = 'alphabetical'

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -61,7 +61,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
42 changes: 15 additions & 27 deletions src/socketio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sys

from .client import Client
from .simple_client import SimpleClient
from .base_manager import BaseManager
from .manager import Manager
from .pubsub_manager import PubSubManager
from .kombu_manager import KombuManager
from .redis_manager import RedisManager
Expand All @@ -12,29 +10,19 @@
from .namespace import Namespace, ClientNamespace
from .middleware import WSGIApp, Middleware
from .tornado import get_tornado_handler
if sys.version_info >= (3, 5): # pragma: no cover
from .asyncio_client import AsyncClient
from .asyncio_simple_client import AsyncSimpleClient
from .asyncio_server import AsyncServer
from .asyncio_manager import AsyncManager
from .asyncio_namespace import AsyncNamespace, AsyncClientNamespace
from .asyncio_redis_manager import AsyncRedisManager
from .asyncio_aiopika_manager import AsyncAioPikaManager
from .asgi import ASGIApp
else: # pragma: no cover
AsyncSimpleClient = None
AsyncClient = None
AsyncServer = None
AsyncManager = None
AsyncNamespace = None
AsyncRedisManager = None
AsyncAioPikaManager = None
from .async_client import AsyncClient
from .async_simple_client import AsyncSimpleClient
from .async_server import AsyncServer
from .async_manager import AsyncManager
from .async_namespace import AsyncNamespace, AsyncClientNamespace
from .async_redis_manager import AsyncRedisManager
from .async_aiopika_manager import AsyncAioPikaManager
from .asgi import ASGIApp

__all__ = ['SimpleClient', 'Client', 'Server', 'BaseManager', 'PubSubManager',
__all__ = ['SimpleClient', 'Client', 'Server', 'Manager', 'PubSubManager',
'KombuManager', 'RedisManager', 'ZmqManager', 'KafkaManager',
'Namespace', 'ClientNamespace', 'WSGIApp', 'Middleware']
if AsyncServer is not None: # pragma: no cover
__all__ += ['AsyncSimpleClient', 'AsyncClient', 'AsyncServer',
'AsyncNamespace', 'AsyncClientNamespace', 'AsyncManager',
'AsyncRedisManager', 'ASGIApp', 'get_tornado_handler',
'AsyncAioPikaManager']
'Namespace', 'ClientNamespace', 'WSGIApp', 'Middleware',
'AsyncSimpleClient', 'AsyncClient', 'AsyncServer',
'AsyncNamespace', 'AsyncClientNamespace', 'AsyncManager',
'AsyncRedisManager', 'ASGIApp', 'get_tornado_handler',
'AsyncAioPikaManager']
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import pickle

from socketio.asyncio_pubsub_manager import AsyncPubSubManager
from .async_pubsub_manager import AsyncPubSubManager

try:
import aio_pika
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import engineio

from . import client
from . import base_client
from . import exceptions
from . import packet

default_logger = logging.getLogger('socketio.client')


class AsyncClient(client.Client):
class AsyncClient(base_client.BaseClient):
"""A Socket.IO client for asyncio.
This class implements a fully compliant Socket.IO web client with support
Expand Down Expand Up @@ -456,7 +456,7 @@ async def _handle_reconnect(self):
if self._reconnect_abort is None: # pragma: no cover
self._reconnect_abort = self.eio.create_event()
self._reconnect_abort.clear()
client.reconnecting_clients.append(self)
base_client.reconnecting_clients.append(self)
attempt_count = 0
current_delay = self.reconnection_delay
while True:
Expand Down Expand Up @@ -499,7 +499,7 @@ async def _handle_reconnect(self):
await self._trigger_event('__disconnect_final',
namespace=n)
break
client.reconnecting_clients.remove(self)
base_client.reconnecting_clients.remove(self)

async def _handle_eio_connect(self):
"""Handle the Engine.IO connection event."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ async def disconnect(self, sid, namespace, **kwargs):
Note: this method is a coroutine.
"""
return super().disconnect(sid, namespace, **kwargs)
return self.basic_disconnect(sid, namespace, **kwargs)

async def enter_room(self, sid, namespace, room, eio_sid=None):
"""Add a client to a room.
Note: this method is a coroutine.
"""
return super().enter_room(sid, namespace, room, eio_sid=eio_sid)
return self.basic_enter_room(sid, namespace, room, eio_sid=eio_sid)

async def leave_room(self, sid, namespace, room):
"""Remove a client from a room.
Note: this method is a coroutine.
"""
return super().leave_room(sid, namespace, room)
return self.basic_leave_room(sid, namespace, room)

async def close_room(self, room, namespace):
"""Remove all participants from a room.
Note: this method is a coroutine.
"""
return super().close_room(room, namespace)
return self.basic_close_room(room, namespace)

async def trigger_callback(self, sid, id, data):
"""Invoke an application callback.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio

from socketio import namespace
from socketio import base_namespace


class AsyncNamespace(namespace.Namespace):
class AsyncNamespace(base_namespace.BaseServerNamespace):
"""Base class for asyncio server-side class-based namespaces.
A class-based namespace is a class that contains all the event handlers
Expand Down Expand Up @@ -168,7 +168,7 @@ async def disconnect(self, sid, namespace=None):
sid, namespace=namespace or self.namespace)


class AsyncClientNamespace(namespace.ClientNamespace):
class AsyncClientNamespace(base_namespace.BaseClientNamespace):
"""Base class for asyncio client-side class-based namespaces.
A class-based namespace is a class that contains all the event handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from engineio import json
import pickle

from .asyncio_manager import AsyncManager
from .async_manager import AsyncManager


class AsyncPubSubManager(AsyncManager):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
aioredis = None
RedisError = None

from .asyncio_pubsub_manager import AsyncPubSubManager
from .async_pubsub_manager import AsyncPubSubManager


class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import engineio

from . import asyncio_manager
from . import async_manager
from . import base_server
from . import exceptions
from . import packet
from . import server


class AsyncServer(server.Server):
class AsyncServer(base_server.BaseServer):
"""A Socket.IO server for asyncio.
This class implements a fully compliant Socket.IO web server with support
Expand Down Expand Up @@ -104,7 +104,7 @@ class AsyncServer(server.Server):
def __init__(self, client_manager=None, logger=False, json=None,
async_handlers=True, namespaces=None, **kwargs):
if client_manager is None:
client_manager = asyncio_manager.AsyncManager()
client_manager = async_manager.AsyncManager()
super().__init__(client_manager=client_manager, logger=logger,
json=json, async_handlers=async_handlers,
namespaces=namespaces, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def disconnect(self):
"""Disconnect from the server.
Note: this method is a coroutine.
i """
"""
if self.connected:
await self.client.disconnect()
self.client = None
Expand Down

0 comments on commit ef0f88f

Please sign in to comment.