
    V#gu                         S r SrSSKrSSKrSSKrSSKrSSKJrJ	r	J
r
JrJrJrJr  SSKJr  SSKJrJrJrJrJr  SSKJr  SSKJrJr  SS	KJrJr  \R<                  " S
5      rS r  " S S\!5      r" " S S\5      rg))
ConnectionSignalMatchreStructuredText    N)r   LOCAL_IFACE
LOCAL_PATHvalidate_bus_namevalidate_interface_namevalidate_member_namevalidate_object_path)DBusException)ErrorMessageHANDLER_RESULT_NOT_YET_HANDLEDMethodCallMessageMethodReturnMessageSignalMessage)ProxyObject)is_py2is_py3)
ObjectPathStringzdbus.connectionc                      g N )argskwargss     1/usr/lib/python3/dist-packages/dbus/connection.py_noopr   1   s        c                       \ rS rSr/ SQr\" \5      r     SS jrS rS r	S r
\" S 5      rS	 rS
 rS rS rS rS rSrg)r   5   )_sender_name_owner_member
_interface_sender_path_handler_args_match_rule_byte_arrays_conn_weakref_destination_keyword_interface_keyword_message_keyword_member_keyword_sender_keyword_path_keyword_int_args_match_arg0namespace_int_args_pathsNc                 P   Ub  [        U5        Ub  [        U5        Ub  [        U5        Ub  [        U5        S U l        [
        R                  " U5      U l        X l        X@l	        XPl
        X0l        Xl        X`l        X l        SU;   a  [        S5      eXpl        Xl        Xl        Xl        Xl        Xl        Xl        Xl        U(       d  S U l        S U l        g 0 U l        0 U l        U H  n[4        R6                  " SU5      nU(       d  [        SU-  5      e [9        US   5      nUS:  d  US:  a  [        SU-  5      eUS	   c  UU   U R0                  U'   Mr  US	   S
:X  a  UU   U R2                  U'   M  [        SU-  5      e   g ! [:         a    [        SU-  5      ef = f)Nutf8_strings*unexpected keyword argument 'utf8_strings'zarg(\d+)(\w+)?$z(SignalMatch: unknown keyword argument %s   r   ?   z9SignalMatch: arg match index must be in range(64), not %d   path)r
   r	   r   r   r(   weakrefrefr*   r$   r#   r"   r%   r2   r&   r!   	TypeErrorr)   r/   r0   r.   r,   r-   r+   r'   r1   r3   rematchint
ValueError)selfconnsenderobject_pathdbus_interfacememberhandlerbyte_arrayssender_keywordpath_keywordinterface_keywordmember_keywordmessage_keyworddestination_keywordarg0namespacer   kwargr?   indexs                      r   __init__SignalMatch.__init__A   s     (%#N3f%" -
$[[.( 
+ #)V#HII'-)-"3 /$7!!#'D #'D #%D #%D !3U;#$N&+%, - --aME 19
# %8:?%@ A A8#28-D((/1X'28-D((/#$N&+%, - -%   " -#$N&+%, - --s   FF%c                 *    [        [        U 5      5      $ z-SignalMatch objects are compared by identity.)hashidrB   s    r   __hash__SignalMatch.__hash__   s    BtH~r   c                     XL $ rV   r   rB   others     r   __eq__SignalMatch.__eq__   s
    }r   c                     XL$ rV   r   r]   s     r   __ne__SignalMatch.__ne__   s      r   c                     U R                   $ r   )r$   rY   s    r   <lambda>SignalMatch.<lambda>   s    4<<r   c                 *   U R                   Gcz  S/nU R                  b  UR                  SU R                  -  5        U R                  b  UR                  SU R                  -  5        U R                  b  UR                  SU R                  -  5        U R
                  b  UR                  SU R
                  -  5        U R                  b  UR                  SU R                  -  5        U R                  b8  U R                  R                  5        H  u  p#UR                  SX#4-  5        M     U R                  b8  U R                  R                  5        H  u  p#UR                  SX#4-  5        M     S	R                  U5      U l         U R                   $ )
Nztype='signal'zsender='%s'z	path='%s'zinterface='%s'zmember='%s'zarg0namespace='%s'z
arg%d='%s'zarg%dpath='%s',)r(   r$   appendr%   r#   r"   r2   r1   itemsr3   join)rB   rulerR   values       r   __str__SignalMatch.__str__   sG   ::#$D||'MDLL89zz%K$**45*,t>?||'MDLL89"".043F3FFG##/$($8$8$>$>$@LEKK~ => %A##/$($8$8$>$>$@LEKK 0E> AB %A $DJzzr   c                 j    SU R                   [        U 5      U R                  U R                  5       4-  $ )Nz<%s at %x "%s" on conn %r>)	__class__rX   r(   r*   rY   s    r   __repr__SignalMatch.__repr__   s2    ,>>2d8TZZ9K9K9MNO 	Pr   c                     Xl         g r   )r!   )rB   new_names     r   set_sender_name_owner!SignalMatch.set_sender_name_owner   s    "*r   c                     US U R                   4;  a  gXR                  :w  a  gX R                  :w  a  gX0R                  :w  a  gX@R                  :w  a  gX`R
                  :w  a  gg)NFT)r&   r$   r%   r#   r"   r'   )rB   rD   rE   rF   rG   rH   r   s          r   matches_removal_spec SignalMatch.matches_removal_spec   s\    4//\\!**$__,\\!%%%r   c                 v   S nU R                   S UR                  5       4;  a  gU R                  c  U R                  Gb(  [	        SS9nUR
                  " S0 UD6nU R                  R                  5        H5  u  pEU[        U5      :  d!  [        X$   [        5      (       a
  X$   U:w  d  M5    g   U R                  b  U R                  R                  5        H  u  pEU[        U5      :  a    gX$   n[        U[        5      (       d  [        U[        5      (       d    gXV:X  a  MM  USS  S:X  a  UR                  U5      (       a  Mn  USS  S:X  a  UR                  U5      (       a  M    g   U R                  b  [	        SS9nUR
                  " S0 UD6n[        U R                  5      n[        U5      S:X  dI  [        US   [        5      (       a1  US   R                  U R                  5      (       a  US   XwS-    S;  a  gU R                  S UR                  5       4;  a  gU R                  S UR!                  5       4;  a  gU R"                  S UR%                  5       4;  a  g Ub  U R&                  (       d  UR                  U R&                  S9n0 nU R(                  b  UR                  5       X0R(                  '   U R*                  b  UR-                  5       X0R*                  '   U R.                  b  UR%                  5       X0R.                  '   U R0                  b  UR                  5       X0R0                  '   U R2                  b  UR!                  5       X0R2                  '   U R4                  b  XU R4                  '   U R6                  " U0 UD6  g!   [8        R:                  " 5         [<        R?                  S	SS
9   g= f)NFTrI   /r   r7   ) .z&Exception in handler for D-Bus signal:exc_infor   ) r!   
get_senderr1   r3   dictget_args_listrj   len
isinstancer   r   
startswithr2   r"   
get_memberr#   get_interfacer%   get_pathr)   r/   r+   get_destinationr0   r.   r,   r-   r&   loggingbasicConfig_loggererror)rB   messager   r   rR   rm   argnamespace_lens           r   maybe_handle_message SignalMatch.maybe_handle_message   s\    ""41C1C1E*FF+t/C/C/Od+F((262D $ 4 4 : : <SY&%dk6::{e+ 	 != ##/$($8$8$>$>$@LED	)$+C%c622:c:;V;V$ !& %bc
c 1cnnU6K6K #BCCE4D4DS4I4I$ %A *d+F((262D 3 34MTa!$q'622Aw))$*=*=>>7=):;9L <<g&8&8&:;;??4)>)>)@"AA::dG$4$4$677	P |4#4#4,,9J9J,KF##//6/A/A/C++,((44;4K4K4M001!!--4-=-=-?))*##//6/A/A/C++,&&2292G2G2I../$$007t,,-MM4*6* 	P!MMBQMOs   !D)N +N8c                     U R                  5       nUbI  UR                  " X R                  U R                  U R                  U R
                  40 U R                  D6  g g r   )r*   remove_signal_receiverr"   r#   r$   r%   r'   )rB   rC   s     r   removeSignalMatch.remove  sS    !!#''ll(,(,

< +/*:*:< r   )r2   r'   r)   r*   r+   r&   r1   r3   r#   r,   r"   r.   r-   r%   r0   r(   r$   r/   r!   )FNNNNNNN)__name__
__module____qualname____firstlineno___slotstuple	__slots__rS   rZ   r_   rb   propertyrD   rn   rr   rv   ry   r   r   __static_attributes__r   r   r   r   r   5   si    F fI /4378<;?#A-F! /0F0P+ L\<r   r   c                      ^  \ rS rSrSr\rU 4S jrS rSS jr	    SS jr
S r    SS jrS	 rS
 r  SS jr  SS jrS rSrU =r$ )r   i  znA connection to another application. In this base class there is
assumed to be no bus daemon.

:Since: 0.81.0
c                    > [         [        U ]
  " U0 UD6  [        U S5      (       dW  SU l        / U l        0 U l         [        R                  " 5       U l	         U R                  U R                  R                  5        g g )N_dbus_Connection_initializedr7   )superr   rS   hasattrr   "_Connection__call_on_disconnection!_signal_recipients_by_object_path	threadingLock_signals_lockadd_message_filterrq   _signal_func)rB   r   r   rq   s      r   rS   Connection.__init__"  su    j$($9&9 t;<<01D-+-D(57D2> "+!1D=##DNN$?$?@ =r   c                     U$ )a  Return the unique name for the given bus name, activating it
if necessary and possible.

If the name is already unique or this connection is not to a
bus daemon, just return it.

:Returns: a bus name. If the given `bus_name` exists, the returned
    name identifies its current owner; otherwise the returned name
    does not exist.
:Raises DBusException: if the implementation has failed
    to activate the given bus name.
:Since: 0.81.0
r   )rB   bus_names     r   activate_name_ownerConnection.activate_name_owner5  s	     r   c                     UR                  SS5      nUb"  Ub  [        S5      eSSKJn  U" S[        SS9  UnU(       a+  [        S	S
R                  UR                  5       5      -  5      eU R                  XUUS9$ )ae  Return a local proxy for the given remote object.

Method calls on the proxy are translated into method calls on the
remote object.

:Parameters:
    `bus_name` : str
        A bus name (either the unique name or a well-known name)
        of the application owning the object. The keyword argument
        named_service is a deprecated alias for this.
    `object_path` : str
        The object path of the desired object
    `introspect` : bool
        If true (default), attempt to introspect the remote
        object to find out supported methods and their signatures

:Returns: a `dbus.proxies.ProxyObject`
named_serviceN3bus_name and named_service cannot both be specifiedr   warnziPassing the named_service parameter to get_object by name is deprecated: please use positional parametersr9   
stacklevelz4get_object does not take these keyword arguments: %sz, )
introspect)popr=   warningsr   DeprecationWarningrk   keysProxyObjectClass)rB   r   rE   r   r   r   r   s          r   
get_objectConnection.get_objectE  s    ( 

?D9$# !/ 0 0% C#3 %H ,.2ii.FG H H $$T[0: % < 	<r   c                    U R                  5         UR                  SS5      nUb"  Ub  [        S5      eUnSSKJn  U" S[
        SS9  [        XXSX!40 UD6n	U R                  R                  5          U R                  R                  U0 5      n
U
R                  U0 5      nUR                  U/ 5      nUR                  U	5        U R                  R                  5         U	$ ! U R                  R                  5         f = f)	a  Arrange for the given function to be called when a signal matching
the parameters is received.

:Parameters:
    `handler_function` : callable
        The function to be called. Its positional arguments will
        be the arguments of the signal. By default it will receive
        no keyword arguments, but see the description of
        the optional keyword arguments below.
    `signal_name` : str
        The signal name; None (the default) matches all names
    `dbus_interface` : str
        The D-Bus interface name with which to qualify the signal;
        None (the default) matches all interface names
    `bus_name` : str
        A bus name for the sender, which will be resolved to a
        unique name if it is not already; None (the default) matches
        any sender.
    `path` : str
        The object path of the object which must have emitted the
        signal; None (the default) matches any object path
:Keywords:
    `utf8_strings` : bool
        If True, the handler function will receive any string
        arguments as dbus.UTF8String objects (a subclass of str
        guaranteed to be UTF-8). If False (default) it will receive
        any string arguments as dbus.String objects (a subclass of
        unicode).
    `byte_arrays` : bool
        If True, the handler function will receive any byte-array
        arguments as dbus.ByteArray objects (a subclass of str).
        If False (default) it will receive any byte-array
        arguments as a dbus.Array of dbus.Byte (subclasses of:
        a list of ints).
    `sender_keyword` : str
        If not None (the default), the handler function will receive
        the unique name of the sending endpoint as a keyword
        argument with this name.
    `destination_keyword` : str
        If not None (the default), the handler function will receive
        the bus name of the destination (or None if the signal is a
        broadcast, as is usual) as a keyword argument with this name.
    `interface_keyword` : str
        If not None (the default), the handler function will receive
        the signal interface as a keyword argument with this name.
    `member_keyword` : str
        If not None (the default), the handler function will receive
        the signal name as a keyword argument with this name.
    `path_keyword` : str
        If not None (the default), the handler function will receive
        the object-path of the sending object as a keyword argument
        with this name.
    `message_keyword` : str
        If not None (the default), the handler function will receive
        the `dbus.lowlevel.SignalMessage` as a keyword argument with
        this name.
    `arg...` : unicode or UTF-8 str
        If there are additional keyword parameters of the form
        ``arg``\ *n*, match only signals where the *n*\ th argument
        is the value given for that keyword parameter. As of this
        time only string arguments can be matched (in particular,
        object paths and signatures can't).
    `arg0namespace` : str
        If not None (the default) match only signals where the first
        argument is a string that either is equal to the
        keyword parameter, or starts with the keyword parameter
        followed by a dot (and optionally more text).
    `arg...path`: str
        If there are additional keyword parameters of the form
        ``arg``\ *n* ``path``, match only signals where the *n*\ th
        argument is either equal or matches in a path like manner.
        A path-like comparison matches when either the keyword or the
        argument ends with a '/' and is a prefix of the other. An
        example argument path match is arg0path='/aa/bb/'. This would
        match messages with first arguments of '/', '/aa/', '/aa/bb/',
        '/aa/bb/cc/' and '/aa/bb/cc'. It would not match messages with
        first arguments of '/aa/b', '/aa' or even '/aa/bb'.
    `named_service` : str
        A deprecated alias for `bus_name`.
r   Nr   r   r   zrPassing the named_service parameter to add_signal_receiver by name is deprecated: please use positional parametersr9   r   )_require_main_loopr   r=   r   r   r   r   r   acquirer   
setdefaultri   release)rB   handler_functionsignal_namerF   r   r:   keywordsr   r   r?   by_interface	by_membermatchess                r   add_signal_receiverConnection.add_signal_receiverj  s   l 	! _d;$# !, - -$H% K#3 DD'G=EG 	""$	)AALL"L$//CI**;;GNN5!&&( &&(s   1AC C:c              #   4  #    Ub  S U4nOSnUb  S U4nOSnUb  S U4nOSnU Hp  nU R                   R                  U5      nUc  M#  U HG  nUR                  US 5      nUc  M  U H'  nUR                  US 5      n	U	c  M  U	 H  n
U
v   M	     M)     MI     Mr     g 7f)Nr   )r   get)rB   r:   rF   rG   	path_keysinterface_keysmember_keysr   r   r   ms              r   _iter_easy_matchesConnection._iter_easy_matches  s     tII%"N3N$N.K!KDAAEEdKL#"0(,,^TB	$)F'mmFD9G $ %	 *	 #1	 s   BBc                    UR                  SS 5      nUb"  Ub  [        S5      eUnSSKJn  U" S[        SS9  / n	/ n
U R
                  R                  5          U R                  R                  US 5      nUc   U R
                  R                  5         g UR                  US 5      nUc   U R
                  R                  5         g UR                  US 5      nUc   U R
                  R                  5         g U HG  nXL d  UR                  " UUUUU40 UD6(       a  U
R                  U5        M6  U	R                  U5        MI     U	(       a  XU'   OX	 U(       d  X	 U(       d  U R                  U	 U R
                  R                  5         U
 H  nU R                  U5        M     g ! U R
                  R                  5         f = f)Nr   r   r   r   zuPassing the named_service parameter to remove_signal_receiver by name is deprecated: please use positional parametersr9   r   )r   r=   r   r   r   r   r   r   r   r   ry   ri   _clean_up_signal_match)rB   handler_or_matchr   rF   r   r:   r   r   r   new	deletionsr   r   r   r?   s                  r   r   !Connection.remove_signal_receiver  s    !_d;$# !, - -$H% ) $3
 	""$!	)AAEEdFJLL#: &&(9 %((>I 4 &&(3  mmK6G. &&(+ !$-11(262@2=2B	>
 5=> $$U+JJu% ! ),+&* $4' BB4H&&(E''.  &&(s   F! F! F! 4A8F! !F=c                     g r   r   )rB   r?   s     r   r   !Connection._clean_up_signal_match5  s    r   c                    [        U[        5      (       d  [        $ UR                  5       nUR	                  5       nUR                  5       nU R                  X2U5       H  nUR                  U5        M     U[        :X  a,  U[        :X  a"  US:X  a  U R                   H  n U" U 5        M     [        $ ! [         a-    [        R                  " 5         [        R                  SSS9   ML  f = f)zfD-Bus filter function. Handle signals by dispatching to Python
callbacks kept in the match-rule tree.
Disconnectedz-Exception in handler for Disconnected signal:r7   r   )r   r   r   r   r   r   r   r   r   r   r   	Exceptionr   r   r   r   )rB   r   rF   r:   r   r?   cbs          r   r   Connection._signal_func9  s    
 '=1111 ..0!((*,,T-8:E&&w/: k)J>)22/tH 3 .- ! /'')MM #",- " //s    B223C)(C)c                 &  ^^^ U[         :X  a  [        S[         -  5      eU[        :X  a  [        S[        -  5      e[        U
S9mSU;   a  [	        S5      e[        UUUUS9n UR                  " USU06  Tc&  Tc#  UR                  S
5        U R                  U5        g	Tc  [        mTc  [        mUUU4S jnU R!                  XU	US9$ ! [         a=  n[        R                  " 5         [        R                  SXeUR                  U5        e S	nAff = f)a#  Call the given method, asynchronously.

If the reply_handler is None, successful replies will be ignored.
If the error_handler is None, failures will be ignored. If both
are None, the implementation may request that no reply is sent.

:Returns: The dbus.lowlevel.PendingCall.
:Since: 0.81.0
1Methods may not be called on the reserved path %s6Methods may not be called on the reserved interface %sr|   r5   r6   destinationr:   	interfacemethod	signature<Unable to set arguments %r according to signature %r: %s: %sNTc                 
  > [        U [        5      (       a  T" U R                  " S0 TD66   g [        U [        5      (       a.  T" [	        U R                  5       SU R                  5       065        g T" [        SU -  5      5        g )Nnamez%Unexpected type for reply message: %rr   )r   r   r   r   r   get_error_namer=   )r   error_handlerget_args_optsreply_handlers    r   msg_reply_handler0Connection.call_async.<locals>.msg_reply_handler  s    '#677w44E}EFG\22m-4-B-B-DF1G1G1I F G i )68?)@ A Br   )require_main_loop)r   r   r   r   r=   r   ri   r   r   r   r   r   rq   set_no_replysend_messager   send_message_with_reply)rB   r   rE   rF   r   r   r   r   r   timeoutrI   r   r   r   er   r   s          ``       @r   
call_asyncConnection.call_asyncW  sA    *$ !*,6!7 8 8[( !/1<!= > > 5V#HII#)4.<+13
	NN6Y6  ]%:   &g& !M !M	B ++G(/:K , M 	M9  	!MM 11;;; 	s   #C	 	
D8DDc	                    U[         :X  a  [        S[         -  5      eU[        :X  a  [        S[        -  5      e[        US9n
SU	;   a  [	        S5      e[        UUUUS9n UR                  " USU06  U R                  X5      nUR                  " S0 U
D6n[        U5      S
:X  a  g	[        U5      S:X  a  US
   $ [!        U5      $ ! [         a=  n[        R                  " 5         [        R                  SXeUR                  U5        e S	nAff = f)z5Call the given method, synchronously.
:Since: 0.81.0
r   r   r|   r5   r6   r   r   r   Nr   r7   r   )r   r   r   r   r=   r   ri   r   r   r   r   r   rq   !send_message_with_reply_and_blockr   r   r   )rB   r   rE   rF   r   r   r   r   rI   r   r   r   r   reply_message	args_lists                  r   call_blockingConnection.call_blocking  s*    *$ !*,6!7 8 8[( !/1<!= > > 5V#HII#)4.<+13
	NN6Y6 >>!//@-@	y>Q^q Q<##!  	!MM 11;;; 	s    C 
D8DDc                 :    U R                   R                  U5        g)zArrange for `callable` to be called with one argument (this
Connection object) when the Connection becomes
disconnected.

:Since: 0.83.0
N)r   ri   )rB   callables     r   call_on_disconnection Connection.call_on_disconnection  s     	$$++H5r   )__call_on_disconnectionr   r   r   )NNT)NNNN)      FT)r	  F)r   r   r   r   __doc__r   r   rS   r   r   r   r   r   r   r   r   r  r  r   __classcell__)rq   s   @r   r   r     s     #A& #<L /315+/'+	qf < ,0.2(,$(	9/v.@ .3%)>MB 04"')$V6 6r   r   )#__all____docformat__r   r>   r   r;   _dbus_bindingsr   _Connectionr   r   r   r	   r
   r   dbus.exceptionsr   dbus.lowlevelr   r   r   r   r   dbus.proxiesr   dbus._compatr   r   r   r   	getLoggerr   r   objectr   r   r   r   <module>r     s~   2 ("  	  I I I *( ( % ' / 

-
.	a<& a<Hp6 p6r   