
    ՟fC                     L   d Z ddlZddlZddl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mZmZ ddlmZmZmZmZ ddlmZ ddlmZ dd	lmZmZ dd
lm Z m!Z!m"Z"m#Z# 	 ddl$m%Z%m&Z& dZ'e	rddl)m)Z) ddl*m+Z+  edd      Z, ee-      Z. G d ded         Z/y# e($ r dZ'Y 8w xY w)z]This module contains the class Updater, which tries to make creating Telegram bots intuitive.    N)Path)TracebackType)
TYPE_CHECKINGAnyAsyncContextManagerCallable	CoroutineListOptionalTypeTypeVarUnion)
DEFAULT_80
DEFAULT_IPDEFAULT_NONEDefaultValue)
get_logger)build_repr_with_selected_attrs)DVTypeODVInput)InvalidToken
RetryAfterTelegramErrorTimedOut)WebhookAppClassWebhookServerTF)socket)Bot_UpdaterTypeUpdater)boundc            !           e Zd ZdZdZ	 	 	 	 d@dZdedefdZdee	e
      d	ee
   d
ee   ddfdZdefdZedefd       ZdAdZdAdZdddeeeedddf
dedededee   dee   dee   dee   deee      dee   deeegdf      ddfdZdededee   dee   dee   dee   dedee   deee      dej:                  deeegdf      ddfd Zee d!ddd"ddddd#ddfd$e!e   d%e!e   d&ed'ee"ee#f      d(ee"ee#f      ded)ee   deee      dee   d*ee   d+ed,ee   d-ee"ee#d.f      ddfd/Z$	 	 	 	 	 	 	 	 	 dBd$ed%ed&ededeee      d'ee"ee#f      d(ee"ee#f      dee   d)ee   deej:                     d*ee   d+ed,ee   d-ee"ee#d.f      ddfd0Z%e&d1ed$ed%ed&edef
d2       Z'd3ed4e(f   d5eegdf   d6ed7ed8eej:                     ddfd9Z)	 	 	 	 	 	 dCd:ed)ee   deee      dee   d'ee*   d;ed*ee   d+ed,ee   ddfd<Z+dAd=Z,dAd>Z-dAd?Z.y)Dr    a]  This class fetches updates for the bot either via long polling or by starting a webhook
    server. Received updates are enqueued into the :attr:`update_queue` and may be fetched from
    there to handle them appropriately.

    Instances of this class can be used as asyncio context managers, where

    .. code:: python

        async with updater:
            # code

    is roughly equivalent to

    .. code:: python

        try:
            await updater.initialize()
            # code
        finally:
            await updater.shutdown()

    .. seealso:: :meth:`__aenter__` and :meth:`__aexit__`.

    .. seealso:: :wiki:`Architecture Overview <Architecture>`,
        :wiki:`Builder Pattern <Builder-Pattern>`

    .. versionchanged:: 20.0

        * Removed argument and attribute ``user_sig_handler``
        * The only arguments and attributes are now :attr:`bot` and :attr:`update_queue` as now
          the sole purpose of this class is to fetch updates. The entry point to a PTB application
          is now :class:`telegram.ext.Application`.

    Args:
        bot (:class:`telegram.Bot`): The bot used with this Updater.
        update_queue (:class:`asyncio.Queue`): Queue for the updates.

    Attributes:
        bot (:class:`telegram.Bot`): The bot used with this Updater.
        update_queue (:class:`asyncio.Queue`): Queue for the updates.

    )
__lock__polling_cleanup_cb__polling_task__polling_task_stop_event_httpd_initialized_last_update_id_runningbotupdate_queueasyncio.Queue[object]c                     || _         || _        d| _        d| _        d| _        d | _        t        j                         | _        d | _	        t        j                         | _        d | _        y )Nr   F)r+   r,   r)   r*   r(   r'   asyncioLock_Updater__lock_Updater__polling_taskEvent!_Updater__polling_task_stop_event_Updater__polling_cleanup_cb)selfr+   r,   s      P/var/www/cvtools/html/venv/lib/python3.12/site-packages/telegram/ext/_updater.py__init__zUpdater.__init__v   s\    
 3? !/3lln6:8?&W[!    r6   returnc                    K   	 | j                          d{    | S 7 # t        $ r | j                          d{  7    w xY ww)a0  
        |async_context_manager| :meth:`initializes <initialize>` the Updater.

        Returns:
            The initialized Updater instance.

        Raises:
            :exc:`Exception`: If an exception is raised during initialization, :meth:`shutdown`
                is called in this case.
        N)
initialize	Exceptionshutdownr6   s    r7   
__aenter__zUpdater.__aenter__   sG     	//### 	 $ 	--/!!	s.   A    A  A?AAexc_typeexc_valexc_tbNc                 @   K   | j                          d{    y7 w)zB|async_context_manager| :meth:`shuts down <shutdown>` the Updater.N)r>   )r6   rA   rB   rC   s       r7   	__aexit__zUpdater.__aexit__   s      mmos   c                 0    t        | | j                        S )a  Give a string representation of the updater in the form ``Updater[bot=...]``.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        )r+   )r   r+   r?   s    r7   __repr__zUpdater.__repr__   s     .dAAr9   c                     | j                   S )N)r*   r?   s    r7   runningzUpdater.running   s    }}r9   c                    K   | j                   rt        j                  d       y| j                  j	                          d{    d| _         y7 w)zInitializes the Updater & the associated :attr:`bot` by calling
        :meth:`telegram.Bot.initialize`.

        .. seealso::
            :meth:`shutdown`
        z$This Updater is already initialized.NT)r(   _LOGGERdebugr+   r<   r?   s    r7   r<   zUpdater.initialize   sD      MM@Ahh!!###  	$s   A AAAc                    K   | j                   rt        d      | j                  st        j	                  d       y| j
                  j                          d{    d| _        t        j	                  d       y7 !w)z
        Shutdown the Updater & the associated :attr:`bot` by calling :meth:`telegram.Bot.shutdown`.

        .. seealso::
            :meth:`initialize`

        Raises:
            :exc:`RuntimeError`: If the updater is still running.
        zThis Updater is still running!z-This Updater is already shut down. Returning.NFzShut down of Updater complete)rI   RuntimeErrorr(   rK   rL   r+   r>   r?   s    r7   r>   zUpdater.shutdown   sd      <<?@@  MMIJhh!!!!56 	"s   AA=A;"A=g        
   poll_intervaltimeoutbootstrap_retriesread_timeoutwrite_timeoutconnect_timeoutpool_timeoutallowed_updatesdrop_pending_updateserror_callbackc                 v  K   |
r t        j                  |
      rt        d      | j                  4 d{    | j                  rt        d      | j                  st        d      d| _        	 t        j                         }| j                  ||||||||	|||
       d{    t        j                  d       |j                          d{    t        j                  d       | j                  cddd      d{    S 7 7 e7 :# t        $ r	 d	| _         w xY w7  # 1 d{  7  sw Y   yxY ww)
aM  Starts polling updates from Telegram.

        .. versionchanged:: 20.0
            Removed the ``clean`` argument in favor of :paramref:`drop_pending_updates`.

        Args:
            poll_interval (:obj:`float`, optional): Time to wait between polling updates from
                Telegram in seconds. Default is ``0.0``.
            timeout (:obj:`int`, optional): Passed to
                :paramref:`telegram.Bot.get_updates.timeout`. Defaults to ``10`` seconds.
            bootstrap_retries (:obj:`int`, optional): Whether the bootstrapping phase of the
                :class:`telegram.ext.Updater` will retry on failures on the Telegram server.

                * < 0 - retry indefinitely (default)
                *   0 - no retries
                * > 0 - retry up to X times
            read_timeout (:obj:`float`, optional): Value to pass to
                :paramref:`telegram.Bot.get_updates.read_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. versionchanged:: 20.7
                    Defaults to :attr:`~telegram.request.BaseRequest.DEFAULT_NONE` instead of
                    ``2``.
                .. deprecated:: 20.7
                    Deprecated in favor of setting the timeout via
                    :meth:`telegram.ext.ApplicationBuilder.get_updates_read_timeout` or
                    :paramref:`telegram.Bot.get_updates_request`.
            write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.Bot.get_updates.write_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. deprecated:: 20.7
                    Deprecated in favor of setting the timeout via
                    :meth:`telegram.ext.ApplicationBuilder.get_updates_write_timeout` or
                    :paramref:`telegram.Bot.get_updates_request`.
            connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.Bot.get_updates.connect_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. deprecated:: 20.7
                    Deprecated in favor of setting the timeout via
                    :meth:`telegram.ext.ApplicationBuilder.get_updates_connect_timeout` or
                    :paramref:`telegram.Bot.get_updates_request`.
            pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.Bot.get_updates.pool_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. deprecated:: 20.7
                    Deprecated in favor of setting the timeout via
                    :meth:`telegram.ext.ApplicationBuilder.get_updates_pool_timeout` or
                    :paramref:`telegram.Bot.get_updates_request`.
            allowed_updates (List[:obj:`str`], optional): Passed to
                :meth:`telegram.Bot.get_updates`.
            drop_pending_updates (:obj:`bool`, optional): Whether to clean any pending updates on
                Telegram servers before actually starting to poll. Default is :obj:`False`.

                .. versionadded :: 13.4
            error_callback (Callable[[:exc:`telegram.error.TelegramError`], :obj:`None`],                 optional): Callback to handle :exc:`telegram.error.TelegramError` s that occur
                while calling :meth:`telegram.Bot.get_updates` during polling. Defaults to
                :obj:`None`, in which case errors will be logged. Callback signature::

                    def callback(error: telegram.error.TelegramError)

                Note:
                    The :paramref:`error_callback` must *not* be a :term:`coroutine function`! If
                    asynchronous behavior of the callback is wanted, please schedule a task from
                    within the callback.

        Returns:
            :class:`asyncio.Queue`: The update queue that can be filled from the main thread.

        Raises:
            :exc:`RuntimeError`: If the updater is already running or was not initialized.

        zYThe `error_callback` must not be a coroutine function! Use an ordinary function instead. N This Updater is already running!:This Updater was not initialized via `Updater.initialize`!T)rQ   rR   rT   rU   rV   rW   rS   rY   rX   readyrZ   zWaiting for polling to startz%Polling updates from Telegram startedF)r/   iscoroutinefunction	TypeErrorr1   rI   rN   r(   r*   r3   _start_pollingrK   rL   waitr=   r,   )r6   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   polling_readys               r7   start_pollingzUpdater.start_polling   s>    z g99.I 
 ;;  	%  	%||"#EFF$$"#_`` DM '))"/#!-"/$3!-&7)=$3'#1 *    <=#((***EF $$A 	%  	%  	% +  %; 	%  	%  	%  	%s   3D9DD96D$03D#D	$,DDD*D$5D9D"D9	DDDD$"D9$D6*D-+D62D9r^   c           	         	K   t         j                  d        j                  ||dd        d {    t         j                  d       dt        f	 fd}dt        dd fd}t        j                   j                  ||xs |d	| j                  
      d       _	        d	 fd}| _
        |
|
j                          y y 7 w)NzUpdater started (polling) )rY   webhook_urlrX   zBootstrap doner:   c            	        K   	 j                   j                  j                  	       d {   } | rcj                  st
        j                  d       y| D ]%  }j                  j                  |       d {    ' | d   j                  dz   _        y7 j# t        $ r  t        $ r!}t
        j                  d|       Y d }~yd }~ww xY w7 Vw)NoffsetrR   rT   rV   rU   rW   rX   zcSomething went wrong processing the data received from Telegram. Received data was *not* processed!exc_infoTzYUpdater stopped unexpectedly. Pulled updates will be ignored and pulled again on restart.rP      )r+   get_updatesr)   r   r=   rK   criticalrI   r,   put	update_id)
updatesexcupdaterX   rV   rW   rT   r6   rR   rU   s
      r7   polling_action_cbz1Updater._start_polling.<locals>.polling_action_cbw  s      $ 4 4//#!-$3"/!-$3 !5 ! * ||$$, 	 #* <"//33F;;;<+22;+@+@1+DD(A !    9  ! 
 " <sJ   C/B! BB! AC CCB! !C3C
CCCrs   c                 2    t         j                  d|        y )Nz-Exception happened while polling for updates.rk   )rK   	exception)rs   s    r7   default_error_callbackz6Updater._start_polling.<locals>.default_error_callback  s    MX[\r9   zgetting Updates)	action_cb	on_err_cbdescriptioninterval
stop_eventz"Updater:start_polling:polling_task)namec            	         K   t         j                  d       	 j                  j                  j                  d        d {    y 7 # t
        $ r t         j                  d       Y y w xY ww)NzHCalling `get_updates` one more time to mark all fetched updates as read.r   ri   a-  Error while calling `get_updates` one more time to mark all fetched updates as read: %s. Suppressing error to ensure graceful shutdown. When polling for updates is restarted, updates may be fetched again. Please adjust timeouts via `ApplicationBuilder` or the parameter `get_updates_request` of `Bot`.)rK   rL   r+   rn   r)   r   rw   )rX   rV   rW   rT   r6   rU   s   r7   _get_updates_cleanupz4Updater._start_polling.<locals>._get_updates_cleanup  s{     MMZhh**//!-$3"/!-$3 + 	 	 	 ! !!`s:   A5/A 	A
A A5A A2/A51A22A5r:   N)rK   rL   
_bootstrapboolr   r/   create_task_network_loop_retryr4   r2   r5   set)r6   rQ   rR   rT   rU   rV   rW   rS   rY   rX   r^   rZ   ru   rx   r   s   ` `````  `     r7   ra   zUpdater._start_polling[  s      	12
 oo!5 	  
 	
 	
 	&'"	 "	 "	H	] 	]$ 	] &11$$+(B,B-&99 %  6	
 	 	. %9!IIK y	
s   .CCBCrf   r   (   listenporturl_pathcertkeyrg   
ip_addressmax_connectionssecret_tokenunixr   c                 p  K   t         st        d      |rcd}t        |t              st        |j	                  d            t        |t              st        |j	                  d            |st        d      | j
                  4 d{    | j                  rt        d      | j                  st        d      d	| _        	 t        j                         }| j                  t        j                  |      t        j                  |      |||||	||||
|||
       d{    t        j                  d       |j                          d{    t        j                  d       | j"                  cddd      d{    S 7 7 e7 :# t         $ r	 d| _         w xY w7  # 1 d{  7  sw Y   yxY ww)a/  
        Starts a small http server to listen for updates via webhook. If :paramref:`cert`
        and :paramref:`key` are not provided, the webhook will be started directly on
        ``http://listen:port/url_path``, so SSL can be handled by another
        application. Else, the webhook will be started on
        ``https://listen:port/url_path``. Also calls :meth:`telegram.Bot.set_webhook` as required.

        Important:
            If you want to use this method, you must install PTB with the optional requirement
            ``webhooks``, i.e.

            .. code-block:: bash

               pip install "python-telegram-bot[webhooks]"

        .. seealso:: :wiki:`Webhooks`

        .. versionchanged:: 13.4
            :meth:`start_webhook` now *always* calls :meth:`telegram.Bot.set_webhook`, so pass
            ``webhook_url`` instead of calling ``updater.bot.set_webhook(webhook_url)`` manually.
        .. versionchanged:: 20.0

            * Removed the ``clean`` argument in favor of :paramref:`drop_pending_updates` and
              removed the deprecated argument ``force_event_loop``.

        Args:
            listen (:obj:`str`, optional): IP-Address to listen on. Defaults to
                `127.0.0.1 <https://en.wikipedia.org/wiki/Localhost>`_.
            port (:obj:`int`, optional): Port the bot should be listening on. Must be one of
                :attr:`telegram.constants.SUPPORTED_WEBHOOK_PORTS` unless the bot is running
                behind a proxy. Defaults to ``80``.
            url_path (:obj:`str`, optional): Path inside url (http(s)://listen:port/<url_path>).
                Defaults to ``''``.
            cert (:class:`pathlib.Path` | :obj:`str`, optional): Path to the SSL certificate file.
            key (:class:`pathlib.Path` | :obj:`str`, optional): Path to the SSL key file.
            drop_pending_updates (:obj:`bool`, optional): Whether to clean any pending updates on
                Telegram servers before actually starting to poll. Default is :obj:`False`.

                .. versionadded :: 13.4
            bootstrap_retries (:obj:`int`, optional): Whether the bootstrapping phase of the
                :class:`telegram.ext.Updater` will retry on failures on the Telegram server.

                * < 0 - retry indefinitely
                *   0 - no retries (default)
                * > 0 - retry up to X times
            webhook_url (:obj:`str`, optional): Explicitly specify the webhook url. Useful behind
                NAT, reverse proxy, etc. Default is derived from :paramref:`listen`,
                :paramref:`port`, :paramref:`url_path`, :paramref:`cert`, and :paramref:`key`.
            ip_address (:obj:`str`, optional): Passed to :meth:`telegram.Bot.set_webhook`.
                Defaults to :obj:`None`.

                .. versionadded :: 13.4
            allowed_updates (List[:obj:`str`], optional): Passed to
                :meth:`telegram.Bot.set_webhook`. Defaults to :obj:`None`.
            max_connections (:obj:`int`, optional): Passed to
                :meth:`telegram.Bot.set_webhook`. Defaults to ``40``.

                .. versionadded:: 13.6
            secret_token (:obj:`str`, optional): Passed to :meth:`telegram.Bot.set_webhook`.
                Defaults to :obj:`None`.

                When added, the web server started by this call will expect the token to be set in
                the ``X-Telegram-Bot-Api-Secret-Token`` header of an incoming request and will
                raise a :class:`http.HTTPStatus.FORBIDDEN <http.HTTPStatus>` error if either the
                header isn't set or it is set to a wrong token.

                .. versionadded:: 20.0
            unix (:class:`pathlib.Path` | :obj:`str` | :class:`socket.socket`, optional): Can be
                either:

                * the path to the unix socket file as :class:`pathlib.Path` or :obj:`str`. This
                  will be passed to `tornado.netutil.bind_unix_socket <https://www.tornadoweb.org/
                  en/stable/netutil.html#tornado.netutil.bind_unix_socket>`_ to create the socket.
                  If the Path does not exist, the file will be created.

                * or the socket itself. This option allows you to e.g. restrict the permissions of
                  the socket for improved security. Note that you need to pass the correct family,
                  type and socket options yourself.

                Caution:
                    This parameter is a replacement for the default TCP bind. Therefore, it is
                    mutually exclusive with :paramref:`listen` and :paramref:`port`. When using
                    this param, you must also run a reverse proxy to the unix socket and set the
                    appropriate :paramref:`webhook_url`.

                .. versionadded:: 20.8
                .. versionchanged:: 21.1
                    Added support to pass a socket instance itself.
        Returns:
            :class:`queue.Queue`: The update queue that can be filled from the main thread.

        Raises:
            :exc:`RuntimeError`: If the updater is already running or was not initialized.
        z`To use `start_webhook`, PTB must be installed via `pip install "python-telegram-bot[webhooks]"`.z|You can not pass unix and {0}, only use one. Unix if you want to initialize a unix socket, or {0} for a standard TCP server.r   r   zqSince you set unix, you also need to set the URL to the webhook of the proxy you run in front of the unix socket.Nr\   r]   T)r   r   r   r   r   rS   rY   rg   rX   r^   r   r   r   r   z#Waiting for webhook server to startzWebhook server startedF)WEBHOOKS_AVAILABLErN   
isinstancer   formatr1   rI   r(   r*   r/   r3   _start_webhook	get_valuerK   rL   rb   r=   r,   )r6   r   r   r   r   r   rS   rg   rX   rY   r   r   r   r   	error_msgwebhook_readys                   r7   start_webhookzUpdater.start_webhook  s    \ "4 
 N  fl3"9#3#3H#=>>dL1"9#3#3F#;<<"H 
 ;; %	% %	%||"#EFF$$"#_`` DM '))'11&9%//5%&7)= +$3')$3!- *   " CD#((***67 $$K%	% %	% %	%$ +  %A%	% %	% %	% %	%s   BF6	F
F66F!AF
 F!,F
FF
'F!2F6>F?F6F
F

FF!F6!F3'F*(F3/F6c           
        K   t         j                  d       |j                  d      sd| }t        || j                  | j
                  |      }|C|A	 t        j                  t        j                  j                        }|j                  ||       nd }t        |||||      | _        |	s,| j                  |rdndt!        j"                  |      ||      }	| j%                  |rt'        |      j)                         nd |||	||||       d {    | j                  j+                  |
       d {    y # t        j                  $ r}t        d      |d }~ww xY w7 P7 .w)	Nz Updater thread started (webhook)/zInvalid SSL Certificatehttpshttpprotocolr   r   r   )r   max_retriesrY   rg   rX   r   r   r   )r^   )rK   rL   
startswithr   r+   r,   sslcreate_default_contextPurposeCLIENT_AUTHload_cert_chainSSLErrorr   r   r'   _gen_webhook_urlr   r   r   r   
read_bytesserve_forever)r6   r   r   r   rS   rX   r   r   rY   rg   r^   r   r   r   r   appssl_ctxrs   s                     r7   r   zUpdater._start_webhookw  so    " 	89""3'8*~H h$2C2C\R H474N4NKK++5 ''c2 G#FD#wE//$+#--f5!	 0 K oo -1d&&(d)!5#+!+%  
 	
 	
 kk''e'444; << H#$=>CGH 	
 	5sI   AE%?D: A<E%E!#E%4E#5E%:EEEE%#E%r   c                     |  d| d| | S )Nz://: r   s       r7   r   zUpdater._gen_webhook_url  s     3vhavhZ88r9   ry   .rz   r{   r|   r}   c                 d  K   dt         ffd}t        j                  d       |}| j                  rA	  |        d{   sy	 |}|rt        j                  |       d{    | j                  r@yy7 6# t        $ r/}t        j                  d|       d|j                  z   }Y d}~cd}~wt        $ r#}	t        j                  d|	       d}Y d}	~	d}	~	wt        $ r t        j                  d	        t        $ r(}
 ||
       |dk(  rd
nt        dd|z        }Y d}
~
d}
~
ww xY w7 ǭw)a  Perform a loop calling `action_cb`, retrying after network errors.

        Stop condition for loop: `self.running` evaluates :obj:`False` or return value of
        `action_cb` evaluates :obj:`False`.

        Args:
            action_cb (:term:`coroutine function`): Network oriented callback function to call.
            on_err_cb (:obj:`callable`): Callback to call when TelegramError is caught. Receives
                the exception object as a parameter.
            description (:obj:`str`): Description text to use for logs and exception raised.
            interval (:obj:`float` | :obj:`int`): Interval to sleep between each call to
                `action_cb`.
            stop_event (:class:`asyncio.Event` | :obj:`None`): Event to wait on for stopping the
                loop. Setting the event will make the loop exit even if `action_cb` is currently
                running.

        r:   c                  
  K   s         d {   S t        j                                } t        j                  j                               }t        j                  | |ft         j                         d {   \  }}t	        j
                  t         j                        5  |D ]  }|j                           	 d d d        ||v rt        j                  d       y| j                         S 7 7 x# 1 sw Y   8xY ww)N)return_whenz#Network loop retry %s was cancelledF)r/   r   rb   FIRST_COMPLETED
contextlibsuppressCancelledErrorcancelrK   rL   result)action_cb_task	stop_taskdonependingtaskry   r{   r}   s        r7   	do_actionz.Updater._network_loop_retry.<locals>.do_action  s     &[(($00=N++JOO,=>I"),,+9P9P# MD' $$W%;%;< "# "DKKM"" D C[Q!((** )" "s:   DC3A+D<C5=*D'C7 4D5D7D <DzStart network loop retry %sNz%sg      ?zTimed out %s: %sr   zInvalid token; abortingrm      g      ?)r   rK   rL   rI   r   inforetry_afterr   r   rw   r   minr/   sleep)r6   ry   rz   r{   r|   r}   r   cur_intervalrs   toetelegram_excs    ` ` `     r7   r   zUpdater._network_loop_retry  s	    4	+ 	+& 	3[All(&[(( )$  (mmL111/ ll( 5T3'"S__4 !0+sC  !!";<  W,' %1A$5q3r3CU;V	W 2s|   3D0
A< A:A< D0
D0&D.'D08D0:A< <	D+%B/*D0/D+;CD0*D+D&!D0&D++D0r   bootstrap_intervalc
           	         	K   ddt         f fd}
dt         f	 fd}dt        ddffd}ss  j                  |
|d|d	       d{    dr j                  ||d
|d	       d{    yy7 (7 w)zPrepares the setup for fetching updates: delete or set the webhook and drop pending
        updates if appropriate. If there are unsuccessful attempts, this will retry as specified by
        :paramref:`max_retries`.
        r   r:   c                     K   t         j                  d        rt         j                  d       j                  j                          d {    y7 w)NzDeleting webhook-Dropping pending updates from Telegram server)rY   F)rK   rL   r+   delete_webhook)rY   r6   s   r7   bootstrap_del_webhookz1Updater._bootstrap.<locals>.bootstrap_del_webhook  sI     MM,-#MN(())?S)TTT Us   AAAAc            	         K   t         j                  d       rt         j                  d       j                  j                          d {    y7 w)NzSetting webhookr   )urlcertificaterX   r   rY   r   r   F)rK   rL   r+   set_webhook)rX   r   rY   r   r   r   r6   rg   s   r7   bootstrap_set_webhookz1Updater._bootstrap.<locals>.bootstrap_set_webhook!  sd     MM+,#MN((&&  /%%9 /) '    s   AAAArs   Nc                     t        | t              s'dk  sk  rdz  t        j                  d       y t        j	                  d|        | )Nr   rm   z-Failed bootstrap phase; try=%s max_retries=%sz,Failed bootstrap phase after %s retries (%s))r   r   rK   warningerror)rs   r   retriess    r7   bootstrap_on_err_cbz/Updater._bootstrap.<locals>.bootstrap_on_err_cb0  sR    
 c<0kAoS^I^1CWk LgWZ[	r9   zbootstrap del webhook)r}   zbootstrap set webhook)r   r=   r   )r6   r   rg   rX   rY   r   r   r   r   r   r   r   r   r   s   `````` ```   @r7   r   zUpdater._bootstrap  s       	T 		T 	 		Y 	4 	$  {**%#'" +    G **%#'" +    s$   ABB!B=B>BBc                   K   | j                   4 d{    | j                  st        d      t        j	                  d       d| _        | j                          d{    | j                          d{    t        j	                  d       ddd      d{    y7 7 D7 .7 # 1 d{  7  sw Y   yxY ww)zStops the polling/webhook.

        .. seealso::
            :meth:`start_polling`, :meth:`start_webhook`

        Raises:
            :exc:`RuntimeError`: If the updater is not running.
        NzThis Updater is not running!zStopping UpdaterFzUpdater.stop() is complete)r1   rI   rN   rK   rL   r*   _stop_httpd_stop_pollingr?   s    r7   stopzUpdater.stopY  s      ;; 	8 	8<<"#ABBMM,-!DM""$$$$$&&&MM67	8 	8 	8 %&	8 	8 	8 	8si   B>B!B>AB)B#B)6B%7B)B>B'B>#B)%B)'B>)B;/B20B;7B>c                    K   | j                   r?t        j                  d       | j                   j                          d{    d| _         yy7 w)z@Stops the Webhook server by calling ``WebhookServer.shutdown()``z4Waiting for current webhook connection to be closed.N)r'   rK   rL   r>   r?   s    r7   r   zUpdater._stop_httpdo  s?     ;;MMPQ++&&(((DK (s   ?AAAc                   K   | j                   rt        j                  d       | j                  j	                          t        j                  t        j                        5  | j                    d{    ddd       d| _         | j                  j                          | j                  r | j                          d{    d| _
        yt        j                  d       yy7 p# 1 sw Y   oxY w7 1w)z&Stops the polling task by awaiting it.z-Waiting background polling task to finish up.NzmNo polling cleanup callback defined. The last fetched updates may be fetched again on the next polling start.)r2   rK   rL   r4   r   r   r   r/   r   clearr5   r   r?   s    r7   r   zUpdater._stop_pollingv  s     MMIJ**..0$$W%;%;< *))))*
 #'D**002((//111,0)?! 
 ** * 2s=   AC2!C$1C"2C$6AC2>C0?#C2"C$$C-)C2)r+   r   r,   r-   r   )	NNNNNNr   NN)NNrm   Nr   N)/__name__
__module____qualname____doc__	__slots__r8   r   r@   r   r   BaseExceptionr   rE   strrG   propertyr   rI   r<   r>   r   floatintr   r
   r   r   rd   r/   r3   ra   r   r   r   r   r   r   r   staticmethodr   r	   r   bytesr   r   r   r   r   r9   r7   r    r    =   s   )VI\\ .\"|  $	4./	 -(	 '		
 
		B# 	B   !7.  #!#(4)5+7(4/3/3DHC%C% C% 	C%
 uoC%  C% "%C% uoC% "$s),C% 'tnC% !=/4*?!@AC% 
!C%Jpp p uo	p
  p "%p uop p 'tnp "$s),p }}p !=/4*?!@Ap 
ph )&+/*.!"%)/3/3$(!&*59h%sh% Skh% 	h%
 uS$Y'(h% eCI&'h% h% c]h% "$s),h% 'tnh% SMh% h% smh% uS$012h% 
!h%b ,0*./3%))-$(!&*59A5A5 A5 	A5
 A5 "$s),A5 uS$Y'(A5 eCI&'A5 'tnA5 c]A5 &A5 SMA5 A5 smA5 uS$012A5  
!A5F 93 9 93 9# 9RU 9 9
F2CN+F2 ]OT12F2 	F2
 F2 W]]+F2 
F2Z 04 $$%$(!&*OO c]O "$s),	O
 'tnO uoO "O SMO O smO 
Ob8,r9   )0r   r/   r   r   pathlibr   typesr   typingr   r   r   r   r	   r
   r   r   r   r   telegram._utils.defaultvaluer   r   r   r   telegram._utils.loggingr   telegram._utils.reprr   telegram._utils.typesr   r   telegram.errorr   r   r   r   "telegram.ext._utils.webhookhandlerr   r   r   ImportErrorr   telegramr   r   r   rK   r    r   r9   r7   <module>r      s   & d   
     \ [ . ? 2 L LQ  ~Y7
X
N!), N  s    
B B#"B#