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   ÚasyncioÚ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   Ú
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   ÚfeedÚauthenticatedr%   Úerrorr   Úset_exceptionr   )r   Údatar   r   r   r#   !   s   ÿzDBusProtocol.data_receivedc                 C   s"   | j  |¡D ]}| j |¡ qd S r   )r   r&   r   Ú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   ÚdoneÚRuntimeErrorr   ÚoutgoingÚ	serialiser   r   )r   ÚmessageÚ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Ú	TypeErrorr3   )r   r1   r   r   r   Úsend_and_get_reply5   s   €zDBusProtocol.send_and_get_replyN)
Ú__name__Ú
__module__Ú__qualname__r   r    r%   r#   r"   r3   r8   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 )ÚProxyz¬An 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   ÚmsggenÚprotocol©Ú	__class__r   r   r   A   s   
zProxy.__init__c                 C   s   d  | j| j¡S )NzProxy({}, {}))ÚformatÚ_msggenr>   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   )r4   r5   r   r6   r>   r8   )ÚargsÚkwargsr,   ©Úmake_msgr   r   r   ÚinnerI   s   €z!Proxy._method_call.<locals>.innerr   )r   rI   rJ   r   rH   r   Ú_method_callH   s   zProxy._method_call)r9   r:   r;   Ú__doc__r   rE   rK   Ú__classcell__r   r   rA   r   r<   ;   s
    r<   Ú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   Úget_event_loopÚcreate_unix_connectionr   r	   r   r<   r
   ÚHellor   )ÚbusÚloopÚtÚpÚhello_replyr   r   r   Úconnect_and_authenticateQ   s   €

rX   )rN   N)rL   r   Úwarningsr   Újeepneyr   r   Újeepney.authr   r   r   r   Újeepney.busr	   Újeepney.bus_messagesr
   Újeepney.routingr   Újeepney.wrappersr   ÚProtocolr   r<   rX   r   r   r   r   Ú<module>   s    ÿ,