
    @ia`                     $   d dl Z 	 d dlmZ n# e$ r	 d dlmZ Y nw xY wd dlZd dlmZ d dlm	Z	m
Z
mZmZ dZ e j        d          Zd dlmZmZmZmZmZ d dlmZ  G d	 d
          Z G d d          Z G d de          Z G d de          ZdS )    N)RLock)process_introspection_data)DBusExceptionIntrospectionParserExceptionMissingErrorHandlerExceptionMissingReplyHandlerExceptionrestructuredtextzdbus.proxies)BUS_DAEMON_IFACEBUS_DAEMON_NAMEBUS_DAEMON_PATHINTROSPECTABLE_IFACE
LOCAL_PATH)is_py2c                   $    e Zd ZdZd Zd Zd ZdS )_DeferredMethodzXA proxy method which will only get called once we have its
    introspection reply.
    c                 H    || _         |j        | _        || _        || _        d S N)_proxy_method_method_name_append_block)selfproxy_methodappendblocks       ./usr/lib/python3/dist-packages/dbus/proxies.py__init__z_DeferredMethod.__init__8   s'    )(5    c                     d|v s|                     dd          r|                     | j        ||           d S |                                   | j        |i |S )Nreply_handlerignore_replyF)getr   r   r   r   argskeywordss      r   __call__z_DeferredMethod.__call__?   sj    x''LL// ( LL+T8<<<4 KKMMM%4%t8x888r   c                 >    |                      | j        ||           d S r   )r   r   r#   s      r   
call_asyncz_DeferredMethod.call_asyncJ   s!    T'x88888r   N__name__
__module____qualname____doc__r   r&   r(    r   r   r   r   4   sK           	9 	9 	99 9 9 9 9r   r   c                   $    e Zd ZdZd Zd Zd ZdS )_ProxyMethodzA proxy method.

    Typically a member of a ProxyObject. Calls to the
    method produce messages that travel over the Bus and are routed
    to a specific named Service.
    c                     |t           k    rt          dt           z            || _        || _        || _        || _        t          j        |           || _        |t          j	        |           || _
        d S )Nz1Methods may not be called on the reserved path %s)r   r   _proxy_connection_named_service_object_path_dbus_bindingsvalidate_member_namer   validate_interface_name_dbus_interface)r   proxy
connectionbus_nameobject_pathmethod_nameifaces          r   r   z_ProxyMethod.__init__U   s    *$$ !*,6!7 8 8 8  %)'*+K888*25999$r   c           
      p   |                     dd           }|                     dd           }|                     dd          }|                     dd           }||1|t                      |t                      |rt          d          |                     d| j                  }|7|| j        }n|dz   | j        z   }| j        j                            |d           }|s|+ | j	        j
        | j        | j        || j        ||||fi | d S  | j	        j        | j        | j        || j        ||fi |S )	Nr    error_handlerr!   F	signaturez6ignore_reply and reply_handler cannot be used togetherdbus_interface.)popr   r   	TypeErrorr9   r   r2   _introspect_method_mapr"   r3   r(   r4   r5   call_blocking)	r   r$   r%   r    rA   r!   rB   rC   keys	            r   r&   z_ProxyMethod.__call__i   s    _d;; _d;;||NE::LLd33	$(A$2444&2444 1 !0 1 1 1 "&68LMM%'$s*T->>:>>sDIII 	>=4'D'(;(,(9(6(,(9(1(,(5(54 4 +34 4 4 4 4 24#1$2E262C2@262C2;26> > 5=> > >r   c           
         |                     dd           }|                     dd           }|                     dd           }|                     d| j                  }|7|r|dz   | j        z   }n| j        }| j        j                            |d           } | j        j        | j        | j	        || j        ||||fi | d S )Nr    rA   rB   rC   rD   )
rE   r9   r   r2   rG   r"   r3   r(   r4   r5   )r   r$   r%   r    rA   rB   rC   rI   s           r   r(   z_ProxyMethod.call_async   s     _d;; _d;;LLd33	!&68LMM ($s*T->>':>>sDIII##D$7$($5$2$($5$-$($1$1	0 	0 '/	0 	0 	0 	0 	0r   Nr)   r.   r   r   r0   r0   N   sL         % % %(*> *> *>X0 0 0 0 0r   r0   c                       e Zd ZdZeZeZdZdZ	dZ
	 	 ddZ ed	 ddd
          Z ed ddd          Z ed ddd          ZddZd Zd Zd Zd Zd Zd Zd ZddZd ZeZdS )ProxyObjectzA proxy to the remote Object.

    A ProxyObject is provided by the Bus. ProxyObjects
    have member functions, and can be called like normal Python objects.
    r         NTFc                 R   |                     dd          }|,|t          d          |}ddlm}  |dt          d           |                     d	d          }	|	,|t          d
          |	}ddlm}  |dt          d           |r7t          dd                    |                                          z            |r|                                 || _        |t          j
        |           |x| _        | _        t          j        |           || _        |s|                    |          | _        d| _        g | _        i | _        t'                      | _        |r| j        t*          k    r| j        | _        dS | j        | _        |                                 | _        dS )a  Initialize the proxy object.

        :Parameters:
            `conn` : `dbus.connection.Connection`
                The bus or connection on which to find this object.
                The keyword argument `bus` is a deprecated alias for this.
            `bus_name` : str
                A bus name for the application owning the object, to be used
                as the destination for method calls and the sender for
                signal matches. The keyword argument ``named_service`` is a
                deprecated alias for this.
            `object_path` : str
                The object path at which the application exports the object
            `introspect` : bool
                If true (default), attempt to introspect the remote
                object to find out supported methods and their signatures
            `follow_name_owner_changes` : bool
                If true (default is false) and the `bus_name` is a
                well-known name, follow ownership changes for that name
        busNz%conn and bus cannot both be specifiedr   )warnz`Passing the bus parameter to ProxyObject by name is deprecated: please use positional parametersrN   )
stacklevelnamed_servicez3bus_name and named_service cannot both be specifiedzjPassing the named_service parameter to ProxyObject by name is deprecated: please use positional parametersz>ProxyObject.__init__ does not take these keyword arguments: %sz, )rE   rF   warningsrQ   DeprecationWarningjoinkeys_require_main_loop_busr6   validate_bus_namer4   _requested_bus_namevalidate_object_path__dbus_object_path__activate_name_owner_pending_introspect_pending_introspect_queuerG   r   _introspect_lockr    INTROSPECT_STATE_DONT_INTROSPECT_introspect_state'INTROSPECT_STATE_INTROSPECT_IN_PROGRESS_Introspect)
r   connr<   r=   
introspectfollow_name_owner_changeskwargsrP   rQ   rS   s
             r   r   zProxyObject.__init__   s   , jj%%? GHHHD%%%%%%D @#3 3 3 3 

?D99$# !, - - -$H%%%%%%D C#3 3 3 3  	8 4"ii667 8 8 8 % 	& ##%%%	,X666 :BAd6+K888$/!( 	E"&":":8"D"DD $( )+&&(# !& 	:T6*DD%)%JD"""%)%QD"'+'7'7'9'9D$$$r   c                     | j         S r   )r4   r   s    r   <lambda>zProxyObject.<lambda>  s	    T%8 r   a  The bus name to which this proxy is bound. (Read-only,
            may change.)

            If the proxy was instantiated using a unique name, this property
            is that unique name.

            If the proxy was instantiated with a well-known name and with
            ``follow_name_owner_changes`` set false (the default), this
            property is the unique name of the connection that owned that
            well-known name when the proxy was instantiated, which might
            not actually own the requested well-known name any more.

            If the proxy was instantiated with a well-known name and with
            ``follow_name_owner_changes`` set true, this property is that
            well-known name.
            c                     | j         S r   )r[   rk   s    r   rl   zProxyObject.<lambda>   s	    t/G r   z[The bus name which was requested when this proxy was
            instantiated.
            c                     | j         S r   )r]   rk   s    r   rl   zProxyObject.<lambda>&  s	    (A r   zThe object-path of this proxy.c                 F     | j         j        |f||| j        | j        d|S )ax  Arrange for the given function to be called when the given signal
        is received.

        :Parameters:
            `signal_name` : str
                The name of the signal
            `handler_function` : callable
                A function to be called when the signal is emitted by
                the remote object. Its positional arguments will be the
                arguments of the signal; optionally, it may be given
                keyword arguments as described below.
            `dbus_interface` : str
                Optional interface with which to qualify the signal name.
                If None (the default) the handler will be called whenever a
                signal of the given member name is received, whatever
                its interface.
        :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).
        )signal_namerC   r<   path)rY   add_signal_receiverr4   r]   r   rp   handler_functionrC   r%   s        r   connect_to_signalzProxyObject.connect_to_signal2  sG    x 	&	%&6 	22=5C/3/B+/+D		2 	2
 )1	2 	2	2r   c           
      p    i } | j         j        | j        | j        t          ddd| j        | j        fddi|S )N
Introspect r.   require_main_loopF)rY   r(   r4   r]   r   _introspect_reply_handler_introspect_error_handler)r   ri   s     r   re   zProxyObject._Introspectu  sa    #ty#D$7$($=$8,B$($B$($B	G G
 7<G
 @FG G 	Gr   c                 @    | j         D ]\  }}} ||i | g | _         d S r   )r`   )r   r   r$   r%   s       r   _introspect_execute_queuez%ProxyObject._introspect_execute_queue~  sC     /3.L 	, 	,*\4L$+(++++)+&&&r   c                    | j                                          	 	 t          |          | _        nF# t          $ r9}|                     |           Y d }~| j                                          d S d }~ww xY w| j        | _        d | _	        | 
                                 | j                                          d S # | j                                          w xY wr   )ra   acquirer   rG   r   r{   release INTROSPECT_STATE_INTROSPECT_DONErc   r_   r}   )r   dataes      r   rz   z%ProxyObject._introspect_reply_handler  s    %%'''	,.H.N.N++/   ..q111 !))+++++ &*%JD"'+D$**,,,!))+++++D!))++++s+   1 B9 
A4A/B9 /A44*B9 9Cc                    t          j                     t                              d| j        | j        |j        j        |j        j        |           | j	        
                                 	 t                              d           | j        | _        d | _        |                                  | j	                                         d S # | j	                                         w xY w)Nz$Introspect error on %s:%s: %s.%s: %sz'Executing introspect queue due to error)loggingbasicConfig_loggererrorr4   r]   	__class__r+   r*   ra   r   debugrb   rc   r_   r}   r   )r   r   s     r   r{   z%ProxyObject._introspect_error_handler  s    <)4+Do0%/2J	 	 	 	%%'''	,MMCDDD%)%JD"'+D$**,,,!))+++++D!))++++s   +AC C"c                     | j                                          	 | j        | j                                         | j                                          d S # | j                                          w xY wr   )ra   r   r_   r   r   rk   s    r   _introspect_blockzProxyObject._introspect_block  sr    %%'''	,'3(..000 !))+++++D!))++++s    A A1c                    | j                                          	 | j        | j        k    r| j                            |||f           n ||i | | j                                          d S # | j                                          w xY wr   )ra   r   rc   rd   r`   r   r   )r   callbackr$   ri   s       r   _introspect_add_to_queuez$ProxyObject._introspect_add_to_queue  s    %%'''	,%)UUU.55xv6NOOOO $)&)))!))+++++D!))++++s   6A, ,Bc                     |                     d          r$|                    d          rt          |          |                     |          S N__)
startswithendswithAttributeErrorget_dbus_methodr   members     r   __getattr__zProxyObject.__getattr__  sM    T"" 	0vt'<'< 	0 (((''///r   c                     |                      | | j        | j        | j        ||          }| j        | j        k    r!|                     || j        | j                  }|S )a,  Return a proxy method representing the given D-Bus method. The
        returned proxy method can be called in the usual way. For instance, ::

            proxy.get_dbus_method("Foo", dbus_interface='com.example.Bar')(123)

        is equivalent to::

            proxy.Foo(123, dbus_interface='com.example.Bar')

        or even::

            getattr(proxy, "Foo")(123, dbus_interface='com.example.Bar')

        However, using `get_dbus_method` is the only way to call D-Bus
        methods with certain awkward names - if the author of a service
        implements a method called ``connect_to_signal`` or even
        ``__getattr__``, you'll need to use `get_dbus_method` to call them.

        For services which follow the D-Bus convention of CamelCaseMethodNames
        this won't be a problem.
        )	ProxyMethodClassrY   r4   r]   rc   rd   DeferredMethodClassr   r   )r   r   rC   rets       r   r   zProxyObject.get_dbus_method  sn    . ##D$)$($7$($=v$24 4 !T%QQQ**30M+/+AC CC 
r   c                 L    d| j         | j        | j        t          |           fz  S )Nz&<ProxyObject wrapping %s %s %s at %#x>)rY   r4   r]   idrk   s    r   __repr__zProxyObject.__repr__  s.    7It*D,Er$xx9Q Q 	Qr   )NNNTFr   )r*   r+   r,   r-   r0   r   r   r   rb   rd   r   r   propertyr<   requested_bus_namer=   ru   re   r}   rz   r{   r   r   r   r   r   __str__r.   r   r   rL   rL      sq        
 $)'($./+'($=A<AQ: Q: Q: Q:f x88$ H$ ""G"G$  (AA$02 2KA2 A2 A2 A2FG G G, , ,, , ,, , ,, , ,
, 
, 
,0 0 0$ $ $ $LQ Q Q GGGr   rL   c                       e Zd ZdZd Z ed ddd          ZeZ ed ddd          Z ed ddd	          Z	 ed
 ddd          Z
 ed ddd          Z	 ddZd ZddZd ZeZdS )	InterfacezAn interface into a remote object.

    An Interface can be used to wrap ProxyObjects
    so that calls can be routed to their correct
    D-Bus interface.
    c                 f    t          |t                    r|j        | _        n|| _        || _        dS )a:  Construct a proxy for the given interface on the given object.

        :Parameters:
            `object` : `dbus.proxies.ProxyObject` or `dbus.Interface`
                The remote object or another of its interfaces
            `dbus_interface` : str
                An interface the `object` implements
        N)
isinstancer   proxy_object_objr9   )r   objectrC   s      r   r   zInterface.__init__  s7     fi(( 	+DIIDI-r   c                     | j         j        S r   )r   r=   rk   s    r   rl   zInterface.<lambda>  s    )> r   Nz.The D-Bus object path of the underlying objectc                     | j         j        S r   )r   r<   rk   s    r   rl   zInterface.<lambda>  s    di&8 r   z:The bus name to which the underlying proxy object is boundc                     | j         j        S r   )r   r   rk   s    r   rl   zInterface.<lambda>	  s    	0L r   zGThe bus name which was requested when the underlying object was createdc                     | j         S r   )r   rk   s    r   rl   zInterface.<lambda>  s    $) r   zThe underlying proxy objectc                     | j         S r   )r9   rk   s    r   rl   zInterface.<lambda>  s	    D,@ r   zThe D-Bus interface representedc                 >    |s| j         } | j        j        |||fi |S )aa  Arrange for a function to be called when the given signal is
        emitted.

        The parameters and keyword arguments are the same as for
        `dbus.proxies.ProxyObject.connect_to_signal`, except that if
        `dbus_interface` is None (the default), the D-Bus interface that
        was passed to the `Interface` constructor is used.
        )r9   r   ru   rs   s        r   ru   zInterface.connect_to_signal  sG      	2!1N*ty*;8H+9G G=EG G 	Gr   c                     |                     d          r$|                    d          rt          |          | j                            || j                  S r   )r   r   r   r   r   r9   r   s     r   r   zInterface.__getattr__"  sV    T"" 	Kvt'<'< 	K (((9,,VT5IJJJr   c                 J    || j         }| j                            ||          S )a&  Return a proxy method representing the given D-Bus method.

        This is the same as `dbus.proxies.ProxyObject.get_dbus_method`
        except that if `dbus_interface` is None (the default),
        the D-Bus interface that was passed to the `Interface` constructor
        is used.
        )r9   r   r   )r   r   rC   s      r   r   zInterface.get_dbus_method(  s*     !!1Ny((@@@r   c                 @    d| j         | j        t          |           fz  S )Nz%<Interface %r implementing %r at %#x>)r   r9   r   rk   s    r   r   zInterface.__repr__4  s&    6	4'D83 3 	3r   r   )r*   r+   r,   r-   r   r   r=   r]   r<   r   r   rC   ru   r   r   r   r   r.   r   r   r   r     s5        . . . (>>dLN NK&x88$$% %H "#L#L#'$CD D 833T4>@ @LX@@$DF FN *.G G G G K K K
A 
A 
A 
A3 3 3 GGGr   r   )r   	threadingr   ImportErrordummy_threadingr6   dbus._expat_introspect_parserr   dbus.exceptionsr   r   r   r   __docformat__	getLoggerr   r
   r   r   r   r   dbus._compatr   r   r0   r   rL   r   r.   r   r   <module>r      s  8 & & & &%%%%%%%%&     D D D D D D" " " " " " " " " " " " # '
N
+
+                    9 9 9 9 9 9 9 94]0 ]0 ]0 ]0 ]0 ]0 ]0 ]0@{ { { { {& { { {|	K K K K K K K K K Ks    