U
    ¯ªh^  ã                   @   s\   d dl Z d dlZd dlZddlmZmZ G dd„ deƒZG dd„ deƒZG dd	„ d	eƒZdS )
é    Né   )Ú
ConnectionÚPacketCodecc                   @   s$   e Zd ZdZeZdd„ Zdd„ ZdS )ÚIntermediatePacketCodecs   îîîîc                 C   s   t  dt|ƒ¡| S )Nú<i)ÚstructÚpackÚlen)ÚselfÚdata© r   úO/tmp/pip-unpacked-wheel-c81u5j2r/telethon/network/connection/tcpintermediate.pyÚencode_packet   s    z%IntermediatePacketCodec.encode_packetc                 Ã   s,   t  d| d¡I d H ¡d }| |¡I d H S )Nr   é   r   )r   ÚunpackZreadexactly)r
   ÚreaderÚlengthr   r   r   Úread_packet   s    z#IntermediatePacketCodec.read_packetN)Ú__name__Ú
__module__Ú__qualname__ÚtagÚobfuscate_tagr   r   r   r   r   r   r      s   r   c                       s4   e Zd ZdZdZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú!RandomizedIntermediatePacketCodecz‡
    Data packets are aligned to 4bytes. This codec adds random bytes of size
    from 0 to 3 bytes, which are ignored by decoder.
    Ns   ÝÝÝÝc                    s&   t  dd¡}t |¡}tƒ  || ¡S )Nr   é   )ÚrandomÚrandintÚosÚurandomÚsuperr   )r
   r   Úpad_sizeÚpadding©Ú	__class__r   r   r      s    
z/RandomizedIntermediatePacketCodec.encode_packetc                 ƒ   s8   t ƒ  |¡I d H }t|ƒd }|dkr4|d | … S |S )Nr   r   )r   r   r	   )r
   r   Zpacket_with_paddingr    r"   r   r   r   !   s
    z-RandomizedIntermediatePacketCodec.read_packet)	r   r   r   Ú__doc__r   r   r   r   Ú__classcell__r   r   r"   r   r      s
   r   c                   @   s   e Zd ZdZeZdS )ÚConnectionTcpIntermediatezŠ
    Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
    Always sends 4 extra bytes for the packet length.
    N)r   r   r   r$   r   Zpacket_codecr   r   r   r   r&   )   s   r&   )	r   r   r   Ú
connectionr   r   r   r   r&   r   r   r   r   Ú<module>   s   