509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
iRÛVÔ`  ã               @   sÜ   d dl Z yd dlmZ W n  ek
r8   d dlmZ Y nX 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
„ d
ƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZdS )é    N)ÚRLock)Úprocess_introspection_data)ÚDBusExceptionÚIntrospectionParserExceptionÚMissingErrorHandlerExceptionÚMissingReplyHandlerExceptionZrestructuredtextzdbus.proxies)ÚBUS_DAEMON_IFACEÚBUS_DAEMON_NAMEÚBUS_DAEMON_PATHÚINTROSPECTABLE_IFACEÚ
LOCAL_PATH)Úis_py2c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_DeferredMethodzXA proxy method which will only get called once we have its
    introspection reply.
    c             C   s   || _ |j| _|| _|| _d S )N)Ú_proxy_methodÚ_method_nameÚ_appendÚ_block)ÚselfÚproxy_methodÚappendÚblock© r   ú/usr/lib64/python3.6/proxies.pyÚ__init__6   s    z_DeferredMethod.__init__c             O   s@   d|ks|j ddƒr(| j| j||ƒ d S | jƒ  | j||ŽS d S )NÚreply_handlerÚignore_replyF)Úgetr   r   r   )r   ÚargsÚkeywordsr   r   r   Ú__call__=   s    z_DeferredMethod.__call__c             O   s   | j | j||ƒ d S )N)r   r   )r   r   r   r   r   r   Ú
call_asyncH   s    z_DeferredMethod.call_asyncN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r   r   r   r   r   2   s   r   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_ProxyMethodz°A 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             C   sX   |t krtdt  ƒ‚|| _|| _|| _|| _tj|ƒ || _|d k	rNtj	|ƒ || _
d S )Nz1Methods may not be called on the reserved path %s)r   r   Ú_proxyÚ_connectionÚ_named_serviceÚ_object_pathÚ_dbus_bindingsZvalidate_member_namer   Zvalidate_interface_nameÚ_dbus_interface)r   ÚproxyZ
connectionÚbus_nameÚobject_pathZmethod_nameZifacer   r   r   r   S   s    

z_ProxyMethod.__init__c       	   	   O   s  |j dd ƒ}|j dd ƒ}|j ddƒ}|j dd ƒ}|d k	s@|d k	rl|d krPtƒ ‚n|d kr`tƒ ‚n|rltdƒ‚|j d| jƒ}|d kr°|d kr’| j}n|d | j }| jjj|d ƒ}|s¼|d k	râ| j	j
| j| j|| j||||f|Ž n | j	j| j| j|| j||f|ŽS d S )	Nr   Úerror_handlerr   FÚ	signaturez6ignore_reply and reply_handler cannot be used togetherÚdbus_interfaceÚ.)Úpopr   r   Ú	TypeErrorr+   r   r&   Ú_introspect_method_mapr   r'   r    r(   r)   Zcall_blocking)	r   r   r   r   r/   r   r0   r1   Úkeyr   r   r   r   g   sD    

z_ProxyMethod.__call__c          	   O   sŒ   |j dd ƒ}|j dd ƒ}|j dd ƒ}|j d| jƒ}|d krd|rN|d | j }n| j}| jjj|d ƒ}| jj| j| j	|| j||||f|Ž d S )Nr   r/   r0   r1   r2   )
r3   r+   r   r&   r5   r   r'   r    r(   r)   )r   r   r   r   r/   r0   r1   r6   r   r   r   r    “   s$    
z_ProxyMethod.call_asyncN)r!   r"   r#   r$   r   r   r    r   r   r   r   r%   L   s   ,r%   c               @   s¼   e Zd ZdZeZeZdZdZ	dZ
d%dd	„Zed
d„ dddƒZedd„ dddƒZedd„ dddƒZd&dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd'd!d"„Zd#d$„ ZeZdS )(ÚProxyObjectz£A 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       
      K   s<  |j ddƒ}|dk	rB|dk	r$tdƒ‚|}ddlm} |dtdd� |j d	dƒ}	|	dk	r„|dk	rftd
ƒ‚|	}ddlm} |dtdd� |ržtddj|jƒ ƒ ƒ‚|rª|jƒ  || _|dk	rÂt	j
|ƒ | | _| _t	j|ƒ || _|sî|j|ƒ| _d| _g | _i | _tƒ | _| �s| jtk�r&| j| _n| j| _| 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 parametersr9   )Ú
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, )r3   r4   Úwarningsr;   ÚDeprecationWarningÚjoinÚkeysZ_require_main_loopÚ_busr*   Zvalidate_bus_namer(   Ú_requested_bus_nameZvalidate_object_pathÚ__dbus_object_path__Zactivate_name_ownerÚ_pending_introspectÚ_pending_introspect_queuer5   r   Ú_introspect_lockr   Ú INTROSPECT_STATE_DONT_INTROSPECTÚ_introspect_stateÚ'INTROSPECT_STATE_INTROSPECT_IN_PROGRESSÚ_Introspect)
r   Zconnr-   r.   Z
introspectZfollow_name_owner_changesÚkwargsr:   r;   r=   r   r   r   r   ¹   sJ    




zProxyObject.__init__c             C   s   | j S )N)r(   )r   r   r   r   Ú<lambda>  s    zProxyObject.<lambda>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             C   s   | j S )N)rC   )r   r   r   r   rM     s    z[The bus name which was requested when this proxy was
            instantiated.
            c             C   s   | j S )N)rD   )r   r   r   r   rM   $  s    zThe object-path of this proxy.c             K   s"   | 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_namer1   r-   Úpath)rB   Zadd_signal_receiverr(   rD   )r   rN   Úhandler_functionr1   r   r   r   r   Úconnect_to_signal0  s    <
zProxyObject.connect_to_signalc          	   C   s>   i }t rd|d< | jj| j| jtddf | j| jfddi|—ŽS )NTZutf8_stringsZ
IntrospectÚ Zrequire_main_loopF)r   rB   r    r(   rD   r   Ú_introspect_reply_handlerÚ_introspect_error_handler)r   rL   r   r   r   rK   s  s    
zProxyObject._Introspectc             C   s*   x| j D ]\}}}|||Ž qW g | _ d S )N)rF   )r   r   r   r   r   r   r   Ú_introspect_execute_queue~  s    z%ProxyObject._introspect_execute_queuec             C   sp   | j jƒ  zTyt|ƒ| _W n* tk
rD } z| j|ƒ d S d }~X nX | j| _d | _| j	ƒ  W d | j j
ƒ  X d S )N)rG   Úacquirer   r5   r   rT   Ú INTROSPECT_STATE_INTROSPECT_DONErI   rE   rU   Úrelease)r   ÚdataÚer   r   r   rS   †  s    

z%ProxyObject._introspect_reply_handlerc          
   C   sh   t jƒ  tjd| j| j|jj|jj|ƒ | j	j
ƒ  z$tjdƒ | j| _d | _| jƒ  W d | j	jƒ  X d S )Nz$Introspect error on %s:%s: %s.%s: %sz'Executing introspect queue due to error)ÚloggingZbasicConfigÚ_loggerÚerrorr(   rD   Ú	__class__r"   r!   rG   rV   ÚdebugrH   rI   rE   rU   rX   )r   r]   r   r   r   rT   •  s    

z%ProxyObject._introspect_error_handlerc          
   C   s4   | j jƒ  z| jd k	r | jjƒ  W d | j jƒ  X d S )N)rG   rV   rE   r   rX   )r   r   r   r   Ú_introspect_block¤  s
    

zProxyObject._introspect_blockc          
   C   sJ   | j jƒ  z.| j| jkr,| jj|||fƒ n
|||Ž W d | j jƒ  X d S )N)rG   rV   rI   rJ   rF   r   rX   )r   Úcallbackr   rL   r   r   r   Ú_introspect_add_to_queue®  s    
z$ProxyObject._introspect_add_to_queuec             C   s,   |j dƒr|jdƒrt|ƒ‚n
| j|ƒS d S )NÚ__)Ú
startswithÚendswithÚAttributeErrorÚget_dbus_method)r   Úmemberr   r   r   Ú__getattr__º  s    
zProxyObject.__getattr__c             C   s<   | j | | j| j| j||ƒ}| j| jkr8| j|| 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.
        )	ÚProxyMethodClassrB   r(   rD   rI   rJ   ÚDeferredMethodClassrb   r`   )r   rh   r1   Úretr   r   r   rg   À  s    

zProxyObject.get_dbus_methodc             C   s   d| j | j| jt| ƒf S )Nz&<ProxyObject wrapping %s %s %s at %#x>)rB   r(   rD   Úid)r   r   r   r   Ú__repr__æ  s    zProxyObject.__repr__)NNNTF)N)N)r!   r"   r#   r$   r%   rj   r   rk   rH   rJ   rW   r   Úpropertyr-   Úrequested_bus_namer.   rQ   rK   rU   rS   rT   r`   rb   ri   rg   rn   Ú__str__r   r   r   r   r7   ¬   s6    
R

C

&r7   c               @   sž   e Zd ZdZdd„ Zedd„ dddƒZeZedd„ ddd	ƒZed
d„ dddƒZ	edd„ dddƒZ
edd„ dddƒZddd„Zdd„ Zddd„Zdd„ ZeZdS )Ú	Interfacez An 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             C   s$   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)Ú
isinstancerr   Úproxy_objectÚ_objr+   )r   Úobjectr1   r   r   r   r   ô  s    	

zInterface.__init__c             C   s   | j jS )N)ru   r.   )r   r   r   r   rM     s    zInterface.<lambda>Nz.The D-Bus object path of the underlying objectc             C   s   | j jS )N)ru   r-   )r   r   r   r   rM     s    z:The bus name to which the underlying proxy object is boundc             C   s   | j jS )N)ru   rp   )r   r   r   r   rM   	  s    zGThe bus name which was requested when the underlying object was createdc             C   s   | j S )N)ru   )r   r   r   r   rM     s    zThe underlying proxy objectc             C   s   | j S )N)r+   )r   r   r   r   rM     s    zThe D-Bus interface representedc             K   s   |s
| j }| jj|||f|Ž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.
        )r+   ru   rQ   )r   rN   rP   r1   r   r   r   r   rQ     s    

zInterface.connect_to_signalc             C   s2   |j dƒr|jdƒrt|ƒ‚n| jj|| jƒS d S )Nrc   )rd   re   rf   ru   rg   r+   )r   rh   r   r   r   ri   "  s    
zInterface.__getattr__c             C   s   |dkr| 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.
        N)r+   ru   rg   )r   rh   r1   r   r   r   rg   (  s    zInterface.get_dbus_methodc             C   s   d| j | jt| ƒf S )Nz%<Interface %r implementing %r at %#x>)ru   r+   rm   )r   r   r   r   rn   4  s    zInterface.__repr__)N)N)r!   r"   r#   r$   r   ro   r.   rD   r-   rp   rt   r1   rQ   ri   rg   rn   rq   r   r   r   r   rr   ì  s&   

rr   )r[   Z	threadingr   ÚImportErrorZdummy_threadingr*   Zdbus._expat_introspect_parserr   Zdbus.exceptionsr   r   r   r   Z__docformat__Z	getLoggerr\   r   r	   r
   r   r   Zdbus._compatr   r   r%   rv   r7   rr   r   r   r   r   Ú<module>   s"   
`  B