U
    [e+                  	   @   s   d dl mZ d dlmZ ddlT d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ed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   R/var/www/html/services/stratfitenv/lib/python3.8/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 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   
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__)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_versionbody_lengthserialfields)HeaderZ
Endiannesslittle)msg_typer   r   r   
new_header,   s
      r0   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

    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)r0   MessageTypemethod_callr   r,   HeaderFieldspathr   
ValueErrordestinationr   member	signatureMessage)Z
remote_objmethodr8   bodyheaderr   r   r   r   0   s    


c                 C   s^   t tj}| jj|jtj< | jjtj	d}|dk	r@||jtj
< |dk	rT||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)r0   r1   Zmethod_returnr<   r+   r,   r3   reply_serialgetsenderr6   r8   r9   )
parent_msgr8   r;   r<   r?   r   r   r   r   I   s    
c                 C   sj   t tj}| jj|jtj< ||jtj< | jj	tj
d}|dk	rL||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 error_name: The name of the error
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    N)r0   r1   errorr<   r+   r,   r3   r=   
error_namer>   r?   r6   r8   r9   )r@   rB   r8   r;   r<   r?   r   r   r   r	   Y   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)r0   r1   signalr   r,   r3   r4   r   r5   r7   r8   r9   )ZemitterrC   r8   r;   r<   r   r   r   r
   k   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 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   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   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getattrrE   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   rM   r   r   r   rK      s    zProxyBase._method_callN)r   r   r   r    r   rN   rK   r   r   r   r   rD      s   
rD   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   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   )rP   r   r   r   props_if)r   rP   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*ZGetssr   rQ   rP   r   )r   namer   r   r   r>      s    

zProperties.getc                 C   s   t | jdd| jjfS )z*Get all property values for this interfaceZGetAllsrS   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)SetZssvrS   )r   rT   r8   valuer   r   r   set   s    
zProperties.setN)r   r   r   r    r   r   r   r   r>   rV   rY   r   r   r   r   r      s
   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   rZ      s    zIntrospectable.IntrospectN)r   r   r   r   rZ   r   r   r   r   r      s   c                   @   s    e Zd ZdZdd Zdd ZdS )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,   r>   r3   rB   rT   r;   data)r   msgr   r   r   r      s    zDBusErrorResponse.__init__c                 C   s   d | j| jS )Nz[{}] {})r   rT   r[   r   r   r   r   __str__   s    zDBusErrorResponse.__str__N)r   r   r   r    r   r]   r   r   r   r   r      s   r\   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<   Zmessage_typer1   rA   r   r;   r^   r   r   r   
unwrap_msg   s    r_   )Nr   )Nr   )Nr   )Nr   )typingr   warningsr   Z	low_level__all__r   r!   r0   r   r   r	   r
   r   rD   r   r   	Exceptionr   r9   r_   r   r   r   r   <module>   s2   




