o
    pi5                     @  s  U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZ ddlmZ ddlmZ e	d	Ze	d
Zd"ddZd"ddZd"ddZe
edddG dd dZd#ddZe Zded< G dd dejZG dd dee ZG d d! d!ee ZdS )$    )annotationsN)	dataclass)AnyGenericLiteralTypeVarfinaloverload)WeakKeyDictionary   )get_async_backend)AsyncBackendTDreturnNonec                        t   I dH  dS )z
    Check for cancellation and allow the scheduler to switch to another task.

    Equivalent to (but more efficient than)::

        await checkpoint_if_cancelled()
        await cancel_shielded_checkpoint()


    .. versionadded:: 3.0

    N)r   
checkpoint r   r   U/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/anyio/lowlevel.pyr         r   c                     r   )z
    Enter a checkpoint if the enclosing cancel scope has been cancelled.

    This does not allow the scheduler to switch to a different task.

    .. versionadded:: 3.0

    N)r   checkpoint_if_cancelledr   r   r   r   r      s   	r   c                     r   )z
    Allow the scheduler to switch to another task but without checking for cancellation.

    Equivalent to (but potentially more efficient than)::

        with CancelScope(shield=True):
            await checkpoint()


    .. versionadded:: 3.0

    N)r   cancel_shielded_checkpointr   r   r   r   r   +   r   r   TF)frozenreprc                   @  s"   e Zd ZU dZded< ded< dS )EventLoopTokenza
    An opaque object that holds a reference to an event loop.

    .. versionadded:: 4.11.0
    ztype[AsyncBackend]backend_classobjectnative_tokenN)__name__
__module____qualname____doc____annotations__r   r   r   r   r   ;   s   
 r   c                  C  s   t  } |  }t| |S )z
    Return a token object that can be used to call code in the current event loop from
    another thread.

    .. versionadded:: 4.11.0

    )r   current_tokenr   )r   Z	raw_tokenr   r   r   r$   H   s   
r$   z1WeakKeyDictionary[object, dict[RunVar[Any], Any]]	_run_varsc                   @  s   e Zd Ze ZdS )_NoValueSetN)r   r    r!   enumautoNO_VALUE_SETr   r   r   r   r&   X   s    r&   c                   @  s   e Zd ZdZd	ddZdS )
RunvarToken_var_value	_redeemedvar	RunVar[T]value%T | Literal[_NoValueSet.NO_VALUE_SET]c                 C  s   || _ || _d| _d S )NFr+   )selfr/   r1   r   r   r   __init___   s   
zRunvarToken.__init__N)r/   r0   r1   r2   )r   r    r!   	__slots__r4   r   r   r   r   r*   \   s    r*   c                   @  s   e Zd ZU dZdZejZded< efd"d	d
Ze	d#ddZ
ed$ddZed%ddZefd&ddZd'ddZd(ddZd)dd Zd!S )*RunVarz[
    Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop.
    _name_defaultz!Literal[_NoValueSet.NO_VALUE_SET]r)   namestrdefaultr2   c                 C  s   || _ || _d S Nr7   )r3   r:   r<   r   r   r   r4   n   s   
zRunVar.__init__r   dict[RunVar[T], T]c                 C  s6   t  j}zt| W S  ty   i  }t|< | Y S w r=   )r$   r   r%   KeyError)r3   r   Zrun_varsr   r   r   _current_varst   s   
zRunVar._current_varsr   T | Dc                 C     d S r=   r   r3   r<   r   r   r   get}      z
RunVar.getr   c                 C  rB   r=   r   r3   r   r   r   rD      rE   %D | Literal[_NoValueSet.NO_VALUE_SET]c                 C  sZ   z| j |  W S  ty#   |tjur| Y S | jtjur!| j Y S Y nw td| j d)NzRun variable "z!" has no value and no default set)r@   r?   r6   r)   r9   LookupErrorr8   rC   r   r   r   rD      s   

r1   RunvarToken[T]c                 C  s&   | j }t| || tj}||| < |S r=   )r@   r*   rD   r6   r)   )r3   r1   Zcurrent_varstokenr   r   r   set   s   z
RunVar.setrJ   r   c                 C  sb   |j | ur	td|jrtd|jtju r&z| j| = W n ty%   Y nw |j| j| < d|_d S )Nz)This token does not belong to this RunVarz This token has already been usedT)r,   
ValueErrorr.   r-   r&   r)   r@   r?   )r3   rJ   r   r   r   reset   s   

zRunVar.resetc                 C  s   d| j dS )Nz<RunVar name=>)r8   rF   r   r   r   __repr__   s   zRunVar.__repr__N)r:   r;   r<   r2   )r   r>   )r<   r   r   rA   )r   r   )r<   rG   r   rA   )r1   r   r   rI   )rJ   rI   r   r   )r   r;   )r   r    r!   r"   r5   r&   r)   r#   r4   propertyr@   r	   rD   rK   rM   rO   r   r   r   r   r6   e   s"   
 

r6   )r   r   )r   r   )
__future__r   r'   dataclassesr   typingr   r   r   r   r   r	   weakrefr
   Z_core._eventloopr   abcr   r   r   r   r   r   r   r$   r%   r#   Enumr&   r*   r6   r   r   r   r   <module>   s(     




	