
    ;Sid%                         d dl Z d dlZd dlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ej                  rddlmZ  G d d	      Z G d
 d      Zy)    N   )_NOT_A_REQUEST   )helpersutils)	functions	TLRequest)TelegramClientc                        e Zd ZdZdZd Zed        Zej                  d        Zd Z	d Z
ej                  Zej                  ZddZ fd	Zd
 Z fdZ xZS )_TakeoutClientz'
    Proxy object over the client.
    )	__enter____exit__
__aenter__	__aexit__c                 <    || _         || _        || _        d | _        y N)_TakeoutClient__finalize_TakeoutClient__client_TakeoutClient__request_TakeoutClient__success)selffinalizeclientrequests       \/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/client/account.py__init__z_TakeoutClient.__init__   s      #     c                     | j                   S r   r   )r   s    r   successz_TakeoutClient.success   s    ~~r   c                     || _         y r   r   )r   values     r   r    z_TakeoutClient.success"   s	    r   c                    K   | j                   }|j                  j                  5 || j                         d {   j                  |j                  _        | S | j                  t        d      | S 7 8w)NzgCan't send a takeout request while another takeout for the current session still not been finished yet.)r   session
takeout_idr   id
ValueError)r   r   s     r   r   z_TakeoutClient.__aenter__&   sp     >>$$,/5dnn/E)E(I(IFNN%  ^^' O P P	 *Fs   8A5A39A5c                   K   | j                   | j                  r	|d u | _         | j                   V | t        j                  j	                  | j                                d {   }|st        d      d | j                  _        y y 7 $w)NzFailed to finish the takeout.)r   r   r   accountFinishTakeoutSessionRequestr'   r$   r%   )r   exc_type	exc_value	tracebackresults        r   r   z_TakeoutClient.__aexit__0   sz     >>!doo%-DN>>%	 1 1 M M!  ! !F !@AA&*DLL# &!s   A B	"B#%B	c                   K   | j                   j                  j                  }|t        d      t	        j
                  |       }|r|fn|}g }|D ]_  }t        |t              s
t               |j                  | t               d {    |j                  t        j                  ||             a | j                  |r|d   n||       d {   S 7 M7 w)NzJTakeout mode has not been initialized (are you calling outside of "with"?)r   )ordered)r   r$   r%   r'   r   is_list_like
isinstancer	   r   resolveappendr   InvokeWithTakeoutRequest)r   r   r0   r%   singlerequestswrappedrs           r   __call__z_TakeoutClient.__call__>   s     ]]**55
 7 8 8 ''00"(WJg 	NAa+$&&))D%(((NN9==j!LM		N ]] GAJgw # @ @ 	@ )@s%   BCCACCCCc                 ~    |j                  d      r|t        |       j                  vrt        t        |   |      S )N__)
startswithtype_TakeoutClient__PROXY_INTERFACEAttributeErrorsuper__getattribute__)r   name	__class__s     r   rB   z_TakeoutClient.__getattribute__P   s:     ??4 Td1M1M%M   w'--r   c                     t        | j                  |      }t        j                  |      r4t	        j
                  t        | j                  j                  |      |       S |S r   )getattrr   inspectismethod	functoolspartialrD   )r   rC   r"   s      r   __getattr__z_TakeoutClient.__getattr__]   sR    t,E" $$//6> > r   c                     |j                  dj                  t        |       j                  j	                  d                  rt
        |   ||      S t        | j                  ||      S )Nz_{}___)	r=   formatr>   __name__lstriprA   __setattr__setattrr   )r   rC   r"   rD   s      r   rQ   z_TakeoutClient.__setattr__g   sR    ??7>>$t**=*=*D*DS*IJK7&tU33t}}dE22r   )F)rO   
__module____qualname____doc__r?   r   propertyr    setterr   r   r   _sync_enterr   
_sync_exitr   r:   rB   rK   rQ   __classcell__)rD   s   @r   r   r      s~     M   ^^ 	+ ##I!!H@$.3 3r   r   c                   f    e Zd Z	 ddddddddddddedededed	ed
edededdfdZdddedefdZy)AccountMethodsN)contactsuserschats
megagroupschannelsfilesmax_file_sizer   r
   r   r]   r^   r_   r`   ra   rb   rc   returnc          	          t        |||||||      }	d |	j                         D        }
| j                  j                  t	        |
      r t        j                  j                  di |	}nd}t        || |      S )a~  
        Returns a :ref:`telethon-client` which calls methods behind a takeout session.

        It does so by creating a proxy object over the current client through
        which making requests will use :tl:`InvokeWithTakeoutRequest` to wrap
        them. In other words, returns the current client modified so that
        requests are done as a takeout:

        Some of the calls made through the takeout session will have lower
        flood limits. This is useful if you want to export the data from
        conversations or mass-download media, since the rate limits will
        be lower. Only some requests will be affected, and you will need
        to adjust the `wait_time` of methods like `client.iter_messages
        <telethon.client.messages.MessageMethods.iter_messages>`.

        By default, all parameters are `None`, and you need to enable those
        you plan to use by setting them to either `True` or `False`.

        You should ``except errors.TakeoutInitDelayError as e``, since this
        exception will raise depending on the condition of the session. You
        can then access ``e.seconds`` to know how long you should wait for
        before calling the method again.

        There's also a `success` property available in the takeout proxy
        object, so from the `with` body you can set the boolean result that
        will be sent back to Telegram. But if it's left `None` as by
        default, then the action is based on the `finalize` parameter. If
        it's `True` then the takeout will be finished, and if no exception
        occurred during it, then `True` will be considered as a result.
        Otherwise, the takeout will not be finished and its ID will be
        preserved for future usage as `client.session.takeout_id
        <telethon.sessions.abstract.Session.takeout_id>`.

        Arguments
            finalize (`bool`):
                Whether the takeout session should be finalized upon
                exit or not.

            contacts (`bool`):
                Set to `True` if you plan on downloading contacts.

            users (`bool`):
                Set to `True` if you plan on downloading information
                from users and their private conversations with you.

            chats (`bool`):
                Set to `True` if you plan on downloading information
                from small group chats, such as messages and media.

            megagroups (`bool`):
                Set to `True` if you plan on downloading information
                from megagroups (channels), such as messages and media.

            channels (`bool`):
                Set to `True` if you plan on downloading information
                from broadcast channels, such as messages and media.

            files (`bool`):
                Set to `True` if you plan on downloading media and
                you don't only wish to export messages.

            max_file_size (`int`):
                The maximum file size, in bytes, that you plan
                to download for each message with media.

        Example
            .. code-block:: python

                from telethon import errors

                try:
                    async with client.takeout() as takeout:
                        await client.get_messages('me')  # normal call
                        await takeout.get_messages('me')  # wrapped through takeout (less limits)

                        async for message in takeout.iter_messages(chat, wait_time=0):
                            ...  # Do something with the message

                except errors.TakeoutInitDelayError as e:
                    print('Must wait', e.seconds, 'before takeout')
        )r]   message_usersmessage_chatsmessage_megagroupsmessage_channelsrb   file_max_sizec              3   $   K   | ]  }|d u 
 y wr    ).0args     r   	<genexpr>z)AccountMethods.takeout.<locals>.<genexpr>   s     LSDLs   Nrl   )	dictvaluesr$   r%   anyr   r)   InitTakeoutSessionRequestr   )r   r   r]   r^   r_   r`   ra   rb   rc   request_kwargsarg_specifiedr   s               r   takeoutzAccountMethods.takeouto   s    x )%'
 MN4I4I4KL<<""*c-.@''AA " "G Ghg66r   r    c                    K   	 t        d| d      4 d{   }||_        ddd      d{    y7 7 # 1 d{  7  sw Y   yxY w# t        $ r Y yw xY ww)ap  
        Finishes the current takeout session.

        Arguments
            success (`bool`):
                Whether the takeout completed successfully or not.

        Returns
            `True` if the operation was successful, `False` otherwise.

        Example
            .. code-block:: python

                await client.end_takeout(success=False)
        TNF)r   r    r'   )r   r    rv   s      r   end_takeoutzAccountMethods.end_takeout   sl      	%dD$7 * *7")* * 	* * * * *   		sl   AA 2A 6A 4A AA A A?AA AA 	AAAA)T)rO   rS   rT   boolrv   rx   rl   r   r   r\   r\   n   s     "m7 "#!"&m7"m7m7 	m7
 m7 m7 m7 m7 m7  m7 ,<m7^ 0 4 D r   r\   )rI   rG   typingr^   r    r   r   tlr   r	   TYPE_CHECKINGtelegramclientr
   r   r\   rl   r   r   <module>r      s<       !  %	.
\3 \3~E Er   