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 )zConstruct 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 )zConstruct 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 )zConstruct 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   zSubclass 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 )		ProxyBasezA 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   zBuild 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 )zGet 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"    




