o ` @s|ddlmZddlmZddlmZmZmZmZGdddZ GdddZ Gdd d Z Gd d d e Z d efd dZdS))contextmanager)count) HeaderFieldsMessage MessageFlag MessageTypec@seZdZddZddZdS)MessageFilterscCsi|_t|_dSN)filtersr filter_idsselfr3/usr/lib/python3/dist-packages/jeepney/io/common.py__init__s zMessageFilters.__init__ccs(|jD] }|j|r|VqdSr )r valuesrulematches)r messagehandlerrrr s  zMessageFilters.matchesN)__name__ __module__ __qualname__rrrrrrrs rc@s2eZdZdefddZddZddZdd Zd S) FilterHandler cCs0||_t|j|_||_||_||jj|j<dSr )_filtersnextr _filter_idrqueuer )r r rrrrrrs  zFilterHandle.__init__cCs|jj|j=dSr )rr rr rrrcloseszFilterHandle.closecCs|jSr )rr rrr __enter__szFilterHandle.__enter__cCs |dS)NF)r)r exc_typeexc_valexc_tbrrr__exit__ szFilterHandle.__exit__N)rrrrrrrr#rrrrrs  rc@s8eZdZddZeddZddZd defd d ZdS) ReplyMatchercCs i|_dSr _futuresr rrrr&s zReplyMatcher.__init__ccs,||j|<z |VW|j|=dS|j|=w)z>Context manager to capture a reply for the given serial numberNr%)r serialfuturerrrcatch)s  zReplyMatcher.catchcCs4|jjtjd}||jvr|j||dSdS)zDispatch an incoming message which may be a reply Returns True if a task was waiting for it, otherwise False. TF)headerfieldsgetr reply_serialr& set_result)r msg rep_serialrrrdispatch3s  zReplyMatcher.dispatchNexccCs:|durtd}|ji}|_|D]}||qdS)z4Throw an error in any task still waiting for a replyNz(D-Bus router closed before reply arrived) RouterClosedr&r set_exception)r r3futuresfutrrrdrop_all?s   zReplyMatcher.drop_allr ) rrrrrr)r2 Exceptionr8rrrrr$%s    r$c@seZdZdZdS)r4aRaised 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)rrr__doc__rrrrr4Hsr4r0cCs<|jjtjkrtd|jjdtj|jj@rtddS)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) r+ message_typer method_call TypeErrorrno_reply_expectedflags ValueError)r0rrrcheck_replyableRs rBN) contextlibr itertoolsrjeepneyrrrrrrr$r9r4rBrrrrs  #