
    ;Si                          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	m
Z
mZmZmZmZmZmZ  G d d	e      Z G d
 de      Zy)    )Enum   )Session   )utils)TLObject)PeerUserPeerChatPeerChannelInputPeerUserInputPeerChatInputPeerChannel
InputPhotoInputDocumentc                   $    e Zd ZdZdZed        Zy)_SentFileTyper   r   c                 |    | t         k(  rt        j                  S | t        k(  rt        j                  S t        d      )Nz/The cls must be either InputDocument/InputPhoto)r   r   DOCUMENTr   PHOTO
ValueError)clss    ]/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/sessions/memory.py	from_typez_SentFileType.from_type   s6    - )))J &&&NOO    N)__name__
__module____qualname__r   r   staticmethodr    r   r   r   r      s     HEP Pr   r   c                   .    e Zd Z fdZd Zed        Zed        Zed        Zed        Z	e	j                  d        Z	ed        Zej                  d	        Zd
 Zd Zd Zd Zd Zd Zed        Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Z xZS )MemorySessionc                     t         |           d| _        d | _        d | _        d | _        d | _        i | _        t               | _	        i | _
        y Nr   )super__init___dc_id_server_address_port	_auth_key_takeout_id_filesset	_entities_update_states)self	__class__s    r   r%   zMemorySession.__init__   sK    #
 r   c                 6    |xs d| _         || _        || _        y r#   )r&   r'   r(   )r/   dc_idserver_addressports       r   set_dczMemorySession.set_dc)   s    jq-
r   c                     | j                   S N)r&   r/   s    r   r2   zMemorySession.dc_id.   s    {{r   c                     | j                   S r7   )r'   r8   s    r   r3   zMemorySession.server_address2   s    ###r   c                     | j                   S r7   )r(   r8   s    r   r4   zMemorySession.port6   s    zzr   c                     | j                   S r7   r)   r8   s    r   auth_keyzMemorySession.auth_key:   s    ~~r   c                     || _         y r7   r<   r/   values     r   r=   zMemorySession.auth_key>   s	    r   c                     | j                   S r7   r*   r8   s    r   
takeout_idzMemorySession.takeout_idB   s    r   c                     || _         y r7   rB   r?   s     r   rC   zMemorySession.takeout_idF   s
     r   c                 :    | j                   j                  |d       S r7   )r.   get)r/   	entity_ids     r   get_update_statezMemorySession.get_update_stateJ   s    ""&&y$77r   c                 "    || j                   |<   y r7   )r.   )r/   rG   states      r   set_update_statezMemorySession.set_update_stateM   s    ).I&r   c                 6    | j                   j                         S r7   )r.   itemsr8   s    r   get_update_stateszMemorySession.get_update_statesP   s    ""((**r   c                      y r7   r   r8   s    r   closezMemorySession.closeS       r   c                      y r7   r   r8   s    r   savezMemorySession.saveV   rQ   r   c                      y r7   r   r8   s    r   deletezMemorySession.deleteY   rQ   r   c                     | ||||fS r7   r   )idhashusernamephonenames        r   _entity_values_to_rowz#MemorySession._entity_values_to_row\   s    
 45$..r   c                    t        |t              sy 	 t        j                  |d      }t        j                  |      }t        |t        t        f      r|j                  }nt        |t              rd}ny t        |dd       xs d }||j                         }t        |dd       }t        j                  |      xs d }| j                  |||||      S # t
        $ r Y y w xY w)NF)
allow_selfr   rY   rZ   )
isinstancer   r   get_input_peerget_peer_id	TypeErrorr   r   access_hashr   getattrlowerget_display_namer\   )r/   ep	marked_idp_hashrY   rZ   r[   s           r   _entity_to_rowzMemorySession._entity_to_rowc   s    !X&	$$Q59A))!,I a-)9:;]]F=)F1j$/74~~'H7D)%%a(0D))vx
 	
'  	
 	s   ,C 	C C c                 j   t        |t              st        j                  |      r|}ng }t	        |d      r|j                  |j                         t	        |d      r|j                  |j                         t	        |d      r:t        j                  |j                        r|j                  |j                         t	        |d      r:t        j                  |j                        r|j                  |j                         g }|D ]'  }| j                  |      }|s|j                  |       ) |S )Nuserchatchatsusers)r_   r   r   is_list_likehasattrappendrm   rn   ro   extendrp   rk   )r/   tloentitiesrowsrg   rows         r   _entities_to_rowszMemorySession._entities_to_rows   s    #x(U-?-?-DHHsF#)sF#)sG$););CII)F		*sG$););CII)F		* 	!A%%a(CC 	! r   c                 ^    | xj                   t        | j                  |            z  c_         y r7   )r-   r,   ry   )r/   ru   s     r   process_entitieszMemorySession.process_entities   s     #d44S9::r   c                 `    	 t        fd| j                  D              S # t        $ r Y y w xY w)Nc              3   <   K   | ]  \  }}}}}|k(  r||f  y wr7   r   ).0rW   rX   _found_phonerZ   s        r   	<genexpr>z9MemorySession.get_entity_rows_by_phone.<locals>.<genexpr>   s1      C'Br4K-8E-A T
 C   nextr-   StopIteration)r/   rZ   s    `r   get_entity_rows_by_phonez&MemorySession.get_entity_rows_by_phone   s<    	 C>>C C C 		   ! 	--c                 `    	 t        fd| j                  D              S # t        $ r Y y w xY w)Nc              3   <   K   | ]  \  }}}}}|k(  r||f  y wr7   r   )r~   rW   rX   found_usernamer   rY   s        r   r   z<MemorySession.get_entity_rows_by_username.<locals>.<genexpr>   s1      I'Er4A-;x-G T
 Ir   r   )r/   rY   s    `r   get_entity_rows_by_usernamez)MemorySession.get_entity_rows_by_username   s<    	 I>>I I I 		r   c                 `    	 t        fd| j                  D              S # t        $ r Y y w xY w)Nc              3   <   K   | ]  \  }}}}}|k(  r||f  y wr7   r   )r~   rW   rX   r   
found_namer[   s        r   r   z8MemorySession.get_entity_rows_by_name.<locals>.<genexpr>   s1      A'Ar4Az-74-? T
 Ar   r   )r/   r[   s    `r   get_entity_rows_by_namez%MemorySession.get_entity_rows_by_name   s<    	 A>>A A A 		r   c                 T   	 |rt        fd| j                  D              S t        j                  t	                    t        j                  t                    t        j                  t                    ft        fd| j                  D              S # t        $ r Y y w xY w)Nc              3   <   K   | ]  \  }}}}}|k(  r||f  y wr7   r   )r~   found_idrX   r   rW   s       r   r   z6MemorySession.get_entity_rows_by_id.<locals>.<genexpr>   s1      A1H4Aq19R &t, Ar   c              3   :   K   | ]  \  }}}}}|v r||f  y wr7   r   )r~   r   rX   r   idss       r   r   z6MemorySession.get_entity_rows_by_id.<locals>.<genexpr>   s1      B1H4Aq19S &t, Bs   )r   r-   r   ra   r	   r
   r   r   )r/   rW   exactr   s    ` @r   get_entity_rows_by_idz#MemorySession.get_entity_rows_by_id   s    	 A#~~A A A %%hrl3%%hrl3%%k"o6
  B#~~B B B 		s   B A6B 	B'&B'c                    	 |j                   dv r|S t        j                  |      S # t        t        f$ rC t        |t              rt        j                  |      }d}nt        |t               xs |dk  }Y nw xY wd }t        |t              rt        j                  |      }|r| j                  |      }n~t        j                  |      \  }}|r|s| j                  |      }nPt        j                  |      d   }|r6| j                  |d      }n"t        |t              r| j                  ||      }|s!t        |t              r| j!                  |      }|r\|\  }}	t        j"                  |      \  }}
|
t$        k(  rt'        ||	      S |
t(        k(  rt+        |      S |
t,        k(  rt/        ||	      S y t1        d|      )N)l   9 l   F?L i@Tr   r   F)r   z%Could not find input entity with key )SUBCLASS_OF_IDr   r`   AttributeErrorrb   r_   r   ra   intstrparse_phoner   parse_usernamer   resolve_invite_linkr   r   
resolve_idr	   r   r
   r   r   r   r   )r/   keyr   resultrZ   rY   invitetuprG   entity_hashkinds              r   get_input_entityzMemorySession.get_input_entity   s   	<!!%II 
'',,	* 	<#x('',&sC00;C!G	< c3%%c*E66u=#(#7#7#< &F!==hGF33C8;C!%!;!;Cu!;!MS!//U;F*S#.11#6F%+"I{#..y9OItx$Y<<!$Y//$'	;?? % DcJJs   ' ' AA98A9c                     t        |t        t        f      st        dt	        |      z        ||t
        j                  t	        |            f}|j                  |j                  f}|| j                  |<   y )NzCannot cache %s instance)
r_   r   r   rb   typer   r   rW   rc   r+   )r/   
md5_digest	file_sizeinstancer   r@   s         r   
cache_filezMemorySession.cache_file   sc    (]J$?@6hGHH9m&=&=d8n&MNh223 Cr   c                 v    ||t         j                  |      f}	  || j                  |    S # t        $ r Y y w xY wr7   )r   r   r+   KeyError)r/   r   r   r   r   s        r   get_filezMemorySession.get_file   sD    9m&=&=c&BC	C()) 		s   , 	88)T)r   r   r   r%   r5   propertyr2   r3   r4   r=   setterrC   rH   rK   rN   rP   rS   rU   r   r\   rk   ry   r{   r   r   r   r   r   r   r   __classcell__)r0   s   @r   r!   r!      s	   !
   $ $     __      ! !8/+ / /
:,; /Kb!r   r!   N)enumr   abstractr    r   tlr   tl.typesr	   r
   r   r   r   r   r   r   r   r!   r   r   r   <module>r      s<         PD P`G `r   