
    _f                         d dl Z d dlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d	 Z G d
 d          Z G d de          ZdS )    N)async_to_sync   )DEFAULT_CHANNEL_LAYER)database_sync_to_async)StopConsumer)get_channel_layer)await_many_dispatchc                     d| vrt          d          | d                             dd          }|                    d          rt          d          |S )zl
    Looks at a message, checks it has a sensible type, and returns the
    handler name for that type.
    typez(Incoming message has no 'type' attribute._z.Malformed type in message (leading underscore))
ValueErrorreplace
startswith)messagehandler_names     C/var/www/html/env/lib/python3.11/site-packages/channels/consumer.pyget_handler_namer      sc     WCDDD6?**344Ls## KIJJJ    c                   B    e Zd ZdZdZeZd Zd Zd Z	e
d             ZdS )AsyncConsumerz
    Base consumer class. Implements the ASGI application spec, and adds on
    channel layer management and routing of events to named methods based
    on their type.
    Fc                   K   || _         t          | j                  | _        | j        M| j                                         d{V | _        t          j        | j        j        | j                  | _	        | j
        rt          |          | _        n|| _        	 | j        $t          || j	        g| j                   d{V  dS t          |g| j                   d{V  dS # t          $ r Y dS w xY w)U
        Dispatches incoming messages to type-based handlers asynchronously.
        N)scoper   channel_layer_aliaschannel_layernew_channelchannel_name	functoolspartialreceivechannel_receive_syncr   	base_sendr	   dispatchr   )selfr   r!   sends       r   __call__zAsyncConsumer.__call__%   sD      
 /t/GHH)&*&8&D&D&F&F F F F F F FD#,#4"*D,=$ $D  : 	"*400DNN!DN		!-)d23T]           *7)T]CCCCCCCCCCC 	 	 	DD	s   )C$ C$ $
C21C2c                    K   t          | t          |          d          }|r ||           d{V  dS t          d|d         z            )z6
        Works out what to do with a message.
        NNo handler for message type %sr   getattrr   r   r&   r   handlers      r   r%   zAsyncConsumer.dispatchC   sk       $ 0 9 94@@ 	Q''"""""""""""=OPPPr   c                 @   K   |                      |           d{V  dS zB
        Overrideable/callable-by-subclasses send method.
        Nr$   r&   r   s     r   r'   zAsyncConsumer.sendM   s2       nnW%%%%%%%%%%%r   c                 `      fd} |_         |_        t          j        | d           |S )z
        Return an ASGI v3 single callable that instantiates a consumer instance
        per scope. Similar in purpose to Django's as_view().

        initkwargs will be used to instantiate the consumer instance.
        c                 >   K    di } || ||           d {V S )N r5   )r   r!   r'   consumercls
initkwargss       r   appz"AsyncConsumer.as_asgi.<locals>.app\   sB      s((Z((H!%$777777777r   r5   )updated)consumer_classconsumer_initkwargsr   update_wrapper)r7   r8   r9   s   `` r   as_asgizAsyncConsumer.as_asgiS   sS    	8 	8 	8 	8 	8 	8 !", 	 c26666
r   N)__name__
__module____qualname____doc__r#   r   r   r(   r%   r'   classmethodr>   r5   r   r   r   r      sv          E/  <Q Q Q& & &   [  r   r   c                   2    e Zd ZdZdZed             Zd ZdS )SyncConsumera  
    Synchronous version of the consumer, which is what we write most of the
    generic consumers against (for now). Calls handlers in a threadpool and
    uses CallBouncer to get the send method out to the main event loop.

    It would have been possible to have "mixed" consumers and auto-detect
    if a handler was awaitable or not, but that would have made the API
    for user-called methods very confusing as there'd be two types of each.
    Tc                     t          | t          |          d          }|r ||           dS t          d|d         z            )r   Nr*   r   r+   r-   s      r   r%   zSyncConsumer.dispatchu   sU     $ 0 9 94@@ 	QGG=OPPPr   c                 0    |                      |           dS r0   r1   r2   s     r   r'   zSyncConsumer.send   s     	wr   N)r?   r@   rA   rB   r#   r   r%   r'   r5   r   r   rE   rE   h   sQ          E	Q 	Q 	Q         r   rE   )r   asgiref.syncr    r   dbr   
exceptionsr   layersr   utilsr	   r   r   rE   r5   r   r   <module>rN      s        & & & & & & # # # # # # & & & & & & $ $ $ $ $ $ % % % % % % & & & & & &  J J J J J J J JZ         =          r   