Ë
    ƒjÐjq  ã                   óä   — d Z ddlZddlZddl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 dd	lmZ  e ej                   d«      dd
 Ž Zej%                  ej&                  ¬«      Z G d„ d«      Zy)z6
This module contains the BinaryReader utility class.
é    N)ÚdatetimeÚtimezoneÚ	timedelta)ÚBytesIO)Úunpacké   )ÚTypeNotFoundError)Ú	tlobjects)Úcore_objectsé   )Útzinfoc                   ó–   — e Zd ZdZd„ Zd„ Zdd„Zdd„Zd„ Zd„ Z	dd„Z
dd	„Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚBinaryReaderz2
    Small utility class to read binary data.
    c                 ó2   — t        |«      | _        d | _        y ©N)r   ÚstreamÚ_last)ÚselfÚdatas     úš/var/labsstorage/home/Thilakkumar/htdocs/soical-media-automation/automation_platform/venv/lib/python3.12/site-packages/telethon/extensions/binaryreader.pyÚ__init__zBinaryReader.__init__   s   € Ü˜d“mˆŒØˆ�
ó    c                 ó*   — | j                  d«      d   S )zReads a single byte value.é   r   )Úread©r   s    r   Ú	read_bytezBinaryReader.read_byte   s   € à�y‰y˜‹|˜A‰Ðr   c                 óP   — t         j                  | j                  d«      d|¬«      S )z!Reads an integer (4 bytes) value.é   Úlittle©Ú	byteorderÚsigned©ÚintÚ
from_bytesr   ©r   r#   s     r   Úread_intzBinaryReader.read_int#   ó   € ä�~‰~˜dŸi™i¨›l°hÀvˆ~ÓNÐNr   c                 óP   — t         j                  | j                  d«      d|¬«      S )z%Reads a long integer (8 bytes) value.é   r    r!   r$   r'   s     r   Ú	read_longzBinaryReader.read_long'   r)   r   c                 ó>   — t        d| j                  d«      «      d   S )z,Reads a real floating point (4 bytes) value.z<fr   r   ©r   r   r   s    r   Ú
read_floatzBinaryReader.read_float+   ó   € ä�d˜DŸI™I a›LÓ)¨!Ñ,Ð,r   c                 ó>   — t        d| j                  d«      «      d   S )z,Reads a real floating point (8 bytes) value.z<dr+   r   r.   r   s    r   Úread_doublezBinaryReader.read_double/   r0   r   c                 óV   — t         j                  | j                  |dz  «      d|¬«      S )z"Reads a n-bits long integer value.r+   r    r!   r$   )r   Úbitsr#   s      r   Úread_large_intzBinaryReader.read_large_int3   s.   € ä�~‰~Ø�I‰I�d˜a‘iÓ ¨H¸Vð ó Eð 	Er   c           
      óô   — | j                   j                  |«      }|dk\  rPt        |«      |k7  rBt        dj	                  |t        |«      t        |«      t        | j                  «      «      «      ‚|| _        |S )z<Read the given amount of bytes, or -1 to read all remaining.r   z=No more data left to read (need {}, got {}: {}); last read {})r   r   ÚlenÚBufferErrorÚformatÚreprr   )r   ÚlengthÚresults      r   r   zBinaryReader.read8   sg   € à—‘×!Ñ! &Ó)ˆØ�aŠKœc &›k¨VÒ3ÜØOß‘˜¤ F£¬T°&«\¼4ÀÇ
Á
Ó;KÓLóð ð
 ˆŒ
Øˆr   c                 ó6   — | j                   j                  «       S )z?Gets the byte array representing the current buffer as a whole.)r   Úgetvaluer   s    r   Ú	get_byteszBinaryReader.get_bytesD   s   € à�{‰{×#Ñ#Ó%Ð%r   c                 ó  — | j                  «       }|dk(  r>| j                  «       | j                  «       dz  z  | j                  «       dz  z  }|dz  }n
|}|dz   dz  }| j                  |«      }|dkD  rd|z
  }| j                  |«       |S )zi
        Reads a Telegram-encoded byte array, without the need of
        specifying its length.
        éþ   r+   é   r   r   r   )r   r   )r   Ú
first_byter;   Úpaddingr   s        r   Útgread_byteszBinaryReader.tgread_bytesL   s”   € ð
 —^‘^Ó%ˆ
Ø˜ÒØ—^‘^Ó%¨¯©Ó)9¸QÑ)>Ñ?Ø—‘Ó  BÑ&ñ(ˆFà˜q‘j‰GàˆFØ ‘z QÑ&ˆGà�y‰y˜Ó ˆØ�QŠ;Ø˜'‘kˆGØ�I‰I�gÔàˆr   c                 ó:   — t        | j                  «       dd¬«      S )z Reads a Telegram-encoded string.zutf-8Úreplace)ÚencodingÚerrors)ÚstrrE   r   s    r   Útgread_stringzBinaryReader.tgread_stringa   s   € ä�4×$Ñ$Ó&°ÀÔKÐKr   c                 ó„   — | j                  d¬«      }|dk(  ry|dk(  ryt        dj                  t        |«      «      «      ‚)zReads a Telegram boolean value.F©r#   ì   µuä2 Tì   7óx zInvalid boolean code {})r(   ÚRuntimeErrorr9   Úhex©r   Úvalues     r   Útgread_boolzBinaryReader.tgread_boole   sC   € à—‘ U�Ó+ˆØ�JÒØØ�jÒ ØäÐ8×?Ñ?ÄÀEÃ
ÓKÓLÐLr   c                 óH   — | j                  «       }t        t        |¬«      z   S )zbReads and converts Unix time (used by Telegram)
           into a Python datetime object.
        )Úseconds)r(   Ú_EPOCHr   rR   s     r   Útgread_datezBinaryReader.tgread_dateo   s   € ð —‘“ˆÜœ	¨%Ô0Ñ0Ð0r   c                 óÞ  — | j                  d¬«      }t        j                  |d«      }|€®|}|dk(  ry|dk(  ry|dk(  r5t        | j                  «       «      D �cg c]  }| j	                  «       ‘Œ c}S t        j                  |d«      }|€N| j                  d«       | j                  «       }t        || j                  «       «      }| j                  |«       |‚|j                  | «      S c c}w )	zReads a Telegram object.FrM   NrN   TrO   éÄµéüÿÿÿ)r(   r
   ÚgetÚrangeÚtgread_objectr   ÚseekÚtell_positionr	   r   Úset_positionÚfrom_reader)r   Úconstructor_idÚclazzrS   Ú_ÚposÚerrors          r   r^   zBinaryReader.tgread_objectv   sÝ   € àŸ™¨e˜Ó4ˆÜ—‘˜n¨dÓ3ˆØˆ=ð #ˆEØ˜
Ò"ØØ˜*Ò$ØØ˜*Ò$Ü6;¸D¿M¹M»OÓ6LÖM°˜×*Ñ*Õ,ÒMÐMä ×$Ñ$ ^°TÓ:ˆEØˆ}à—	‘	˜"”Ø×(Ñ(Ó*�Ü)¨.¸$¿)¹)»+ÓF�Ø×!Ñ! #Ô&Ø�à× Ñ  Ó&Ð&ùò Ns   ÁC*c                 óº   — d| j                  d¬«      k7  rt        d«      ‚| j                  «       }t        |«      D �cg c]  }| j                  «       ‘Œ c}S c c}w )z,Reads a vector (a list) of Telegram objects.rZ   FrM   z-Invalid constructor code, vector was expected)r(   rP   r]   r^   )r   Úcountre   s      r   Útgread_vectorzBinaryReader.tgread_vector�   sM   € à˜Ÿ™¨e˜Ó4Ò4ÜÐNÓOÐOà—‘“ˆÜ.3°E«lÖ;¨�×"Ñ"Õ$Ò;Ð;ùÒ;s   ¾Ac                 ó8   — | j                   j                  «        y)z.Closes the reader, freeing the BytesIO stream.N)r   Úcloser   s    r   rl   zBinaryReader.closeš   s   € à�‰×ÑÕr   c                 ó6   — | j                   j                  «       S )z)Tells the current position on the stream.)r   Útellr   s    r   r`   zBinaryReader.tell_position    s   € à�{‰{×ÑÓ!Ð!r   c                 ó:   — | j                   j                  |«       y)z(Sets the current position on the stream.N)r   r_   )r   Úpositions     r   ra   zBinaryReader.set_position¤   s   € à�‰×Ñ˜Õ"r   c                 óX   — | j                   j                  |t        j                  «       y)zz
        Seeks the stream position given an offset from the current position.
        The offset may be negative.
        N)r   r_   ÚosÚSEEK_CUR)r   Úoffsets     r   r_   zBinaryReader.seek¨   s   € ð
 	�‰×Ñ˜¤§¡Õ-r   c                 ó   — | S r   © r   s    r   Ú	__enter__zBinaryReader.__enter__³   s   € Øˆr   c                 ó$   — | j                  «        y r   )rl   )r   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__zBinaryReader.__exit__¶   s   € Ø�
‰
�r   N)T)éÿÿÿÿ)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r(   r,   r/   r2   r5   r   r?   rE   rK   rT   rX   r^   rj   rl   r`   ra   r_   rw   r|   rv   r   r   r   r      su   „ ñòòóOóOò-ò-óEó

ò&òò*LòMò1ò'ò4<òò"ò#ò.òór   r   )r�   rr   Útimer   r   r   Úior   Ústructr   rI   r	   Útl.alltlobjectsr
   Útl.corer   ÚgmtimeÚ_EPOCH_NAIVErG   ÚutcrW   r   rv   r   r   ú<module>rŠ      se   ðñó 
Û ß 2Ñ 2Ý Ý å &Ý 'Ý "á˜˜Ÿ™ Q›¨¨Ð+Ð,€Ø	×	Ñ	 X§\¡\Ð	Ó	2€÷eò er   