
    &e                         d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ  ee          Z G d d          Zdedefd	Zd
e	de	dee	         fdZdS )    )AnyDictListOptionalTuple)
get_logger)Delta)
ForwardMsgc                   p    e Zd ZdZd Zdeeef         fdZde	fdZ
deddfdZdd	Zdee         fd
ZdS )ForwardMsgQueuea:  Accumulates a session's outgoing ForwardMsgs.

    Each AppSession adds messages to its queue, and the Server periodically
    flushes all session queues and delivers their messages to the appropriate
    clients.

    ForwardMsgQueue is not thread-safe - a queue should only be used from
    a single thread.
    c                 :    g | _         t                      | _        d S )N_queuedict_delta_index_mapselfs    Clib/python3.11/site-packages/streamlit/runtime/forward_msg_queue.py__init__zForwardMsgQueue.__init__#   s    (* =AFF    returnc                     ddl m fd| j        D             t          | j                                                  dS )Nr   )MessageToDictc                 &    g | ]} |          S  r   ).0mr   s     r   
<listcomp>z-ForwardMsgQueue.get_debug.<locals>.<listcomp>0   s#    <<<1mmA&&<<<r   )queueids)google.protobuf.json_formatr   r   listr   keys)r   r   s    @r   	get_debugzForwardMsgQueue.get_debug,   sY    ====== =<<<<<<-224455
 
 	
r   c                 2    t          | j                  dk    S )Nr   )lenr   r   s    r   is_emptyzForwardMsgQueue.is_empty4   s    4;1$$r   msgNc                    t          |          s| j                            |           dS t          |j        j                  }|| j        v r| j        |         }| j        |         }t          |j        |j                  }|St                      }|j        
                    |           |j        
                    |j                   || j        |<   dS t          | j                  | j        |<   | j                            |           dS )zCAdd message into queue, possibly composing it with another message.N)_is_composable_messager   appendtuplemetadata
delta_pathr   _maybe_compose_deltasdeltar
   CopyFromr&   )r   r(   	delta_keyindexold_msgcomposed_deltanew_msgs          r   enqueuezForwardMsgQueue.enqueue7   s    %c** 	Ks###F #,122	---))4Ek%(G27=#)LLN)$,,&&~666 ))#,777%,E" ,/t{+;+;i(3r   c                 :    g | _         t                      | _        dS )zClear the queue.Nr   r   s    r   clearzForwardMsgQueue.clearS   s     $r   c                 <    | j         }|                                  |S )zeClear the queue and return a list of the messages it contained
        before being cleared.
        )r   r9   )r   r   s     r   flushzForwardMsgQueue.flushX   s     

r   )r   N)__name__
__module____qualname____doc__r   r   strr   r$   boolr'   r
   r7   r9   r   r;   r   r   r   r   r      s         C C C
4S> 
 
 
 
%$ % % % % :  $        8' ' ' '
tJ'      r   r   r(   r   c                 |    |                      d          sdS | j                            d          }|dk    o|dk    S )zHTrue if the ForwardMsg is potentially composable with other ForwardMsgs.r0   Ftypeadd_rowsarrow_add_rows)HasFieldr0   
WhichOneof)r(   
delta_types     r   r*   r*   a   sH    <<   u
 %%f--J#F
6F(FFr   	old_delta	new_deltac                     |                      d          }|dk    rdS |                     d          }|dk    r|S |dk    r|S dS )aJ  Combines new_delta onto old_delta if possible.

    If the combination takes place, the function returns a new Delta that
    should replace old_delta in the queue.

    If the new_delta is incompatible with old_delta, the function returns None.
    In this case, the new_delta should just be appended to the queue as normal.
    rC   	add_blockNnew_element)rG   )rI   rJ   old_delta_typenew_delta_types       r   r/   r/   n   sc     ))&11N$$ t))&11N&&$$4r   N)typingr   r   r   r   r   streamlit.loggerr   streamlit.proto.Delta_pb2r	   streamlit.proto.ForwardMsg_pb2r
   r<   LOGGERr   rA   r*   r/   r   r   r   <module>rU      s   4 3 3 3 3 3 3 3 3 3 3 3 3 3 ' ' ' ' ' ' + + + + + + 5 5 5 5 5 5	H		F F F F F F F FR
G
 
Gt 
G 
G 
G 
G!U !u !% ! ! ! ! ! !r   