
    +c
                         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y)    )contextmanager)count)HeaderFieldsMessageMessageFlagMessageTypec                       e Zd Zd Zd Zy)MessageFiltersc                 0    i | _         t               | _        y N)filtersr   
filter_idsselfs    3/usr/lib/python3/dist-packages/jeepney/io/common.py__init__zMessageFilters.__init__   s    '    c              #      K   | j                   j                         D ]"  }|j                  j                  |      s| $ y wr   )r   valuesrulematches)r   messagehandles      r   r   zMessageFilters.matches   s9     ll))+ 	F{{""7+	s
   9AAN)__name__
__module____qualname__r   r    r   r   r
   r
      s    "r   r
   c                   *    e Zd ZdefdZd Zd Zd Zy)FilterHandler   c                     || _         t        |j                        | _        || _        || _        | | j                   j                  | j                  <   y r   )_filtersnextr   
_filter_idr   queuer   )r   r   r   r$   s       r   r   zFilterHandle.__init__   sA    w112	
15doo.r   c                 F    | j                   j                  | j                  = y r   )r!   r   r#   r   s    r   closezFilterHandle.close   s    MM!!$//2r   c                     | j                   S r   )r$   r   s    r   	__enter__zFilterHandle.__enter__   s    zzr   c                 $    | j                          y)NF)r&   )r   exc_typeexc_valexc_tbs       r   __exit__zFilterHandle.__exit__    s    

r   N)r   r   r   r
   r   r&   r(   r-   r   r   r   r   r      s    6 63r   r   c                   6    e Zd Zd Zed        Zd ZddefdZy)ReplyMatcherc                     i | _         y r   _futuresr   s    r   r   zReplyMatcher.__init__&   s	    r   c              #   r   K   || j                   |<   	 | | j                   |= y# | j                   |= w xY ww)z>Context manager to capture a reply for the given serial numberNr1   )r   serialfutures      r   catchzReplyMatcher.catch)   s8      !'f	&Lf%f%s   7% 747c                     |j                   j                  j                  t        j                  d      }|| j
                  v r| j
                  |   j                  |       yy)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   sO    
 ZZ&&**<+D+DbI
&MM*%005r   Nexcc                     |t        d      }| j                  i c}| _        |j                         D ]  }|j                  |        y)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?   sH    ;IJC!%>># 	#Cc"	#r   r   )	r   r   r   r   r   r6   r@   	ExceptionrG   r   r   r   r/   r/   %   s,     & &
#I #r   r/   c                       e Zd ZdZy)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     	r   rC   r>   c                     | j                   j                  t        j                  k7  r#t	        d| j                   j                   d      t
        j                  | j                   j                  z  rt        d      y)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   sl    
zz+"9"99   #

 7 78; < 	<$$szz'7'77JKK 8r   N)
contextlibr   	itertoolsr   jeepneyr   r   r   r   r
   r   r/   rH   rC   rS   r   r   r   <module>rW      sJ    %  C C  ( #  #F	9 	L Lr   