o
    `	                     @   s   d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ dd	lmZ ed
dd G dd dejZG dd deZdddZdS )z*Deprecated: use jeepney.io.asyncio instead    N)warn)ParserMessageType)AuthenticationErrorBEGINmake_auth_external
SASLParser)get_bus)message_bus)Router)	ProxyBasezOjeepney.integrate.asyncio is deprecated: please use jeepney.io.asyncio instead.   )
stacklevelc                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )DBusProtocolc                 C   s0   t  | _t | _ttj| _t | _d | _	d S N)
r   auth_parserr   parserr   asyncioZFuturerouterauthenticationunique_nameself r   ;/usr/lib/python3/dist-packages/jeepney/integrate/asyncio.py__init__   s
   

zDBusProtocol.__init__c                 C   s   || _ | j dt   d S )N    )	transportwriter   )r   r   r   r   r   connection_made   s   zDBusProtocol.connection_madec                 C   s2   | j t | jd | j| _| | jj d S )NT)	r   r   r   r   Z
set_resultdata_received_post_authdata_receivedr   bufferr   r   r   r   _authenticated   s   zDBusProtocol._authenticatedc                 C   sD   | j | | j jr|   d S | j jr | jt| j j d S d S r   )r   feedZauthenticatedr#   errorr   Zset_exceptionr   )r   datar   r   r   r!   !   s   zDBusProtocol.data_receivedc                 C   s"   | j |D ]}| j| qd S r   )r   r$   r   Zincoming)r   r&   msgr   r   r   r    (   s   z$DBusProtocol.data_received_post_authc                 C   s6   | j  s	td| j|}| }| j| |S )Nz/Wait for authentication before sending messages)r   ZdoneRuntimeErrorr   ZoutgoingZ	serialiser   r   )r   messageZfuturer&   r   r   r   send_message,   s   
zDBusProtocol.send_messagec                    s(   |j jtjkrtd| |I d H S )Nz&Only method call messages have replies)headermessage_typer   method_call	TypeErrorr*   )r   r)   r   r   r   send_and_get_reply5   s   zDBusProtocol.send_and_get_replyN)
__name__
__module____qualname__r   r   r#   r!   r    r*   r/   r   r   r   r   r      s    	r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )ProxyzAn asyncio proxy for calling D-Bus methods

    :param msggen: A message generator object.
    :param DBusProtocol proto: Protocol object to send and receive messages.
    c                    s   t  | || _d S r   )superr   	_protocol)r   ZmsggenZprotocol	__class__r   r   r   A   s   
zProxy.__init__c                 C   s   d | j| jS )NzProxy({}, {}))formatZ_msggenr5   r   r   r   r   __repr__E   s   zProxy.__repr__c                    s    fdd}|S )Nc                     s4    | i |}|j jtju sJ j|I d H S r   )r+   r,   r   r-   r5   r/   )argskwargsr'   make_msgr   r   r   innerI   s   z!Proxy._method_call.<locals>.innerr   )r   r=   r>   r   r<   r   _method_callH   s   zProxy._method_call)r0   r1   r2   __doc__r   r9   r?   __classcell__r   r   r6   r   r3   ;   s
    r3   SESSIONc                    sd   |d u r	t  }|jtt| dI d H \}}|jI d H  tt|} |  I d H }|d |_	||fS )N)pathr   )
r   Zget_event_loopZcreate_unix_connectionr   r	   r   r3   r
   ZHellor   )ZbusZlooptpZhello_replyr   r   r   connect_and_authenticateQ   s   

rF   )rB   N)r@   r   warningsr   Zjeepneyr   r   Zjeepney.authr   r   r   r   Zjeepney.busr	   Zjeepney.bus_messagesr
   Zjeepney.routingr   Zjeepney.wrappersr   ZProtocolr   r3   rF   r   r   r   r   <module>   s    ,