
    .Ph
                         d dl mZ d dlmZ d dlmZmZmZmZ  G d d          Z	 G d d          Z
 G d d	          Z G d
 de          ZdefdZdS )    )contextmanager)count)HeaderFieldsMessageMessageFlagMessageTypec                       e Zd Zd Zd ZdS )MessageFiltersc                 :    i | _         t                      | _        d S N)filtersr   
filter_idsselfs    Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jeepney/io/common.py__init__zMessageFilters.__init__   s    ''    c              #   ~   K   | j                                         D ] }|j                            |          r|V  !d S r   )r   valuesrulematches)r   messagehandles      r   r   zMessageFilters.matches   sO      l))++ 	 	F{""7++ 	 	r   N)__name__
__module____qualname__r   r    r   r   r
   r
      s2        " " "    r   r
   c                   ,    e Zd ZdefdZd Zd Zd ZdS )FilterHandler   c                     || _         t          |j                  | _        || _        || _        | | j         j        | j        <   d S r   )_filtersnextr   
_filter_idr   queuer   )r   r   r   r$   s       r   r   zFilterHandle.__init__   s@    w122	
15do...r   c                 *    | j         j        | j        = d S r   )r!   r   r#   r   s    r   closezFilterHandle.close   s    M!$/222r   c                     | j         S r   )r$   r   s    r   	__enter__zFilterHandle.__enter__   s
    zr   c                 .    |                                   dS )NF)r&   )r   exc_typeexc_valexc_tbs       r   __exit__zFilterHandle.__exit__    s    

ur   N)r   r   r   r
   r   r&   r(   r-   r   r   r   r   r      s\        6 6 6 6 63 3 3      r   r   c                   >    e Zd Zd Zed             Zd ZddefdZdS )ReplyMatcherc                     i | _         d S r   _futuresr   s    r   r   zReplyMatcher.__init__&   s    r   c              #   R   K   || j         |<   	 |V  | j         |= dS # | j         |= w xY w)z>Context manager to capture a reply for the given serial numberNr1   )r   serialfutures      r   catchzReplyMatcher.catch)   sH       !'f	&LLLf%%%f%%%%%s    
&c                     |j         j                            t          j        d          }|| j        v r"| j        |                             |           dS dS )zDispatch an incoming message which may be a reply

        Returns True if a task was waiting for it, otherwise False.
        TF)headerfieldsgetr   reply_serialr2   
set_result)r   msg
rep_serials      r   dispatchzReplyMatcher.dispatch3   sS    
 Z&**<+DbII
&&M*%0055545r   Nexcc                     |t          d          }| j        i c}| _        |                                D ]}|                    |           dS )z4Throw an error in any task still waiting for a replyNz(D-Bus router closed before reply arrived)RouterClosedr2   r   set_exception)r   rA   futuresfuts       r   drop_allzReplyMatcher.drop_all?   s_    ;IJJC!%>>## 	# 	#Cc""""	# 	#r   r   )	r   r   r   r   r   r6   r@   	ExceptionrG   r   r   r   r/   r/   %   sm           & & ^&
 
 
# #I # # # # # #r   r/   c                       e Zd ZdZdS )rC   a  Raised in tasks waiting for a reply when the router is closed

    This will also be raised if the receiver task crashes, so tasks are not
    stuck waiting for a reply that can never come. The router object will not
    be usable after this is raised.
    N)r   r   r   __doc__r   r   r   rC   rC   H   s          	Dr   rC   r>   c                     | j         j        t          j        k    rt	          d| j         j         d          t
          j        | j         j        z  rt          d          dS )z4Raise an error if we wouldn't expect a reply for msgz,Only method call messages have replies (not )z/This message has the no_reply_expected flag setN)	r9   message_typer   method_call	TypeErrorr   no_reply_expectedflags
ValueError)r>   s    r   check_replyablerS   R   st    
z+"999 ; #
 7; ; ; < < 	<$sz'77 LJKKKL Lr   N)
contextlibr   	itertoolsr   jeepneyr   r   r   r   r
   r   r/   rH   rC   rS   r   r   r   <module>rW      s   % % % % % %       C C C C C C C C C C C C              ( #  #  #  #  #  #  #  #F	 	 	 	 	9 	 	 	L L L L L L Lr   