o
    •ºé`+  ã                   @   sÒ   d dl mZ d dlmZ ddlT g d¢ZG dd„ dƒZG dd	„ d	eƒZd
d„ Zd#dd„Z	d#dd„Z
d#dd„Zd#dd„ZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZd efd!d"„ZdS )$é    )ÚUnion)Úwarné   )Ú*)	ÚDBusAddressÚnew_method_callÚnew_method_returnÚ	new_errorÚ
new_signalÚMessageGeneratorÚ
PropertiesÚIntrospectableÚDBusErrorResponsec                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
r   aA  This identifies the object and interface a message is for.

    e.g. messages to display desktop notifications would have this address::

        DBusAddress('/org/freedesktop/Notifications',
                    bus_name='org.freedesktop.Notifications',
                    interface='org.freedesktop.Notifications')
    Nc                 C   s   || _ || _|| _d S ©N)Úobject_pathÚbus_nameÚ	interface©Úselfr   r   r   © r   ú2/usr/lib/python3/dist-packages/jeepney/wrappers.pyÚ__init__   s   
zDBusAddress.__init__c                 C   s   d  t| ƒj| j| j| j¡S )Nz'{}({!r}, bus_name={!r}, interface={!r}))ÚformatÚtypeÚ__name__r   r   r   ©r   r   r   r   Ú__repr__    s   ÿzDBusAddress.__repr__c                 C   s   t | ƒ| j| j|ƒS r   )r   r   r   )r   r   r   r   r   Úwith_interface$   s   zDBusAddress.with_interface©NN)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    
r   c                       s   e Zd Zd‡ fdd„	Z‡  ZS )Ú
DBusObjectNc                    s    t ƒ  |||¡ tddd� d S )Nz)Deprecated alias, use DBusAddress insteadé   )Ú
stacklevel)Úsuperr   r   r   ©Ú	__class__r   r   r   (   s   zDBusObject.__init__r   )r   r   r    r   Ú__classcell__r   r   r&   r   r"   '   s    r"   c              	   C   s   t tj| ddddi d�S )Nr   r   éÿÿÿÿ)ÚflagsÚprotocol_versionÚbody_lengthÚserialÚfields)ÚHeaderÚ
EndiannessÚlittle)Úmsg_typer   r   r   Ú
new_header,   s   ÿr3   Nr   c                 C   sz   t tjƒ}| j|jtj< | jdu rtdƒ‚| j|jtj	< | j
dur(| j
|jtj
< ||jtj< |dur8||jtj< t||ƒS )aÀ  Construct a new method call message

    This is a relatively low-level method. In many cases, this will be called
    from a :class:`MessageGenerator` subclass which provides a more convenient
    API.

    :param DBusAddress remote_obj: The object to call a method on
    :param str method: The name of the method to call
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data (i.e. method parameters)
    Nz3remote_obj.bus_name cannot be None for method calls)r3   ÚMessageTypeÚmethod_callr   r.   ÚHeaderFieldsÚpathr   Ú
ValueErrorÚdestinationr   ÚmemberÚ	signatureÚMessage)Ú
remote_objÚmethodr;   ÚbodyÚheaderr   r   r   r   0   s   



r   c                 C   s^   t tjƒ}| jj|jtj< | jj tj	d¡}|dur ||jtj
< |dur*||jtj< t||ƒS )zÇConstruct a new response message

    :param Message parent_msg: The method call this is a reply to
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    N)r3   r4   Úmethod_returnr@   r-   r.   r6   Úreply_serialÚgetÚsenderr9   r;   r<   )Ú
parent_msgr;   r?   r@   rD   r   r   r   r   I   s   

r   c                 C   sj   t tjƒ}| jj|jtj< ||jtj< | jj 	tj
d¡}|dur&||jtj< |dur0||jtj< t||ƒS )zþConstruct a new error response message

    :param Message parent_msg: The method call this is a reply to
    :param str error_name: The name of the error
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    N)r3   r4   Úerrorr@   r-   r.   r6   rB   Ú
error_namerC   rD   r9   r;   r<   )rE   rG   r;   r?   r@   rD   r   r   r   r	   Y   s   

r	   c                 C   sb   t tjƒ}| j|jtj< | jdu rtdƒ‚| j|jtj< ||jtj	< |dur,||jtj
< t||ƒS )zïConstruct a new signal message

    :param DBusAddress emitter: The object sending the signal
    :param str signal: The name of the signal
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    Nz,emitter.interface cannot be None for signals)r3   r4   Úsignalr   r.   r6   r7   r   r8   r:   r;   r<   )ÚemitterrH   r;   r?   r@   r   r   r   r
   k   s   


r
   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )r   z™Subclass this to define the methods available on a DBus interface.
    
    jeepney.bindgen can automatically create subclasses using introspection.
    c                 C   s   || _ || _d S r   )r   r   )r   r   r   r   r   r   r   ƒ   s   
zMessageGenerator.__init__c                 C   s   d  t| ƒj| j| j¡S )Nz{}({!r}, bus_name={!r}))r   r   r   r   r   r   r   r   r   r   ‡   s   ÿzMessageGenerator.__repr__N)r   r   r    r!   r   r   r   r   r   r   r   ~   s    r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	ProxyBasezÖA proxy is an IO-aware wrapper around a MessageGenerator
    
    Calling methods on a proxy object will send a message and wait for the
    reply. This is a base class for proxy implementations in jeepney.io.
    c                 C   s
   || _ d S r   )Ú_msggen)r   Úmsggenr   r   r   r   ’   s   
zProxyBase.__init__c                 C   s:   |  d¡r	t|ƒ‚t| j|d ƒ}t|ƒr|  |¡S t|ƒ‚)NÚ__)Ú
startswithÚAttributeErrorÚgetattrrL   ÚcallableÚ_method_call)r   ÚitemÚmake_msgr   r   r   Ú__getattr__•   s   

zProxyBase.__getattr__c                 C   s   t dƒ‚)Nz#Needs to be implemented in subclass)ÚNotImplementedError)r   rU   r   r   r   rS   Ÿ   s   zProxyBase._method_callN)r   r   r    r!   r   rV   rS   r   r   r   r   rK   Œ   s
    
rK   c                   @   s>   e Zd ZdZdeeef fdd„Zdd„ Zdd„ Z	d	d
„ Z
dS )r   zäBuild messages for accessing object properties

    If a D-Bus object has multiple interfaces, each interface has its own
    set of properties.

    This uses the standard DBus interface ``org.freedesktop.DBus.Properties``
    Úobjc                 C   s   || _ t|j|jdd�| _d S )Nzorg.freedesktop.DBus.Properties)r   r   )rX   r   r   r   Úprops_if)r   rX   r   r   r   r   ª   s   
ÿzProperties.__init__c                 C   s   t | jdd| jj|fƒS )z$Get the value of the property *name*ÚGetÚss©r   rY   rX   r   )r   Únamer   r   r   rC   ¯   s   

ÿzProperties.getc                 C   s   t | jdd| jjfƒS )z*Get all property values for this interfaceÚGetAllÚsr\   r   r   r   r   Úget_all´   s   
ÿzProperties.get_allc                 C   s   t | jdd| jj|||ffƒS )z?Set the property *name* to *value* (with appropriate signature)ÚSetÚssvr\   )r   r]   r;   Úvaluer   r   r   Úset¹   s   
ÿzProperties.setN)r   r   r    r!   r   r   r   r   rC   r`   rd   r   r   r   r   r   ¢   s    r   c                   @   s   e Zd ZdZdd„ ZdS )r   z#org.freedesktop.DBus.Introspectablec                 C   s
   t | dƒS )z3Request D-Bus introspection XML for a remote objectÚ
Introspect)r   r   r   r   r   re   Á   s   
zIntrospectable.IntrospectN)r   r   r    r   re   r   r   r   r   r   ¾   s    r   c                   @   rJ   )r   z?Raised by proxy method calls when the reply is an error messagec                 C   s   |j j tj¡| _|j| _d S r   )r@   r.   rC   r6   rG   r]   r?   Údata)r   Úmsgr   r   r   r   Ç   s   zDBusErrorResponse.__init__c                 C   s   d  | j| j¡S )Nz[{}] {})r   r]   rf   r   r   r   r   Ú__str__Ë   s   zDBusErrorResponse.__str__N)r   r   r    r!   r   rh   r   r   r   r   r   Å   s    r   rg   c                 C   s   | j jtjkrt| ƒ‚| jS )z³Get the body of a message, raising DBusErrorResponse for error messages

    This is to be used with replies to method_call messages, which may be
    method_return or error.
    )r@   Úmessage_typer4   rF   r   r?   )rg   r   r   r   Ú
unwrap_msgÏ   s   rj   )Nr   )Útypingr   Úwarningsr   Ú	low_levelÚ__all__r   r"   r3   r   r   r	   r
   r   rK   r   r   Ú	Exceptionr   r<   rj   r   r   r   r   Ú<module>   s"    




