Ë
    3ýj.  ã                   óø  — d Z ddlZddlZddl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 	 ddlmZ dZej,                  j/                  d	«      Zed
„ «       Zd„ Zd„ Z G d„ dej8                  «      Zd„ Z G d„ d«      Z G d„ d«      Z  G d„ d«      Z! G d„ dejD                  «      Z#ere#Z$ye Z$y# e$ rB 	 ddlmZ n7# e$ r/ 	 ddlmZ n$# e$ r 	 ddlmZ n# e$ r	 ddlmZ Y nw xY wY nw xY wY nw xY wY ŒÄw xY w)z#Threading primitives and utilities.é    N)Úcontextmanager)ÚTIMEOUT_MAX©ÚProxy)Ú
getcurrent)Ú	get_ident)ÚbgThreadÚLocalÚ
LocalStackÚLocalManagerr   Údefault_socket_timeoutÚbound_open_broker_socketsÚUSE_FAST_LOCALSc              #   óÆ   K  — t        j                  «       }t        j                  | «       	 d–— t        j                  |«       y# t        j                  |«       w xY w­w)zÔContext temporarily setting the default socket timeout.

    Note:
        Only affects sockets created afterwards.  To bound a connection
        that is already open, use :func:`bound_open_broker_sockets`.
    N)ÚsocketÚgetdefaulttimeoutÚsetdefaulttimeout)ÚtimeoutÚprevs     úN/root/telegram-saas/.venv/lib/python3.12/site-packages/celery/utils/threads.pyr   r   $   sH   è ø€ ô ×#Ñ#Ó%€DÜ
×Ñ˜WÔ%ð'Ûä× Ñ  Õ&øŒ× Ñ  Õ&üs   ‚*A!­A ±A!ÁAÁA!c           	   #   ó\  K  — 	 t        t        | j                  dd«      xs d«      }|D ]D  }t        |di «      }dD ]0  }t        t        |j	                  |«      dd«      dd«      }|€Œ-|–— Œ2 ŒF t        t        | j
                  dd«      d	d«      }|�|–— yy# t        $ r d}Y Œ€w xY w­w)
z7Yield the sockets a broker connection already has open.ÚchannelsN© Ú__dict__)ÚclientÚ	subclientÚ
connectionÚ_sockÚ
_transportÚsock)ÚlistÚgetattrÚ	transportÚ	ExceptionÚgetÚ_connection)r   r   ÚchannelÚcachedÚnamer    s         r   Ú_open_broker_socketsr*   4   sÐ   è ø€ ðÜœ 
× 4Ñ 4°jÀ$ÓGÒMÈ2ÓNˆð ò ˆô ˜ *¨bÓ1ˆØ+ò 	ˆDÜÜ˜Ÿ
™
 4Ó(¨,¸Ó=¸wÈóNˆDàÑØ“
ñ		ð	ô Ü�
×&Ñ&¨°dÓ;¸VÀTóK€DàÐØ‹
ð øô ò ØŠðüs.   ‚B,„$B ¨A B,Á)2B,ÂB)Â&B,Â(B)Â)B,c                 ó†   — 	 t        | «      D ]  }	 |j                  |«       Œ y# t        $ r Y Œ#w xY w# t        $ r Y yw xY w)as  Apply ``timeout`` to broker sockets that are already connected.

    :func:`socket.setdefaulttimeout` only affects sockets created
    afterwards, so neither it nor ``Connection.collect(socket_timeout=...)``
    can bound a read on a socket that is already open.  Teardown issues
    exactly such reads (the redis transport drains a pending ``BRPOP`` in
    ``Channel.close()``, py-amqp waits for a ``basic_cancel`` reply), and
    against a peer that went silent without RST they never return.

    See Issue #9705 (reconnect) and Issue #975 (shutdown).  Best effort:
    never raises, as both callers are teardown paths.
    N)r*   Ú
settimeoutr$   )r   r   r    s      r   r   r   L   sQ   € ðÜ(¨Ó4ò 	ˆDðØ—‘ Õ(ñ	øô ò Ùðûäò Ùðús&   ‚4 ‘%¢4 ¥	1®4 °1±4 ´	A ¿A c                   óB   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Zd„ Zd„ Z	ˆ xZ
S )	r	   zBackground service thread.c                 óÒ   •— t         ‰| �  «        t        j                  «       | _        t        j                  «       | _        d| _        |xs | j                  j                  | _	        y )NT)
ÚsuperÚ__init__Ú	threadingÚEventÚ_bgThread__is_shutdownÚ_bgThread__is_stoppedÚdaemonÚ	__class__Ú__name__r)   )Úselfr)   Úkwargsr6   s      €r   r0   zbgThread.__init__f   sI   ø€ Ü‰ÑÔÜ&Ÿ_™_Ó.ˆÔÜ%ŸO™OÓ-ˆÔØˆŒØÒ3˜DŸN™N×3Ñ3ˆ�	ó    c                 ó   — t        «       ‚©N)ÚNotImplementedError©r8   s    r   ÚbodyzbgThread.bodym   s   € Ü!Ó#Ð#r:   c                 óœ   — t         |j                  |Ž t        j                  ¬«       t	        j
                  d t        j                  «       y )N)Úfile)ÚprintÚformatÚsysÚstderrÚ	tracebackÚ	print_exc)r8   ÚmsgÚfmtr9   s       r   Úon_crashzbgThread.on_crashp   s/   € Üˆjˆc�j‰j˜#Ð¤S§Z¡ZÕ0Ü×Ñ˜D¤#§*¡*Õ-r:   c                 ó"  — | j                   }| j                  j                  }	  |«       s	  |«         |«       sŒ| j                  «        y # t        $ r¤}	 | j	                  d| j
                  |«       | j                  «        t        j                  j                  «        t        j                  d«       n8# t        j                  j                  «        t        j                  d«       w xY wY d }~ŒÁd }~ww xY w# | j                  «        w xY w)Nz{0!r} crashed: {1!r}é   )r?   r3   Úis_setr$   rJ   r)   Ú_set_stoppedrD   rE   ÚflushÚosÚ_exit)r8   r?   Úshutdown_setÚexcs       r   ÚrunzbgThread.runt   sÈ   € Ø�y‰yˆØ×)Ñ)×0Ñ0ˆð	 Ù"”nð$Ù”Fñ #•nð ×ÑÕøô !ò $ð$ØŸ™Ð&<¸d¿i¹iÈÔMØ×)Ñ)Ô+äŸ
™
×(Ñ(Ô*ÜŸ™ �øô Ÿ
™
×(Ñ(Ô*ÜŸ™ �úœûð$ûð ×ÑÕúsE   ¤C< ¬A ³C< Á	C9Á-B7Â4C4Â75C,Ã,C4Ã/C< Ã4C9Ã9C< Ã<Dc                 óX   — 	 | j                   j                  «        y # t        $ r Y y w xY wr<   )r4   ÚsetÚ	TypeErrorr>   s    r   rN   zbgThread._set_stopped…   s-   € ð	Ø×Ñ×!Ñ!Õ#øÜò 	ñ ð	ús   ‚ �	)¨)c                 ó¸   — | j                   j                  «        | j                  j                  «        | j	                  «       r| j                  t        «       yy)zGraceful shutdown.N)r3   rV   r4   ÚwaitÚis_aliveÚjoinÚTHREAD_TIMEOUT_MAXr>   s    r   ÚstopzbgThread.stop�   sA   € à×Ñ×ÑÔ Ø×Ñ×ÑÔ Ø�=‰=Œ?Ø�I‰IÔ(Õ)ð r:   r<   )r7   Ú
__module__Ú__qualname__Ú__doc__r0   r?   rJ   rT   rN   r]   Ú__classcell__©r6   s   @r   r	   r	   c   s$   ø„ Ù$õ4ò$ò.ò ò"ö*r:   r	   c                 ó$   — | j                  «        y)a-  Release the contents of the local for the current context.

    This makes it possible to use locals without a manager.

    With this function one can release :class:`Local` objects as well as
    :class:`StackLocal` objects.  However it's not possible to
    release data held by proxies that way, one always has to retain
    a reference to the underlying local object in order to be able
    to release it.

    Example:
        >>> loc = Local()
        >>> loc.foo = 42
        >>> release_local(loc)
        >>> hasattr(loc, 'foo')
        False
    N)Ú__release_local__)Úlocals    r   Úrelease_localrf   •   s   € ð$ 
×ÑÕr:   c                   ó>   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zy
)r
   zLocal object.)Ú__storage__Ú__ident_func__c                 óh   — t         j                  | di «       t         j                  | dt        «       y )Nrh   ri   )ÚobjectÚ__setattr__r   r>   s    r   r0   zLocal.__init__¯   s'   € Ü×Ñ˜4 °Ô3Ü×Ñ˜4Ð!1´9Õ=r:   c                 óH   — t        | j                  j                  «       «      S r<   )Úiterrh   Úitemsr>   s    r   Ú__iter__zLocal.__iter__³   s   € Ü�D×$Ñ$×*Ñ*Ó,Ó-Ð-r:   c                 ó   — t        | |«      S )zCreate a proxy for a name.r   )r8   Úproxys     r   Ú__call__zLocal.__call__¶   s   € ä�T˜5Ó!Ð!r:   c                 óX   — | j                   j                  | j                  «       d «       y r<   )rh   Úpopri   r>   s    r   rd   zLocal.__release_local__º   s!   € Ø×Ñ×Ñ˜T×0Ñ0Ó2°DÕ9r:   c                 ót   — 	 | j                   | j                  «          |   S # t        $ r t        |«      ‚w xY wr<   ©rh   ri   ÚKeyErrorÚAttributeError©r8   r)   s     r   Ú__getattr__zLocal.__getattr__½   s@   € ð	'Ø×#Ñ# D×$7Ñ$7Ó$9Ñ:¸4Ñ@Ð@øÜò 	'Ü  Ó&Ð&ð	'ús   ‚" ¢7c                 óz   — | j                  «       }| j                  }	 |||   |<   y # t        $ r
 ||i||<   Y y w xY wr<   )ri   rh   rx   )r8   r)   ÚvalueÚidentÚstorages        r   rl   zLocal.__setattr__Ã   sJ   € Ø×#Ñ#Ó%ˆØ×"Ñ"ˆð	+Ø#(ˆG�E‰N˜4Ò øÜò 	+Ø" E˜]ˆG�E‹Nð	+ús   ž' §:¹:c                 ór   — 	 | j                   | j                  «          |= y # t        $ r t        |«      ‚w xY wr<   rw   rz   s     r   Ú__delattr__zLocal.__delattr__Ë   s=   € ð	'Ø× Ñ  ×!4Ñ!4Ó!6Ñ7¸Ñ=øÜò 	'Ü  Ó&Ð&ð	'ús   ‚! ¡6N)r7   r^   r_   r`   Ú	__slots__r0   rp   rs   rd   r{   rl   r�   r   r:   r   r
   r
   ª   s-   „ Ùà1€Iò>ò.ò"ò:ò'ò+ó'r:   r
   c                   óš   — e Zd ZdZd„ Zd„ Zd„ Zd„ Z eee«      Z	[[d„ Z
d„ Zd„ Z eej                  «      Zd	„ Zed
„ «       Zed„ «       Zy)Ú_LocalStackaõ  Local stack.

    This class works similar to a :class:`Local` but keeps a stack
    of objects instead.  This is best explained with an example::

        >>> ls = LocalStack()
        >>> ls.push(42)
        >>> ls.top
        42
        >>> ls.push(23)
        >>> ls.top
        23
        >>> ls.pop()
        23
        >>> ls.top
        42

    They can be force released by using a :class:`LocalManager` or with
    the :func:`release_local` function but the correct way is to pop the
    item from the stack after using.  When the stack is empty it will
    no longer be bound to the current context (and as such released).

    By calling the stack without arguments it will return a proxy that
    resolves to the topmost item on the stack.
    c                 ó"   — t        «       | _        y r<   )r
   Ú_localr>   s    r   r0   z_LocalStack.__init__í   s   € Ü“gˆ�r:   c                 ó8   — | j                   j                  «        y r<   )r†   rd   r>   s    r   rd   z_LocalStack.__release_local__ð   s   € Ø�‰×%Ñ%Õ'r:   c                 ó.   — | j                   j                  S r<   )r†   ri   r>   s    r   Ú_get__ident_func__z_LocalStack._get__ident_func__ó   s   € Ø�{‰{×)Ñ)Ð)r:   c                 óF   — t         j                  | j                  d|«       y ©Nri   )rk   rl   r†   )r8   r}   s     r   Ú_set__ident_func__z_LocalStack._set__ident_func__ö   s   € Ü×Ñ˜4Ÿ;™;Ð(8¸%Õ@r:   c                 ó$   ‡ — ˆ fd„}t        |«      S )Nc                  ó:   •— ‰j                   } | €t        d«      ‚| S )Nzobject unbound)ÚtopÚRuntimeError)Úrvr8   s    €r   Ú_lookupz%_LocalStack.__call__.<locals>._lookupü   s"   ø€ Ø—‘ˆBØˆzÜ"Ð#3Ó4Ð4ØˆIr:   r   )r8   r’   s   ` r   rs   z_LocalStack.__call__û   s   ø€ ô	ô
 �W‹~Ðr:   c                 ó€   — t        | j                  dd«      }|€g x| j                  _        }|j                  |«       |S )zPush a new item to the stack.ÚstackN)r"   r†   r”   Úappend)r8   Úobjr‘   s      r   Úpushz_LocalStack.push  s<   € ä�T—[‘[ '¨4Ó0ˆØˆ:ð &(Ð'ˆD�K‰KÔ Ø
�	‰	�#ŒØˆ	r:   c                 ó¦   — t        | j                  dd«      }|€yt        |«      dk(  rt        | j                  «       |d   S |j	                  «       S )z�Remove the topmost item from the stack.

        Note:
            Will return the old value or `None` if the stack was already empty.
        r”   NrL   éÿÿÿÿ)r"   r†   Úlenrf   ru   ©r8   r”   s     r   ru   z_LocalStack.pop  sK   € ô ˜Ÿ™ W¨dÓ3ˆØˆ=ØÜ�‹Z˜1Š_Ü˜$Ÿ+™+Ô&Ø˜‘9Ðà—9‘9“;Ðr:   c                 óN   — t        | j                  dd «      }|rt        |«      S dS )Nr”   r   )r"   r†   rš   r›   s     r   Ú__len__z_LocalStack.__len__  s%   € Ü˜Ÿ™ W¨dÓ3ˆÙ"Œs�5‹zÐ)¨Ð)r:   c                 ó<   — t        | j                  dd «      }|�|S g S )Nr”   )r"   r†   r›   s     r   r”   z_LocalStack.stack"  s&   € ô ˜Ÿ™ W¨dÓ3ˆØÐØˆLØˆ	r:   c                 ó`   — 	 | j                   j                  d   S # t        t        f$ r Y yw xY w)ztThe topmost item on the stack.

        Note:
            If the stack is empty, :const:`None` is returned.
        r™   N)r†   r”   ry   Ú
IndexErrorr>   s    r   r�   z_LocalStack.top+  s3   € ð	Ø—;‘;×$Ñ$ RÑ(Ð(øÜ¤
Ð+ò 	Ùð	ús   ‚ ›-¬-N)r7   r^   r_   r`   r0   rd   r‰   rŒ   Úpropertyri   rs   r—   ru   ÚclassmethodÚtypesÚGenericAliasÚ__class_getitem__r�   r”   r�   r   r:   r   r„   r„   Ò   s   „ ñò4ò(ò*òAáÐ0Ð2DÓE€NØÐ.òòòñ $ E×$6Ñ$6Ó7Ðò*ð ñó ðð ñ	ó ñ	r:   r„   c                   ó*   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zy)r   a¤  Local objects cannot manage themselves.

    For that you need a local manager.
    You can pass a local manager multiple locals or add them
    later by appending them to ``manager.locals``.  Every time the manager
    cleans up, it will clean up all the data left in the locals for this
    context.

    The ``ident_func`` parameter can be added to override the default ident
    function for the wrapped locals.
    Nc                 óä   — |€g | _         n)t        |t        «      r	|g| _         nt        |«      | _         |�0|| _        | j                   D ]  }t
        j                  |d|«       Œ y t        | _        y r‹   )ÚlocalsÚ
isinstancer
   r!   Ú
ident_funcrk   rl   r   )r8   r¨   rª   re   s       r   r0   zLocalManager.__init__E  sj   € Øˆ>ØˆD�KÜ˜¤Ô&Ø!˜(ˆD�Kä˜v›,ˆDŒKØÐ!Ø(ˆDŒOØŸ™ò H�Ü×"Ñ" 5Ð*:¸JÕGñHô (ˆD�Or:   c                 ó"   — | j                  «       S )a4  Return context identifier.

        This is the identifier the local objects use internally
        for this context.  You cannot override this method to change the
        behavior but use it to link other context local objects (such as
        SQLAlchemy's scoped sessions) to the Werkzeug locals.
        )rª   r>   s    r   r   zLocalManager.get_identS  s   € ð �‰Ó Ð r:   c                 ó<   — | j                   D ]  }t        |«       Œ y)zŽManually clean up the data in the locals for this context.

        Call this at the end of the request or use ``make_middleware()``.
        N)r¨   rf   )r8   re   s     r   ÚcleanupzLocalManager.cleanup]  s   € ð
 —[‘[ò 	!ˆEÜ˜%Õ ñ	!r:   c                 ót   — dj                  | j                  j                  t        | j                  «      «      S )Nz<{} storages: {}>)rC   r6   r7   rš   r¨   r>   s    r   Ú__repr__zLocalManager.__repr__e  s-   € Ø"×)Ñ)Ø�N‰N×#Ñ#¤S¨¯©Ó%5ó7ð 	7r:   )NN)r7   r^   r_   r`   r0   r   r­   r¯   r   r:   r   r   r   8  s   „ ñ
ó(ò!ò!ó7r:   r   c                   óX   ‡ — e Zd Zˆ fd„Zed„ «       Z eej                  «      Z	d„ Z
ˆ xZS )Ú_FastLocalStackc                 óœ   •— g | _         | j                   j                  | _        | j                   j                  | _        t        ‰| �  «        y r<   )r”   r•   r—   ru   r/   r0   )r8   r6   s    €r   r0   z_FastLocalStack.__init__l  s5   ø€ ØˆŒ
Ø—J‘J×%Ñ%ˆŒ	Ø—:‘:—>‘>ˆŒÜ‰ÑÕr:   c                 óL   — 	 | j                   d   S # t        t        f$ r Y y w xY w)Nr™   )r”   ry   r    r>   s    r   r�   z_FastLocalStack.topr  s,   € ð	Ø—:‘:˜b‘>Ð!øÜ¤
Ð+ò 	Ùð	ús   ‚ ‘#¢#c                 ó,   — t        | j                  «      S r<   )rš   r”   r>   s    r   r�   z_FastLocalStack.__len__{  s   € Ü�4—:‘:‹Ðr:   )r7   r^   r_   r0   r¡   r�   r¢   r£   r¤   r¥   r�   ra   rb   s   @r   r±   r±   j  s4   ø„ ôð ñó ðñ $ E×$6Ñ$6Ó7Ðör:   r±   )%r`   rP   r   rD   r1   rF   r£   Ú
contextlibr   r   r\   Úcelery.localr   Úgreenletr   r   ÚImportErrorÚ_threadÚthreadÚ_dummy_threadÚdummy_threadÚ__all__Úenvironr%   r   r   r*   r   ÚThreadr	   rf   r
   r„   r   re   r±   r   r   r:   r   ú<module>rÀ      s  ðÙ )Û 	Û Û 
Û Û Û Ý %Ý 7å ð3Ý0ð€ð
 —*‘*—.‘.Ð!2Ó3€ð ñ'ó ð'òò0ô./*ˆy×Ñô /*òd÷*%'ñ %'÷Pcñ c÷L/7ñ /7ôd�i—o‘oô ñ* Ø �Jð �Jøðo ò 
3ð	3Þ%øØò 3ð	3Þ(øØò 	3ð3Þ3øØò 3ß2ð3üð	3üð3üð
3ús}   ®B2 Â2C9Â8B?Â>C9Â?C3ÃCÃC3ÃC-ÃCÃC-ÃC'	Ã$C-Ã&C'	Ã'C-Ã*C3Ã,C-Ã-C3Ã0C9Ã2C3Ã3C9Ã8C9