3
ñ\ð]0   ã               @   s<   d dl Z d dlmZ G dd„ dejƒZG dd„ dejƒZdS )é    N)Ú	namespacec               @   sf   e Zd ZdZdd„ Zdd„ Zddd„Zdd	d
„Zddd„Zddd„Z	ddd„Z
ddd„Zddd„ZdS )ÚAsyncNamespaceaR  Base class for asyncio server-side class-based namespaces.

    A class-based namespace is a class that contains all the event handlers
    for a Socket.IO namespace. The event handlers are methods of the class
    with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
    ``on_message``, ``on_json``, and so on. These can be regular functions or
    coroutines.

    :param namespace: The Socket.IO namespace to be used with all the event
                      handlers defined in this class. If this argument is
                      omitted, the default namespace is used.
    c             C   s   dS )NT© )Úselfr   r   úE/tmp/pip-build-mqc4i71p/python-socketio/socketio/asyncio_namespace.pyÚis_asyncio_based   s    zAsyncNamespace.is_asyncio_basedc             Ç   sj   d| }t | |ƒrft| |ƒ}tj|ƒdkrZy||Ž I dH }W qb tjk
rV   d}Y qbX n||Ž }|S dS )aŒ  Dispatch an event to the proper handler method.

        In the most common usage, this method is not overloaded by subclasses,
        as it performs the routing of events to methods. However, this
        method can be overriden if special dispatching rules are needed, or if
        having a single method that catches all events is desired.

        Note: this method is a coroutine.
        Úon_TN)ÚhasattrÚgetattrÚasyncioÚiscoroutinefunctionÚCancelledError)r   ÚeventÚargsÚhandler_nameÚhandlerÚretr   r   r   Útrigger_event   s    


zAsyncNamespace.trigger_eventNc             Ã   s$   | j j|||||p| j|d�I dH S )a)  Emit a custom event to one or more connected clients.

        The only difference with the :func:`socketio.Server.emit` method is
        that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )ÚdataÚroomÚskip_sidr   ÚcallbackN)ÚserverÚemitr   )r   r   r   r   r   r   r   r   r   r   r   ,   s    
zAsyncNamespace.emitc             Ã   s"   | j j||||p| j|d�I dH S )a$  Send a message to one or more connected clients.

        The only difference with the :func:`socketio.Server.send` method is
        that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )r   r   r   r   N)r   Úsendr   )r   r   r   r   r   r   r   r   r   r   ;   s    
zAsyncNamespace.sendc             Ã   s   | j j||p| jd�I dH S )a  Close a room.

        The only difference with the :func:`socketio.Server.close_room` method
        is that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )r   N)r   Ú
close_roomr   )r   r   r   r   r   r   r   I   s    	zAsyncNamespace.close_roomc             Ã   s   | j j||p| jd�I dH S )a   Return the user session for a client.

        The only difference with the :func:`socketio.Server.get_session`
        method is that when the ``namespace`` argument is not given the
        namespace associated with the class is used.

        Note: this method is a coroutine.
        )r   N)r   Úget_sessionr   )r   Úsidr   r   r   r   r   U   s    	zAsyncNamespace.get_sessionc             Ã   s   | j j|||p| jd�I dH S )a   Store the user session for a client.

        The only difference with the :func:`socketio.Server.save_session`
        method is that when the ``namespace`` argument is not given the
        namespace associated with the class is used.

        Note: this method is a coroutine.
        )r   N)r   Úsave_sessionr   )r   r   Úsessionr   r   r   r   r   a   s    	zAsyncNamespace.save_sessionc             C   s   | j j||p| jd�S )a  Return the user session for a client with context manager syntax.

        The only difference with the :func:`socketio.Server.session` method is
        that when the ``namespace`` argument is not given the namespace
        associated with the class is used.
        )r   )r   r   r   )r   r   r   r   r   r   r   m   s    zAsyncNamespace.sessionc             Ã   s   | j j||p| jd�I dH S )a  Disconnect a client.

        The only difference with the :func:`socketio.Server.disconnect` method
        is that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )r   N)r   Ú
disconnectr   )r   r   r   r   r   r   r    v   s    	zAsyncNamespace.disconnect)NNNNN)NNNN)N)N)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r    r   r   r   r   r      s    
 




	r   c               @   s<   e Zd ZdZdd„ Zdd„ Zddd„Zdd	d
„Zdd„ ZdS )ÚAsyncClientNamespaceaR  Base class for asyncio client-side class-based namespaces.

    A class-based namespace is a class that contains all the event handlers
    for a Socket.IO namespace. The event handlers are methods of the class
    with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
    ``on_message``, ``on_json``, and so on. These can be regular functions or
    coroutines.

    :param namespace: The Socket.IO namespace to be used with all the event
                      handlers defined in this class. If this argument is
                      omitted, the default namespace is used.
    c             C   s   dS )NTr   )r   r   r   r   r   �   s    z%AsyncClientNamespace.is_asyncio_basedc             Ç   sj   d| }t | |ƒrft| |ƒ}tj|ƒdkrZy||Ž I dH }W qb tjk
rV   d}Y qbX n||Ž }|S dS )aŒ  Dispatch an event to the proper handler method.

        In the most common usage, this method is not overloaded by subclasses,
        as it performs the routing of events to methods. However, this
        method can be overriden if special dispatching rules are needed, or if
        having a single method that catches all events is desired.

        Note: this method is a coroutine.
        r   TN)r	   r
   r   r   r   )r   r   r   r   r   r   r   r   r   r   “   s    


z"AsyncClientNamespace.trigger_eventNc             Ã   s    | j j|||p| j|d�I dH S )a  Emit a custom event to the server.

        The only difference with the :func:`socketio.Client.emit` method is
        that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )r   r   r   N)Úclientr   r   )r   r   r   r   r   r   r   r   r   ©   s    	
zAsyncClientNamespace.emitc             Ã   s   | j j||p| j|d�I dH S )a  Send a message to the server.

        The only difference with the :func:`socketio.Client.send` method is
        that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        )r   r   N)r&   r   r   )r   r   r   r   r   r   r   r   ¶   s    	zAsyncClientNamespace.sendc             Ã   s   | j jƒ I dH S )a  Disconnect a client.

        The only difference with the :func:`socketio.Client.disconnect` method
        is that when the ``namespace`` argument is not given the namespace
        associated with the class is used.

        Note: this method is a coroutine.
        N)r&   r    )r   r   r   r   r    Ã   s    	zAsyncClientNamespace.disconnect)NNN)NN)	r!   r"   r#   r$   r   r   r   r   r    r   r   r   r   r%   ƒ   s   

r%   )r   Zsocketior   Ú	Namespacer   ZClientNamespacer%   r   r   r   r   Ú<module>   s   }