
    F2j                        d dl mZ d dlZd dlZd dlmZ ej        rd dlmZ ddl	m
Z  G d d          Z G d	 d
          ZdS )    )annotationsN)timeout)socket   )AsyncSocketc                  .    e Zd ZdZdZddZddZddZdS )
SubTimeouta{  Context manager that temporarily lowers a socket's timeout to honor
    a secondary deadline (e.g. a QUIC state-machine timer).

    When the secondary deadline expires before the primary timeout, the
    *on_timer* callback is invoked and the ``SocketTimeout`` exception is
    suppressed.  The caller can inspect :attr:`timer_fired` after the
    ``with`` block to decide whether to retry the I/O operation.

    When *next_timer* is ``None`` or falls after the primary timeout the
    context manager is a lightweight no-op, the original socket timeout
    is left untouched and any ``SocketTimeout`` raised inside the block
    propagates as a regular user timeout.

    Usage::

        sub = SubTimeout(sock, protocol.next_timer(), send_pending)
        with sub:
            data = sock.recv(blocksize)
        if sub.timer_fired:
            continue  # timer was handled, retry
    sock
next_timeron_timertimer_fired_original_timeout	_adjustedr   _sync_socketr   float | Noner   typing.Callable[[], None]returnNonec                Z    || _         || _        || _        d| _        d | _        d| _        d S NFr
   selfr   r   r   s       `/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/urllib3/util/sub_timeout.py__init__zSubTimeout.__init__-   4     	$ !&/3$    c                   | j                                         | _        | j        ^| j        t	          j                    z
  }t          |d          }| j        || j        k     r!| j                             |           d| _        | S Ngư>Tr   
gettimeoutr   r   timemax
settimeoutr   r   time_to_timers     r   	__enter__zSubTimeout.__enter__:   s}    !%!5!5!7!7?& Odikk9M
  t44M%-AW1W1W	$$]333!% r   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tb
typing.Anyboolc                    | j         r| j                            | j                   |t          u r$| j         rd| _        |                                  dS dS NTFr   r   r$   r   SocketTimeoutr   r   r   r(   r*   r,   s       r   __exit__zSubTimeout.__exit__O   sX     > 	9I  !7888}$$$#DMMOOO4ur   N)r   r   r   r   r   r   r   r   )r   r	   r(   r)   r*   r+   r,   r-   r   r.   )__name__
__module____qualname____doc__	__slots__r   r'   r4    r   r   r	   r	      sa         ,I% % % %   *     r   r	   c                  .    e Zd ZdZdZddZddZddZdS )AsyncSubTimeoutz)Async counterpart of :class:`SubTimeout`.r
   r   _async_socketr   r   r   +typing.Callable[[], typing.Awaitable[None]]r   r   c                Z    || _         || _        || _        d| _        d | _        d| _        d S r   r
   r   s       r   r   zAsyncSubTimeout.__init__l   r   r   c                  K   | j                                         | _        | j        ^| j        t	          j                    z
  }t          |d          }| j        || j        k     r!| j                             |           d| _        | S r   r    r%   s     r   
__aenter__zAsyncSubTimeout.__aenter__y   s}      !%!5!5!7!7?& Odikk9Mt44M%-AW1W1W	$$]333!%r   r(   r)   r*   r+   r,   r-   r.   c                   K   | j         r| j                            | j                   |t          u r*| j         r#d| _        |                                  d {V  dS dS r0   r1   r3   s       r   	__aexit__zAsyncSubTimeout.__aexit__   so       > 	9I  !7888}$$$#D--//!!!!!!!4ur   N)r   r>   r   r   r   r?   r   r   )r   r=   r5   )r6   r7   r8   r9   r:   r   rB   rD   r;   r   r   r=   r=   `   s]        33I% % % %        r   r=   )
__future__r   r"   typingr   r   r2   TYPE_CHECKINGr   contrib.ssar   r>   r	   r=   r;   r   r   <module>rI      s    " " " " " "   + + + + + +	 ;------::::::P P P P P P P Pf4 4 4 4 4 4 4 4 4 4r   