B
    R[                 @   s   d dl mZ d dlmZ ddlT ddddd	d
ddg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S )#    )Union)warn   )*DBusAddressnew_method_callnew_method_return	new_error
new_signalMessageGenerator
Properties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   /lib/python3.7/site-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 )N)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   
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   r   r   r   )	__class__r   r   r   '   s    zDBusObject.__init__)NN)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   )flagsZprotocol_versionZbody_lengthserialfields)ZHeaderZ
Endiannesslittle)Zmsg_typer   r   r   
new_header+   s    r(   Nr   c             C   sz   t tj}| j|jtj< | jdkr*td| j|jtj	< | j
dk	rP| j
|jtj
< ||jtj< |dk	rp||jtj< t||S )a  Construct a new method call message

    :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)r(   MessageTypeZmethod_callr   r&   HeaderFieldspathr   
ValueErrorZdestinationr   member	signatureMessage)Z
remote_objmethodr.   bodyheaderr   r   r   r   /   s    


c             C   s8   t tj}| jj|jtj< |dk	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)
r(   r)   Zmethod_returnr2   r%   r&   r*   reply_serialr.   r/   )
parent_msgr.   r1   r2   r   r   r   r   D   s
    
c             C   sD   t tj}| jj|jtj< ||jtj< |dk	r:||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 signature: The DBus signature of the body data
    :param tuple body: Body data
    N)r(   r)   errorr2   r%   r&   r*   r3   
error_namer.   r/   )r4   r6   r.   r1   r2   r   r   r   r	   Q   s    
c             C   sb   t tj}| j|jtj< | jdkr*td| j|jtj< ||jtj	< |dk	rX||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)r(   r)   signalr   r&   r*   r+   r   r,   r-   r.   r/   )Zemitterr7   r.   r1   r2   r   r   r   r
   _   s    

c               @   s    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 )N)r   r   )r   r   r   r   r   r   r   w   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   r   s   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.integrate.
    c             C   s
   || _ d S )N)_msggen)r   Zmsggenr   r   r   r      s    zProxyBase.__init__c             C   s>   | drt|t| j|d }t|r2| |S t|d S )N__)
startswithAttributeErrorgetattrr9   callable_method_call)r   itemmake_msgr   r   r   __getattr__   s    

zProxyBase.__getattr__c             C   s   t dd S )Nz#Needs to be implemented in subclass)NotImplementedError)r   rA   r   r   r   r?      s    zProxyBase._method_callN)r   r   r   r   r   rB   r?   r   r   r   r   r8      s   
r8   c               @   s>   e Zd ZdZeeef dddZdd Zdd Z	d	d
 Z
dS )r   z~Build messages for accessing object 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   )rD   r   r   r   props_if)r   rD   r   r   r   r      s    
zProperties.__init__c             C   s   t | jdd| jj|fS )NZGetZss)r   rE   rD   r   )r   namer   r   r   get   s    
zProperties.getc             C   s   t | jdd| jjfS )NZGetAlls)r   rE   rD   r   )r   r   r   r   get_all   s    
zProperties.get_allc             C   s   t | jdd| jj|||ffS )NSetZssv)r   rE   rD   r   )r   rF   r.   valuer   r   r   set   s    
zProperties.setN)r   r   r   r   r   r   r   r   rG   rI   rL   r   r   r   r   r      s
   c               @   s   e Zd ZdZdd ZdS )Introspectablez#org.freedesktop.DBus.Introspectablec             C   s
   t | dS )N
Introspect)r   )r   r   r   r   rN      s    zIntrospectable.IntrospectN)r   r   r   r   rN   r   r   r   r   rM      s   rM   c               @   s   e Zd Zdd Zdd ZdS )r   c             C   s   |j jtj| _|j| _d S )N)r2   r&   rG   r*   r6   rF   r1   data)r   msgr   r   r   r      s    zDBusErrorResponse.__init__c             C   s   d | j| jS )Nz[{}] {})r   rF   rO   )r   r   r   r   __str__   s    zDBusErrorResponse.__str__N)r   r   r   r   rQ   r   r   r   r   r      s   )Nr   )Nr   )Nr   )Nr   )typingr   warningsr   Z	low_level__all__r   r   r(   r   r   r	   r
   r   r8   r   rM   	Exceptionr   r   r   r   r   <module>   s,   



