o
    í6Wj¹)  ã                   @  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	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 d d	lmZmZmZmZmZmZ ejd
kr_d dlmZmZ nd dl mZmZ er­d dl!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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: edƒZ;eddd�Z<edƒZ=e>e?B ee> B ee? B Z@deAd< G dd„ ded�ZBdS ) é    )ÚannotationsN)ÚABCMetaÚabstractmethod)ÚAsyncIteratorÚ	AwaitableÚCallableÚ	CoroutineÚSequence)ÚAbstractContextManager)ÚPathLike)ÚSignals)ÚAddressFamilyÚ
SocketKindÚsocket)ÚIOÚTYPE_CHECKINGÚAnyÚ	TypeAliasÚTypeVarÚoverload)é   é   )ÚTypeVarTupleÚUnpack)ÚFileDescriptorLikeé   )ÚCapacityLimiterÚEventÚLockÚ	Semaphore)ÚCancelScope)ÚTaskInfoé   )ÚConnectedUDPSocketÚConnectedUNIXDatagramSocketÚIPSockAddrTypeÚSocketListenerÚSocketStreamÚ	UDPSocketÚUNIXDatagramSocketÚUNIXSocketStream)ÚProcess)Ú	TaskGroup)Ú
TestRunnerÚT_RetvalÚT_coT)Ú	covariantÚPosArgsTr   ÚStrOrBytesPathc                   @  s~  e Zd Zeed½d
d„ƒƒZeed¾dd„ƒƒZeed¿dd„ƒƒZeedÀdd„ƒƒZeedÁdd„ƒƒZ	edÁdd„ƒZ
edÁdd„ƒZeedÂdd„ƒƒZeeejdd œdÃd%d&„ƒƒZeed¿d'd(„ƒƒZeedÄd*d+„ƒƒZeedÅd-d.„ƒƒZeedÆd1d2„ƒƒZeed3dd4œdÇd:d;„ƒƒZeedÈd>d?„ƒƒZee		3dÉdÊdDdE„ƒƒZeedÁdFdG„ƒƒZeedËdKdL„ƒƒZeedÌdMdN„ƒƒZeedÍdWdX„ƒƒZeedÎd[d\„ƒƒZee	3dÏdÐdcdd„ƒƒZeedÑdhdi„ƒƒZeedÒdmdn„ƒƒZeedÒdodp„ƒƒZeedÓdvdw„ƒƒZ ee!dÔd{d|„ƒƒZ"ee!dÕd~d|„ƒƒZ"eedÖd�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–„ƒƒZ%eedÚd—d˜„ƒƒZ&eedÚd™dš„ƒƒZ'eedÒd›dœ„ƒƒZ(eedÛd�dž„ƒƒZ)eedÜdŸd „ƒƒZ*eedÝd¢d£„ƒƒZ+eedÞd¥d¦„ƒƒZ,eedßd§d¨„ƒƒZ-eedàd©dª„ƒƒZ.eedád«d¬„ƒƒZ/eedâd°d±„ƒƒZ0eedãd³d´„ƒƒZ1eedäd¶d·„ƒƒZ2eedÁd¸d¹„ƒƒZ3eedåd»d¼„ƒƒZ4d3S )æÚAsyncBackendÚfuncú1Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]]Úargsútuple[Unpack[PosArgsT]]Úkwargsúdict[str, Any]ÚoptionsÚreturnr.   c                 C  ó   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© )Úclsr4   r6   r8   r:   r=   r=   úc/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/anyio/abc/_eventloop.pyÚrun4   ó    zAsyncBackend.runÚobjectc                 C  r<   )zÆ
        Return an object that allows other threads to run code inside the event loop.

        :return: a token object, specific to the event loop running in the current
            thread
        Nr=   ©r>   r=   r=   r?   Úcurrent_tokenJ   rA   zAsyncBackend.current_tokenÚfloatc                 C  r<   )zz
        Return the current value of the event loop's internal clock.

        :return: the clock value (seconds)
        Nr=   rC   r=   r=   r?   Úcurrent_timeT   rA   zAsyncBackend.current_timeútype[BaseException]c                 C  r<   )zFReturn the exception class that is raised in a task if it's cancelled.Nr=   rC   r=   r=   r?   Úcancelled_exception_class]   rA   z&AsyncBackend.cancelled_exception_classÚNonec                 Ã  ó   �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`.
        Nr=   rC   r=   r=   r?   Ú
checkpointb   ó    zAsyncBackend.checkpointc                 Ã  s(   �|   ¡ tj kr|  ¡ I dH  dS 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ÚinfrK   rC   r=   r=   r?   Úcheckpoint_if_cancelledl   s   €	ÿz$AsyncBackend.checkpoint_if_cancelledc                 Ã  sD   �| j dd�� |  d¡I dH  W d  ƒ dS 1 sw   Y  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ÚsleeprC   r=   r=   r?   Úcancel_shielded_checkpointx   s   €	"ÿz'AsyncBackend.cancel_shielded_checkpointÚdelayc                 Ã  rJ   )zt
        Pause the current task for the specified duration.

        :param delay: the duration, in seconds
        Nr=   )r>   rU   r=   r=   r?   rS   „   rL   zAsyncBackend.sleepF)ÚdeadlinerQ   rV   rQ   Úboolr    c                C  ó   d S ©Nr=   )r>   rV   rQ   r=   r=   r?   rR   �   ó   z AsyncBackend.create_cancel_scopec                 C  r<   )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
        Nr=   rC   r=   r=   r?   rM   ”   rA   z'AsyncBackend.current_effective_deadliner,   c                 C  rX   rY   r=   rC   r=   r=   r?   Úcreate_task_group¢   ó   zAsyncBackend.create_task_groupr   c                 C  rX   rY   r=   rC   r=   r=   r?   Úcreate_event§   r\   zAsyncBackend.create_eventÚfast_acquirer   c                C  rX   rY   r=   )r>   r^   r=   r=   r?   Úcreate_lock¬   r\   zAsyncBackend.create_lockN)Ú	max_valuer^   Úinitial_valueÚintr`   ú
int | Noner   c                C  rX   rY   r=   )r>   ra   r`   r^   r=   r=   r?   Úcreate_semaphore±   s   	zAsyncBackend.create_semaphoreÚtotal_tokensr   c                 C  rX   rY   r=   )r>   re   r=   r=   r?   Úcreate_capacity_limiter¼   r\   z$AsyncBackend.create_capacity_limiterú&Callable[[Unpack[PosArgsT]], T_Retval]Úabandon_on_cancelÚlimiterúCapacityLimiter | Nonec                 Ã  ó   �d S rY   r=   )r>   r4   r6   rh   ri   r=   r=   r?   Úrun_sync_in_worker_threadÁ   ó   €	z&AsyncBackend.run_sync_in_worker_threadc                 C  rX   rY   r=   rC   r=   r=   r?   Úcheck_cancelledÌ   r\   zAsyncBackend.check_cancelledú7Callable[[Unpack[PosArgsT]], Coroutine[Any, Any, T_co]]Útokenr/   c                 C  rX   rY   r=   ©r>   r4   r6   rp   r=   r=   r?   Úrun_async_from_threadÑ   ó   z"AsyncBackend.run_async_from_threadc                 C  rX   rY   r=   rq   r=   r=   r?   Úrun_sync_from_threadÛ   rs   z!AsyncBackend.run_sync_from_threadÚcommandú)StrOrBytesPath | Sequence[StrOrBytesPath]Ústdinúint | IO[Any] | NoneÚstdoutÚstderrr   r+   c                Ë  rk   rY   r=   )r>   ru   rw   ry   rz   r8   r=   r=   r?   Úopen_processå   s   €zAsyncBackend.open_processÚworkersúset[Process]c                 C  rX   rY   r=   )r>   r|   r=   r=   r?   Ú#setup_process_pool_exit_at_shutdownò   r\   z0AsyncBackend.setup_process_pool_exit_at_shutdownÚhostÚstrÚportÚlocal_addressúIPSockAddrType | Noner'   c                 Ã  rk   rY   r=   )r>   r   r�   r‚   r=   r=   r?   Úconnect_tcp÷   ó   €zAsyncBackend.connect_tcpÚpathústr | bytesr*   c                 Ã  rk   rY   r=   )r>   r†   r=   r=   r?   Úconnect_unixþ   ó   €zAsyncBackend.connect_unixÚsockr   r&   c                 C  rX   rY   r=   ©r>   rŠ   r=   r=   r?   Úcreate_tcp_listener  r\   z AsyncBackend.create_tcp_listenerc                 C  rX   rY   r=   r‹   r=   r=   r?   Úcreate_unix_listener  r\   z!AsyncBackend.create_unix_listenerÚfamilyr   Úremote_addressÚ
reuse_portúUDPSocket | ConnectedUDPSocketc                 Ã  rk   rY   r=   )r>   rŽ   r‚   r�   r�   r=   r=   r?   Úcreate_udp_socket  rm   zAsyncBackend.create_udp_socketÚ
raw_socketÚremote_pathr)   c                 Ã  rk   rY   r=   ©r>   r“   r”   r=   r=   r?   Úcreate_unix_datagram_socket  ó   €z(AsyncBackend.create_unix_datagram_socketr$   c                 Ã  rk   rY   r=   r•   r=   r=   r?   r–     r—   ústr | bytes | Noneú0UNIXDatagramSocket | ConnectedUNIXDatagramSocketc                 Ã  rk   rY   r=   r•   r=   r=   r?   r–   $  r…   r   )rŽ   ÚtypeÚprotoÚflagsúbytes | str | Noneústr | int | Noneúint | AddressFamilyrš   úint | SocketKindr›   rœ   úuSequence[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]c                Ã  rk   rY   r=   )r>   r   r�   rŽ   rš   r›   rœ   r=   r=   r?   Úgetaddrinfo+  s   €zAsyncBackend.getaddrinfoÚsockaddrr%   útuple[str, str]c                 Ã  rk   rY   r=   )r>   r£   rœ   r=   r=   r?   ÚgetnameinfoA  r…   zAsyncBackend.getnameinfoÚobjr   c                 Ã  rk   rY   r=   ©r>   r¦   r=   r=   r?   Úwait_readableH  r‰   zAsyncBackend.wait_readablec                 Ã  rk   rY   r=   r§   r=   r=   r?   Úwait_writableM  r‰   zAsyncBackend.wait_writablec                 C  rX   rY   r=   r§   r=   r=   r?   Únotify_closingR  r\   zAsyncBackend.notify_closingc                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_listener_socketW  r‰   z!AsyncBackend.wrap_listener_socketc                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_stream_socket\  r‰   zAsyncBackend.wrap_stream_socketc                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_unix_stream_socketa  r‰   z$AsyncBackend.wrap_unix_stream_socketr(   c                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_udp_socketf  r‰   zAsyncBackend.wrap_udp_socketr#   c                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_connected_udp_socketk  r‰   z&AsyncBackend.wrap_connected_udp_socketc                 Ã  rk   rY   r=   r‹   r=   r=   r?   Úwrap_unix_datagram_socketp  r‰   z&AsyncBackend.wrap_unix_datagram_socketc                 Ã  rk   rY   r=   r‹   r=   r=   r?   Ú#wrap_connected_unix_datagram_socketu  r…   z0AsyncBackend.wrap_connected_unix_datagram_socketc                 C  rX   rY   r=   rC   r=   r=   r?   Úcurrent_default_thread_limiter|  r\   z+AsyncBackend.current_default_thread_limiterÚsignalsr   ú.AbstractContextManager[AsyncIterator[Signals]]c                 G  rX   rY   r=   )r>   r³   r=   r=   r?   Úopen_signal_receiver�  rZ   z!AsyncBackend.open_signal_receiverr!   c                 C  rX   rY   r=   rC   r=   r=   r?   Úget_current_taskˆ  r\   zAsyncBackend.get_current_taskúSequence[TaskInfo]c                 C  rX   rY   r=   rC   r=   r=   r?   Úget_running_tasks�  r\   zAsyncBackend.get_running_tasksc                 Ã  rk   rY   r=   rC   r=   r=   r?   Úwait_all_tasks_blocked’  r‰   z#AsyncBackend.wait_all_tasks_blockedr-   c                 C  rX   rY   r=   )r>   r:   r=   r=   r?   Úcreate_test_runner—  r\   zAsyncBackend.create_test_runner)
r4   r5   r6   r7   r8   r9   r:   r9   r;   r.   )r;   rB   )r;   rE   )r;   rG   )r;   rI   )rU   rE   r;   rI   )rV   rE   rQ   rW   r;   r    )r;   r,   )r;   r   )r^   rW   r;   r   )ra   rb   r`   rc   r^   rW   r;   r   )re   rE   r;   r   )FN)
r4   rg   r6   r7   rh   rW   ri   rj   r;   r.   )r4   ro   r6   r7   rp   rB   r;   r/   )r4   rg   r6   r7   rp   rB   r;   r.   )ru   rv   rw   rx   ry   rx   rz   rx   r8   r   r;   r+   )r|   r}   r;   rI   rY   )r   r€   r�   rb   r‚   rƒ   r;   r'   )r†   r‡   r;   r*   )rŠ   r   r;   r&   )
rŽ   r   r‚   rƒ   r�   rƒ   r�   rW   r;   r‘   )r“   r   r”   rI   r;   r)   )r“   r   r”   r‡   r;   r$   )r“   r   r”   r˜   r;   r™   )r   r�   r�   rž   rŽ   rŸ   rš   r    r›   rb   rœ   rb   r;   r¡   )r   )r£   r%   rœ   rb   r;   r¤   )r¦   r   r;   rI   )rŠ   r   r;   r'   )rŠ   r   r;   r*   )rŠ   r   r;   r(   )rŠ   r   r;   r#   )rŠ   r   r;   r)   )rŠ   r   r;   r$   )r;   r   )r³   r   r;   r´   )r;   r!   )r;   r·   )r:   r9   r;   r-   )5Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r@   rD   rF   rH   rK   rP   rT   rS   rN   rO   rR   rM   r[   r]   r_   rd   rf   rl   rn   rr   rt   r{   r~   r„   rˆ   rŒ   r�   r’   r   r–   r¢   r¥   r¨   r©   rª   r«   r¬   r­   r®   r¯   r°   r±   r²   rµ   r¶   r¸   r¹   rº   r=   r=   r=   r?   r3   3   s.   ÿû	û	ÿ	øÿr3   )Ú	metaclass)CÚ
__future__r   rN   ÚsysÚabcr   r   Úcollections.abcr   r   r   r   r	   Ú
contextlibr
   Úosr   Úsignalr   r   r   r   Útypingr   r   r   r   r   r   Úversion_infor   r   Útyping_extensionsÚ	_typeshedr   Ú_core._synchronizationr   r   r   r   Ú_core._tasksr    Ú_core._testingr!   Ú_socketsr#   r$   r%   r&   r'   r(   r)   r*   Ú_subprocessesr+   Ú_tasksr,   Ú_testingr-   r.   r/   r1   r€   Úbytesr2   Ú__annotations__r3   r=   r=   r=   r?   Ú<module>   s6     
	(
 