B
    R[h
                 @   s   d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mZ ddlmZmZ ddlmZ ddlmZ dd	lmZ G d
d dZG dd deZdddZedkre Zedej dS )z'Synchronous IO wrappers around jeepney
    )FutureN)
SASLParsermake_auth_externalBEGINAuthenticationError)get_bus)ParserMessageType)	ProxyBase)Router)message_busc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
DBusConnectionc             C   s<   || _ t | _tt| _tt| | _| j	 }|d | _
d S )Nr   )sockr   parserr   r   routerProxyr   Z	bus_proxyZHellounique_name)selfr   Zhello_reply r   9lib/python3.7/site-packages/jeepney/integrate/blocking.py__init__   s    

zDBusConnection.__init__c             C   s$   | j |}| }| j| |S )N)r   ZoutgoingZ	serialiser   sendall)r   messagefuturedatar   r   r   send_message   s    zDBusConnection.send_messagec             C   sD   x>| j d}| j|}|rx|D ]}| j| q$W dS qW dS )zRead data from the socket and handle incoming messages.
        
        Blocks until at least one message has been read.
        i   N)r   recvr   feedr   Zincoming)r   bZmsgsmsgr   r   r   recv_messages   s    
zDBusConnection.recv_messagesc             C   s(   |  |}x| s|   qW | S )z:Send a message, wait for the reply and return it.
        )r   Zdoner    result)r   r   r   r   r   r   send_and_get_reply*   s    

z!DBusConnection.send_and_get_replyN)__name__
__module____qualname__r   r   r    r"   r   r   r   r   r      s   r   c                   s,   e Zd Z fddZdd Zdd Z  ZS )r   c                s   t  | || _d S )N)superr   _connection)r   ZmsggenZ
connection)	__class__r   r   r   4   s    zProxy.__init__c             C   s   d | j| jS )NzProxy({}, {}))formatZ_msggenr'   )r   r   r   r   __repr__8   s    zProxy.__repr__c                s   t   fdd}|S )Nc                 s(    | |}|j jtjkstj|S )N)headerZmessage_typer	   Zmethod_callAssertionErrorr'   r"   )argskwargsr   )make_msgr   r   r   inner<   s    
z!Proxy._method_call.<locals>.inner)	functoolswraps)r   r/   r0   r   )r/   r   r   _method_call;   s    zProxy._method_call)r#   r$   r%   r   r*   r3   __classcell__r   r   )r(   r   r   3   s   r   SESSIONc             C   s   t | }tjtjd}|| |dt   t }x*|js`||	d |j
r8t|j
q8W |t t|}|j|j_|S )N)Zfamily    i   )r   socketZAF_UNIXZconnectr   r   r   Zauthenticatedr   r   errorr   r   r   bufferr   Zbuf)ZbusZbus_addrr   Zauth_parserconnr   r   r   connect_and_authenticateE   s    


r;   __main__zUnique name:)r5   )__doc__Zasyncior   r1   r7   Zjeepney.authr   r   r   r   Zjeepney.busr   Zjeepney.low_levelr   r	   Zjeepney.wrappersr
   Zjeepney.routingr   Zjeepney.bus_messagesr   r   r   r;   r#   r:   printr   r   r   r   r   <module>   s   %
