
    ;Si                     \    d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlm	Z	  G d d      Z
y)    N   )	TLRequest)MessageContainer)	TLMessagec                   (    e Zd ZdZd Zd Zd Zd Zy)MessagePackeraN  
    This class packs `RequestState` as outgoing `TLMessages`.

    The purpose of this class is to support putting N `RequestState` into a
    queue, and then awaiting for "packed" `TLMessage` in the other end. The
    simplest case would be ``State -> TLMessage`` (1-to-1 relationship) but
    for efficiency purposes it's ``States -> Container`` (N-to-1).

    This addresses several needs: outgoing messages will be smaller, so the
    encryption and network overhead also is smaller. It's also a central
    point where outgoing requests are put, and where ready-messages are get.
    c                     || _         t        j                         | _        t	        j
                         | _        |t           | _        y N)	_statecollectionsdeque_dequeasyncioEvent_ready__name___log)selfstateloggerss      f/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/extensions/messagepacker.py__init__zMessagePacker.__init__   s2    !'')mmoH%	    c                 n    | j                   j                  |       | j                  j                          y r
   )r   appendr   set)r   r   s     r   r   zMessagePacker.append   s"    5!r   c                 n    | j                   j                  |       | j                  j                          y r
   )r   extendr   r   )r   statess     r   r   zMessagePacker.extend#   s"    6"r   c                   K   | j                   s<| j                  j                          | j                  j                          d{    t	        j
                         }g }d}| j                   rt        |      t        j                  k  r| j                   j                         }|t        |j                        t        j                  z   z  }|t        j                  k  r| j                  j                  ||j                  t!        |j"                  t$              |j&                  r|j&                  j(                  nd      |_        |j+                  |       | j,                  j/                  d|j(                  |j"                  j0                  j2                  t5        |j"                               T|r| j                   j7                  |       nv| j,                  j9                  d|j"                  j0                  j2                  t        |j                               |j:                  j=                  t?        d             d}|syt        |      dkD  rtA        jB                  d	t        jD                  t        |            |jG                         z   }t	        j
                         }| j                  j                  ||d
      }|D ]	  }||_$         |jG                         }||fS 7 w)z
        Returns (batch, data) if one or more items could be retrieved.

        If the cancellation occurs or only invalid items were in the
        queue, (None, None) will be returned instead.
        Nr   )after_idzAssigned msg_id = %d to %s (%x)z:Message payload for %s is too long (%d) and cannot be sentzRequest payload is too big)NN   z<IiF)content_related)%r   r   clearwaitioBytesIOlenr   MAXIMUM_LENGTHpopleftdatar   SIZE_OVERHEADMAXIMUM_SIZEr   write_data_as_message
isinstancerequestr   aftermsg_idr   r   debug	__class__r   id
appendleftwarningfutureset_exception
ValueErrorstructpackCONSTRUCTOR_IDgetvaluecontainer_id)r   bufferbatchsizer   r+   r?   ss           r   getzMessagePacker.get'   sK     {{KK++""$$$ kkc%j,<,K,KKKK'')EC

Oi&=&===D'444#{{@@EJJ
5==)(L38;;U[[//D  A   U#		 A %emm.E.E.N.N "5== 13 &&u- IIL''00#ejj/ LL&&78: Du:>;;'66E
!"D ZZ\F;;<<e = L  .!-.  d{ %s   AK2K/J)K2N)r   
__module____qualname____doc__r   r   r   rD    r   r   r   r      s    &Hr   r   )r   r   r&   r;   tlr   tl.core.messagecontainerr   tl.core.tlmessager   r   rH   r   r   <module>rL      s&      	   7 )d dr   