o
    XzjÞ  ã                   @   s¤   d dl Z d dlZd dlZd dlmZmZmZmZ d dlZee d ¡dd… Ž Z	ee 
d ¡dd… Ž Ze	jejd�Zdd„ Zdd„ ZG d	d
„ d
ƒZG dd„ deƒZdS )é    N)ÚdatetimeÚdateÚ	timedeltaÚtimezoneé   ©Útzinfoc                 C   sD   | j d u r| jtjd�} t| t  ¡ ƒ}t dt 	d|d@ ¡¡d S )Nr   ÚiÚIl   ÿÿ r   )
r   Úreplacer   ÚutcÚintÚ_EPOCHÚtotal_secondsÚstructÚunpackÚpack)ÚdtÚsecs© r   úO/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/tl/tlobject.pyÚ_datetime_to_timestamp   s   
r   c                 C   s4   t | tƒrt | ¡ d¡S t | tƒr|  ¡ S t| ƒS )NÚascii)Ú
isinstanceÚbytesÚbase64Ú	b64encodeÚdecoder   Ú	isoformatÚrepr)Úvaluer   r   r   Ú_json_default   s
   

r!   c                   @   sŒ   e Zd ZdZdZeddd„ƒZedd„ ƒZedd„ ƒZdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdefdd„Zdd„ Zdd„ Zedd„ ƒZdS )ÚTLObjectNc                 C   s$  |du rJt | tƒr|  ¡ } t | tƒr&d |  dd¡d dd„ |  ¡ D ƒ¡¡S t | tƒs0t | t	ƒr4t
| ƒS t| dƒrFd	 d d
d„ | D ƒ¡¡S t
| ƒS g }t | tƒrU|  ¡ } t | tƒrº| |  dd¡¡ | d¡ | r´| d¡ |d7 }|  ¡ D ](\}}|dkr€qw| d| ¡ | |¡ | d¡ | t ||¡¡ | d¡ qw| ¡  |d8 }| d¡ | d| ¡ | d¡ nSt | tƒsÄt | t	ƒrÌ| t
| ƒ¡ nAt| dƒ�r| d¡ |d7 }| D ]}| d| ¡ | t ||¡¡ | d¡ qÝ|d8 }| d| ¡ | d¡ n| t
| ƒ¡ d |¡S )z‹
        Pretty formats the given object as a string which is returned.
        If indent is None, a single line will be returned.
        Nz{}({})Ú_Údictz, c                 s   s.   � | ]\}}|d krd  |t |¡¡V  qdS )r#   z{}={}N)Úformatr"   Úpretty_format)Ú.0ÚkÚvr   r   r   Ú	<genexpr>1   s   € ÿþz)TLObject.pretty_format.<locals>.<genexpr>Ú__iter__z[{}]c                 s   s   � | ]}t  |¡V  qd S ©N©r"   r&   )r'   Úxr   r   r   r*   9   s   € ú(Ú
é   ú	ú=z,
ú)z[
ú]Ú )r   r"   Úto_dictr$   r%   ÚgetÚjoinÚitemsÚstrr   r   ÚhasattrÚappendr&   Úpop)ÚobjÚindentÚresultr(   r)   r.   r   r   r   r&   &   sd   


þ
ÿ








zTLObject.pretty_formatc                 C   sö   t | tƒst | tƒr|  d¡} n	td t| ƒ¡ƒ‚g }t| ƒdk rAt| ƒd d }|dkr1d| }| tt| ƒgƒ¡ | | ¡ n.t| ƒd }|dkrOd| }| tdt| ƒd t| ƒd? d t| ƒd	? d gƒ¡ | | ¡ | t|ƒ¡ d
 	|¡S )z(Write bytes by using Telegram guidelineszutf-8zbytes or str expected, not {}éþ   r1   é   r   é   é   é   ó    )
r   r   r;   ÚencodeÚ	TypeErrorr%   ÚtypeÚlenr=   r9   )ÚdataÚrÚpaddingr   r   r   Úserialize_bytesi   s2   

ÿ
ü

zTLObject.serialize_bytesc                 C   sš   | s	t | tƒs	dS t | tƒrt| ƒ} n(t | tƒr$tt| j| j| jƒƒ} nt | tƒr.t	| ƒ} nt | tƒr;tt 
¡ |  ƒ} t | t	ƒrFt d| ¡S td | ¡ƒ‚)Ns       z<iz Cannot interpret "{}" as a date.)r   r   r   r   r   ÚyearÚmonthÚdayÚfloatr   Úutcnowr   r   rI   r%   )r   r   r   r   Úserialize_datetimeŒ   s   






zTLObject.serialize_datetimec                 C   s   t |t| ƒƒo|  ¡ | ¡ kS r,   ©r   rJ   r7   ©ÚselfÚor   r   r   Ú__eq__    s   zTLObject.__eq__c                 C   s    t |t| ƒƒ p|  ¡ | ¡ kS r,   rV   rW   r   r   r   Ú__ne__£   s    zTLObject.__ne__c                 C   s
   t  | ¡S r,   r-   ©rX   r   r   r   Ú__str__¦   s   
zTLObject.__str__c                 C   s   t j| dd�S )Nr   )r@   r-   r\   r   r   r   Ú	stringify©   s   zTLObject.stringifyc                 C   ó   t ‚r,   ©ÚNotImplementedErrorr\   r   r   r   r7   ¬   ó   zTLObject.to_dictc                 K   s:   |   ¡ }|rtj||fd|i|¤ŽS tj|fd|i|¤ŽS )an  
        Represent the current `TLObject` as JSON.

        If ``fp`` is given, the JSON will be dumped to said
        file pointer, otherwise a JSON string will be returned.

        Note that bytes and datetimes cannot be represented
        in JSON, so if those are found, they will be base64
        encoded and ISO-formatted, respectively, by default.
        Údefault)r7   ÚjsonÚdumpÚdumps)rX   Úfprc   ÚkwargsÚdr   r   r   Úto_json¯   s   zTLObject.to_jsonc                 C   s"   z|   ¡ W S  ty   tdƒ‚w )Nz0a TLObject was expected but found something else)Ú_bytesÚAttributeErrorrI   r\   r   r   r   Ú	__bytes__À   s
   
ûzTLObject.__bytes__c                 C   r_   r,   r`   r\   r   r   r   rk   Í   rb   zTLObject._bytesc                 C   r_   r,   r`   )ÚclsÚreaderr   r   r   Úfrom_readerÐ   s   zTLObject.from_readerr,   )Ú__name__Ú
__module__Ú__qualname__ÚCONSTRUCTOR_IDÚSUBCLASS_OF_IDÚstaticmethodr&   rO   rU   rZ   r[   r]   r^   r7   r!   rj   rm   rk   Úclassmethodrp   r   r   r   r   r"   "   s&    B
"
r"   c                   @   s$   e Zd ZdZedd„ ƒZdd„ ZdS )Ú	TLRequestzO
    Represents a content-related `TLObject` (a request that can be sent).
    c                 C   s   |   ¡ S r,   )Útgread_object)ro   r   r   r   Úread_resultÙ   s   zTLRequest.read_resultc                 Ã   s   �d S r,   r   )rX   ÚclientÚutilsr   r   r   ÚresolveÝ   s   €zTLRequest.resolveN)rq   rr   rs   Ú__doc__rv   rz   r}   r   r   r   r   rx   Õ   s
    
rx   )r   rd   r   r   r   r   r   ÚtimeÚgmtimeÚ_EPOCH_NAIVEÚ	localtimeÚ_EPOCH_NAIVE_LOCALr   r   r   r   r!   r"   rx   r   r   r   r   Ú<module>   s    	 4