o
    v&iS                     @   sX   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 edZ
G dd dejjZdS )z]Minimal backported implementation of asyncio._PyTask from 3.11 compatible down to Python 3.8.    N)AbstractEventLoop)	CoroutineTypeVarAnyOptional_Tc                	       s   e Zd ZdZddddeeeef dee dee	 ddf fdd	Z
dd
ee	 defddZdefddZdefddZ  ZS )Taskz A coroutine wrapped in a Future.Nloopnamecoror
   r   returnc                   s   d| _ t j|||d d S )Nr   r	   )_num_cancels_requestedsuper__init__)selfr   r
   r   	__class__ d/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/backports/asyncio/runner/tasks.pyr      s   zTask.__init__msgc                 C   sp   d| _ |  r	dS |  jd7  _| jdur+tjdkr$| jj|dr#dS n| j r+dS d| _tjdkr6|| _dS )a  Request that this task cancel itself.

        This arranges for a CancelledError to be thrown into the
        wrapped coroutine on the next cycle through the event loop.
        The coroutine then has a chance to clean up or even deny
        the request using try/except/finally.

        Unlike Future.cancel, this does not guarantee that the
        task will be cancelled: the exception might be caught and
        acted upon, delaying cancellation of the task or preventing
        cancellation completely.  The task may also return a value or
        raise a different exception.

        Immediately after this method is called, Task.cancelled() will
        not return True (unless the task was already cancelled).  A
        task will be marked as cancelled when the wrapped coroutine
        terminates with a CancelledError exception (even if cancel()
        was not called).

        This also increases the task's count of cancellation requests.
        F   N)   	   )r   T)	_log_tracebackdoner   _fut_waitersysversion_infocancel_must_cancel_cancel_message)r   r   r   r   r   r      s   



zTask.cancelc                 C   s   | j S )zReturn the count of the task's cancellation requests.

        This count is incremented when .cancel() is called
        and may be decremented using .uncancel().
        r   r   r   r   r   
cancellingL   s   zTask.cancellingc                 C   s   | j dkr|  j d8  _ | j S )zDecrement the task's count of cancellation requests.

        This should be called by the party that called `cancel()` on the task
        beforehand.

        Returns the remaining number of cancellation requests.
        r   r   r"   r#   r   r   r   uncancelT   s   
zTask.uncancel)N)__name__
__module____qualname____doc__r   r   r   r   r   strr   boolr   intr$   r%   __classcell__r   r   r   r   r      s     /r   )r)   asyncio.tasksasyncior   r   typingr   r   r   r   r   tasks_PyTaskr   r   r   r   r   <module>   s    