3
uQh                 @   sB   d Z ddlZddlmZ ddlmZ ddlmZ G dd	 d	ZdS )
z
This module contains the class used to communicate with Telegram's servers
in plain text, when no authorization key has been created yet.
    N   )MTProtoState   )InvalidBufferError)BinaryReaderc               @   s    e Zd ZdZdd Zdd ZdS )MTProtoPlainSenderzw
    MTProto Mobile Protocol plain sender
    (https://core.telegram.org/mtproto/description#unencrypted-messages)
    c            C   s   t d|d| _|| _dS )zn
        Initializes the MTProto plain sender.

        :param connection: the Connection to be used.
        N)Zauth_keyloggers)r   _state_connection)self
connectionr    r   G/tmp/pip-build-2nz6shyl/telethon/telethon/network/mtprotoplainsender.py__init__   s    zMTProtoPlainSender.__init__c          	      s   t |}| jj }| jjtjdd|t|| I dH  | jj I dH }t|dk r\t	|t
|R}|j }|dks~td|j }|dkstd|j }|dkstd|j S Q R X dS )zF
        Sends and receives the result for the given request.
        z<qqir   N   zBad auth_key_idz
Bad msg_idz
Bad length)bytesr	   Z_get_new_msg_idr
   sendstructpacklenrecvr   r   Z	read_longAssertionErrorZread_intZtgread_object)r   requestbodyZmsg_idreaderZauth_key_idlengthr   r   r   r      s    
 
zMTProtoPlainSender.sendN)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   	r   )	r   r   Zmtprotostater   errorsr   
extensionsr   r   r   r   r   r   <module>   s
   