HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/tqdm/contrib/__pycache__/telegram.cpython-310.pyc
o

���g��@s�dZddlmZddlmZddlmZddlmZ	ddl
mZdd	lm
Z
d
dgiZgd�ZGd
d�de
�ZGdd�de	�Zdd�ZeZeZdS)z�
Sends updates to a Telegram bot.

Usage:
>>> from tqdm.contrib.telegram import tqdm, trange
>>> for i in trange(10, token='{token}', chat_id='{chat_id}'):
...     ...

![screenshot](https://tqdm.github.io/img/screenshot-telegram.gif)
�)�getenv)�warn)�Session�)�tqdm)�TqdmWarning�)�
MonoWorkerzgithub.com/�	casperdcl)�
TelegramIO�
tqdm_telegram�ttgranger�trangecs@eZdZdZdZ�fdd�Zedd��Zdd�Zd	d
�Z	�Z
S)rz/Non-blocking file-like IO using a Telegram Bot.zhttps://api.telegram.org/botcs2t���||_||_t�|_|jj|_|j	dS)z-Creates a new message in the given `chat_id`.N)
�super�__init__�token�chat_idr�session�	__class__�__name__�text�
message_id)�selfrr�r��@/usr/local/lib/python3.10/dist-packages/tqdm/contrib/telegram.pyrs


zTelegramIO.__init__c
Cs�t|d�r|jSz|jj|jd|jd|jd|jdd�d���}Wnt	y>}zt
�t|��WYd}~dSd}~ww|�
d�dkrOtd	td
d�dS|dd
|_|jS)N�_message_idz%s/sendMessage�`�
MarkdownV2)rr�
parse_mode��data�
error_codei�z2Creation rate limit: try increasing `mininterval`.r)�
stacklevel�resultr)�hasattrrr�post�APIrrr�json�	Exception�	tqdm_auto�write�str�getrr)r�res�errrr%s*
�����
�zTelegramIO.message_idc
Cs�|sd}|�dd���}||jkrdS|j}|durdS||_z|j|jj|jd|jd|d|j	|dd�d	�}W|St
yV}zt�t
|��WYd}~dSd}~ww)
z/Replaces internal `message_id`'s text with `s`.z...�
�Nz%s/editMessageTextrr)rrrrr )�replace�striprr�submitrr&r'rrr)r*r+r,)r�sr�futurer/rrrr+8s*
�����zTelegramIO.writec
Csfz|j|jj|jd|j|j|jd�d�}W|Sty2}zt�	t
|��WYd}~dSd}~ww)zDeletes internal `message_id`.z%s/deleteMessage)rrr N)r4rr&r'rrrr)r*r+r,)rr6r/rrr�deleteMs����zTelegramIO.delete)r�
__module__�__qualname__�__doc__r'r�propertyrr+r7�
__classcell__rrrrrs	
rcsDeZdZdZ�fdd�Z�fdd�Z�fdd�Z�fdd	�Z�ZS)
ra;
    Standard `tqdm.auto.tqdm` but also sends updates to a Telegram Bot.
    May take a few seconds to create (`__init__`).

    - create a bot <https://core.telegram.org/bots#6-botfather>
    - copy its `{token}`
    - add the bot to a chat and send it a message such as `/start`
    - go to <https://api.telegram.org/bot`{token}`/getUpdates> to find out
      the `{chat_id}`
    - paste the `{token}` & `{chat_id}` below

    >>> from tqdm.contrib.telegram import tqdm, trange
    >>> for i in tqdm(iterable, token='{token}', chat_id='{chat_id}'):
    ...     ...
    csL|�d�s|��}t|�dtd��|�dtd���|_t�j|i|��dS)a.
        Parameters
        ----------
        token  : str, required. Telegram token
            [default: ${TQDM_TELEGRAM_TOKEN}].
        chat_id  : str, required. Telegram chat ID
            [default: ${TQDM_TELEGRAM_CHAT_ID}].

        See `tqdm.auto.tqdm.__init__` for other parameters.
        �disabler�TQDM_TELEGRAM_TOKENr�TQDM_TELEGRAM_CHAT_IDN)r-�copyr�popr�tgiorr�r�args�kwargsrrrris
�ztqdm_telegram.__init__csft�jdi|��|j}|�dd�r!|d�dd��dd�|d<nd|d<|j�|jdi|���dS)N�
bar_formatz<bar/>z	{bar:10u}z{bar}z{l_bar}{bar:10u}{r_bar}r)r�display�format_dictr-r2rBr+�format_meter)rrE�fmtrrrrG{s��ztqdm_telegram.displaycs,t�j|i|��|js|j�d�dSdS)Nr1)r�clearr=rBr+rCrrrrK�s�ztqdm_telegram.clearcsD|jrdSt���|js|jdur|jdks |j��dSdSdS)Nr)r=r�close�leave�posrBr7)rrrrrL�s
�ztqdm_telegram.close)	rr8r9r:rrGrKrLr<rrrrrYs
rcOstt|�fi|��S)zBShortcut for `tqdm.contrib.telegram.tqdm(range(*args), **kwargs)`.)r�range)rDrErrrr
�sr
N)r:�osr�warningsr�requestsr�autorr*�stdr�utils_workerr	�
__author__�__all__rrr
rrrrr�<module>s

A9