U
    gy%                     @  s  U d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZ d dlmZmZmZmZmZmZmZmZmZ ejd	krd d
lmZmZ nd d
lmZmZ ejdkrd dlmZ nd dlmZ ertd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* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 edZ:edZ;ee<e=ddf Z>de?d< G dd dedZ@dS )     )annotationsN)ABCMetaabstractmethod)AsyncIterator	Awaitable)PathLike)Signals)AddressFamily
SocketKindsocket)	IOTYPE_CHECKINGAnyCallableContextManagerSequenceTypeVarUnionoverload)      )TypeVarTupleUnpack)r   
   )	TypeAlias   )CapacityLimiterEventLock	Semaphore)CancelScope)TaskInfo)BlockingPortal   )ConnectedUDPSocketConnectedUNIXDatagramSocketIPSockAddrTypeSocketListenerSocketStream	UDPSocketUNIXDatagramSocketUNIXSocketStream)Process)	TaskGroup)
TestRunnerT_RetvalPosArgsTzPathLike[str]zPathLike[bytes]r   StrOrBytesPathc                   @  s  e Zd ZeeddddddddZeedd	d
dZeedd	ddZeedd	ddZeedd	ddZ	edd	ddZ
edd	ddZeedddddZeeejdddddd d!d"Zeedd	d#d$Zeed%d	d&d'Zeed(d	d)d*Zeedd+d,d-d.Zeed/dd0d1d2dd3d4d5d6Zeedd7d8d9d:Zeedd;ddd<dd=d>d?Zeedd	d@dAZeedddddBdCdDZeed;ddddBdEdFZeedGd	dHdIZeedJdKdKdKdLdMdNdOdPZeedQddRdSdTZeeddUd1dVdWdXdYdZZeed[d\d]d^d_Zeed`dadbdcddZeed`dadbdedfZ eedgdVdVddhdidjdkZ!ee"d`ddldmdndoZ#ee"d`d[dpdmdqdoZ#eed`drdsdmdtdoZ#eedududududvdwdxdydzd1d1d{d|d}d~Z$eeddd1ddddZ%eed`ddbddZ&eed`ddbddZ'eed7d	ddZ(eedddddZ)eedd	ddZ*eedd	ddZ+eedd	ddZ,eedddddZ-d/S )AsyncBackendz1Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]]ztuple[Unpack[PosArgsT]]zdict[str, Any]r/   )funcargskwargsoptionsreturnc                 C  s   dS )a  
        Run the given coroutine function in an asynchronous event loop.

        The current thread must not be already running an event loop.

        :param func: a coroutine function
        :param args: positional arguments to ``func``
        :param kwargs: positional arguments to ``func``
        :param options: keyword arguments to call the backend ``run()`` implementation
            with
        :return: the return value of the coroutine function
        N )clsr3   r4   r5   r6   r8   r8   8/tmp/pip-unpacked-wheel-3u0cc9gf/anyio/abc/_eventloop.pyrun9   s    	zAsyncBackend.runobject)r7   c                 C  s   dS )z

        :return:
        Nr8   r9   r8   r8   r:   current_tokenO   s    zAsyncBackend.current_tokenfloatc                 C  s   dS )zz
        Return the current value of the event loop's internal clock.

        :return: the clock value (seconds)
        Nr8   r=   r8   r8   r:   current_timeW   s    zAsyncBackend.current_timeztype[BaseException]c                 C  s   dS )zFReturn the exception class that is raised in a task if it's cancelled.Nr8   r=   r8   r8   r:   cancelled_exception_class`   s    z&AsyncBackend.cancelled_exception_classNonec                   s   dS )z
        Check if the task has been cancelled, and allow rescheduling of other tasks.

        This is effectively the same as running :meth:`checkpoint_if_cancelled` and then
        :meth:`cancel_shielded_checkpoint`.
        Nr8   r=   r8   r8   r:   
checkpointe   s    zAsyncBackend.checkpointc                   s"   |   tj kr|  I dH  dS )z
        Check if the current task group has been cancelled.

        This will check if the task has been cancelled, but will not allow other tasks
        to be scheduled if not.

        N)current_effective_deadlinemathinfrC   r=   r8   r8   r:   checkpoint_if_cancelledo   s    	z$AsyncBackend.checkpoint_if_cancelledc              	     s,   | j dd | dI dH  W 5 Q R X dS )z
        Allow the rescheduling of other tasks.

        This will give other tasks the opportunity to run, but without checking if the
        current task group has been cancelled, unlike with :meth:`checkpoint`.

        T)shieldr   N)create_cancel_scopesleepr=   r8   r8   r:   cancel_shielded_checkpoint{   s    	z'AsyncBackend.cancel_shielded_checkpoint)delayr7   c                   s   dS )zt
        Pause the current task for the specified duration.

        :param delay: the duration, in seconds
        Nr8   )r9   rL   r8   r8   r:   rJ      s    zAsyncBackend.sleepF)deadlinerH   boolr    )rM   rH   r7   c                C  s   d S Nr8   )r9   rM   rH   r8   r8   r:   rI      s    z AsyncBackend.create_cancel_scopec                 C  s   dS )aQ  
        Return the nearest deadline among all the cancel scopes effective for the
        current task.

        :return:
            - a clock value from the event loop's internal clock
            - ``inf`` if there is no deadline in effect
            - ``-inf`` if the current scope has been cancelled
        :rtype: float
        Nr8   r=   r8   r8   r:   rD      s    z'AsyncBackend.current_effective_deadliner-   c                 C  s   d S rO   r8   r=   r8   r8   r:   create_task_group   s    zAsyncBackend.create_task_groupr   c                 C  s   d S rO   r8   r=   r8   r8   r:   create_event   s    zAsyncBackend.create_eventr   )fast_acquirer7   c                C  s   d S rO   r8   )r9   rR   r8   r8   r:   create_lock   s    zAsyncBackend.create_lockN)	max_valuerR   intz
int | Noner   )initial_valuerT   rR   r7   c                C  s   d S rO   r8   )r9   rV   rT   rR   r8   r8   r:   create_semaphore   s    	zAsyncBackend.create_semaphorer   )total_tokensr7   c                 C  s   d S rO   r8   )r9   rX   r8   r8   r:   create_capacity_limiter   s    z$AsyncBackend.create_capacity_limiterz&Callable[[Unpack[PosArgsT]], T_Retval]zCapacityLimiter | None)r3   r4   abandon_on_cancellimiterr7   c                   s   d S rO   r8   )r9   r3   r4   rZ   r[   r8   r8   r:   run_sync_in_worker_thread   s    	z&AsyncBackend.run_sync_in_worker_threadc                 C  s   d S rO   r8   r=   r8   r8   r:   check_cancelled   s    zAsyncBackend.check_cancelled)r3   r4   tokenr7   c                 C  s   d S rO   r8   r9   r3   r4   r^   r8   r8   r:   run_async_from_thread   s    z"AsyncBackend.run_async_from_threadc                 C  s   d S rO   r8   r_   r8   r8   r:   run_sync_from_thread   s    z!AsyncBackend.run_sync_from_threadr"   c                 C  s   d S rO   r8   r=   r8   r8   r:   create_blocking_portal   s    z#AsyncBackend.create_blocking_portalz)StrOrBytesPath | Sequence[StrOrBytesPath]zint | IO[Any] | Noner   r,   )commandstdinstdoutstderrr5   r7   c                  s   d S rO   r8   )r9   rc   rd   re   rf   r5   r8   r8   r:   open_process   s    zAsyncBackend.open_processzset[Process])workersr7   c                 C  s   d S rO   r8   )r9   rh   r8   r8   r:   #setup_process_pool_exit_at_shutdown   s    z0AsyncBackend.setup_process_pool_exit_at_shutdownstrzIPSockAddrType | Noner(   )hostportlocal_addressr7   c                   s   d S rO   r8   )r9   rk   rl   rm   r8   r8   r:   connect_tcp   s    zAsyncBackend.connect_tcpzstr | bytesr+   )pathr7   c                   s   d S rO   r8   )r9   ro   r8   r8   r:   connect_unix  s    zAsyncBackend.connect_unixr   r'   )sockr7   c                 C  s   d S rO   r8   r9   rq   r8   r8   r:   create_tcp_listener  s    z AsyncBackend.create_tcp_listenerc                 C  s   d S rO   r8   rr   r8   r8   r:   create_unix_listener  s    z!AsyncBackend.create_unix_listenerr	   zUDPSocket | ConnectedUDPSocket)familyrm   remote_address
reuse_portr7   c                   s   d S rO   r8   )r9   ru   rm   rv   rw   r8   r8   r:   create_udp_socket  s    	zAsyncBackend.create_udp_socketr*   )
raw_socketremote_pathr7   c                   s   d S rO   r8   r9   ry   rz   r8   r8   r:   create_unix_datagram_socket   s    z(AsyncBackend.create_unix_datagram_socketr%   c                   s   d S rO   r8   r{   r8   r8   r:   r|   &  s    zstr | bytes | Nonez0UNIXDatagramSocket | ConnectedUNIXDatagramSocketc                   s   d S rO   r8   r{   r8   r8   r:   r|   ,  s    r   )ru   typeprotoflagszbytes | str | Nonezstr | int | Nonezint | AddressFamilyzint | SocketKindz]list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]])rk   rl   ru   r}   r~   r   r7   c                  s   d S rO   r8   )r9   rk   rl   ru   r}   r~   r   r8   r8   r:   getaddrinfo3  s    zAsyncBackend.getaddrinfor&   ztuple[str, str])sockaddrr   r7   c                   s   d S rO   r8   )r9   r   r   r8   r8   r:   getnameinfoI  s    zAsyncBackend.getnameinfoc                   s   d S rO   r8   rr   r8   r8   r:   wait_socket_readableP  s    z!AsyncBackend.wait_socket_readablec                   s   d S rO   r8   rr   r8   r8   r:   wait_socket_writableU  s    z!AsyncBackend.wait_socket_writablec                 C  s   d S rO   r8   r=   r8   r8   r:   current_default_thread_limiterZ  s    z+AsyncBackend.current_default_thread_limiterr   z&ContextManager[AsyncIterator[Signals]])signalsr7   c                 G  s   d S rO   r8   )r9   r   r8   r8   r:   open_signal_receiver_  s    z!AsyncBackend.open_signal_receiverr!   c                 C  s   d S rO   r8   r=   r8   r8   r:   get_current_taskf  s    zAsyncBackend.get_current_taskzSequence[TaskInfo]c                 C  s   d S rO   r8   r=   r8   r8   r:   get_running_tasksk  s    zAsyncBackend.get_running_tasksc                   s   d S rO   r8   r=   r8   r8   r:   wait_all_tasks_blockedp  s    z#AsyncBackend.wait_all_tasks_blockedr.   )r6   r7   c                 C  s   d S rO   r8   )r9   r6   r8   r8   r:   create_test_runneru  s    zAsyncBackend.create_test_runner)FN)N)r   ).__name__
__module____qualname__classmethodr   r;   r>   r@   rA   rC   rG   rK   rJ   rE   rF   rI   rD   rP   rQ   rS   rW   rY   r\   r]   r`   ra   rb   rg   ri   rn   rp   rs   rt   rx   r   r|   r   r   r   r   r   r   r   r   r   r   r8   r8   r8   r:   r2   8   s   	  	 	" r2   )	metaclass)A
__future__r   rE   sysabcr   r   collections.abcr   r   osr   signalr   r   r	   r
   typingr   r   r   r   r   r   r   r   r   version_infor   r   Ztyping_extensionsr   Z_core._synchronizationr   r   r   r   Z_core._tasksr    Z_core._testingr!   Zfrom_threadr"   Z_socketsr$   r%   r&   r'   r(   r)   r*   r+   Z_subprocessesr,   Z_tasksr-   Z_testingr.   r/   r0   rj   bytesr1   __annotations__r2   r8   r8   r8   r:   <module>   s8    ,

(
