
    LMh                         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	 n# e
$ r Y nw xY wddlmZ  G d dej                  Zd	 Zd
 Zedefd            Zed             ZdS )zB
Helper functionality for interoperability with stdlib `logging`.
    N)contextmanager)IteratorListOptionalType   )tqdmc                   (     e Zd Zef fd	Zd Z xZS )_TqdmLoggingHandlerc                 V    t                                                       || _        d S N)super__init__
tqdm_class)selfr   	__class__s     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tqdm/contrib/logging.pyr   z_TqdmLoggingHandler.__init__   s&     	$    c                     	 |                      |          }| j                            || j                   |                                  d S # t
          t          f$ r   |                     |           Y d S xY w)N)file)formatr   writestreamflushKeyboardInterrupt
SystemExithandleError)r   recordmsgs      r   emitz_TqdmLoggingHandler.emit   s    	%++f%%CO!!#DK!888JJLLLLL!:. 	 	 		%V$$$$$$s   A
A (A9)__name__
__module____qualname__std_tqdmr   r    __classcell__)r   s   @r   r   r      sQ         % % % % % %% % % % % % %r   r   c                 t    t          | t          j                  o| j        t          j        t          j        hv S r   )
isinstanceloggingStreamHandlerr   sysstdoutstderr)handlers    r   _is_console_logging_handlerr.   #   s/    w 566 ;3:sz"::<r   c                 6    | D ]}t          |          r|c S d S r   r.   )handlersr-   s     r   (_get_first_found_console_logging_handlerr2   (   s9      &w// 	NNN	 r   c              #     K   | t           j        g} d | D             }	 | D ]g}t          |          }t          |j                  }|&|                    |j                   |j        |_        d |j        D             |gz   |_        hdV  t          | |          D ]\  }}||_        dS # t          | |          D ]\  }}||_        w xY w)a  
    Context manager redirecting console logging to `tqdm.write()`, leaving
    other logging handlers (e.g. log files) unaffected.

    Parameters
    ----------
    loggers  : list, optional
      Which handlers to redirect (default: [logging.root]).
    tqdm_class  : optional

    Example
    -------
    ```python
    import logging
    from tqdm import trange
    from tqdm.contrib.logging import logging_redirect_tqdm

    LOG = logging.getLogger(__name__)

    if __name__ == '__main__':
        logging.basicConfig(level=logging.INFO)
        with logging_redirect_tqdm():
            for i in trange(9):
                if i == 4:
                    LOG.info("console logging redirected to `tqdm.write()`")
        # logging restored
    ```
    Nc                     g | ]	}|j         
S  )r1   ).0loggers     r   
<listcomp>z)logging_redirect_tqdm.<locals>.<listcomp>R   s    DDD&foDDDr   c                 0    g | ]}t          |          |S r5   r0   )r6   r-   s     r   r8   z)logging_redirect_tqdm.<locals>.<listcomp>Z   s6     = = =#27;;== = =r   )	r(   rootr   r2   r1   setFormatter	formatterr   zip)loggersr   original_handlers_listr7   tqdm_handlerorig_handleroriginal_handlerss          r   logging_redirect_tqdmrC   .   s#     D <.DDGDDD0 	N 	NF.z::LCFOTTL')),*@AAA&2&9#= ='-= = =@L~NFOO 	),W6L)M)M 	0 	0%F%/FOO	0 	0W6L)M)M 	0 	0%F%/FOO	0s   A.B, ,Cc               /   0  K   |                                 }|                    dd          }|                    dt                    } || i |5 }t          ||          5  |V  ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )ap  
    Convenience shortcut for:
    ```python
    with tqdm_class(*args, **tqdm_kwargs) as pbar:
        with logging_redirect_tqdm(loggers=loggers, tqdm_class=tqdm_class):
            yield pbar
    ```

    Parameters
    ----------
    tqdm_class  : optional, (default: tqdm.std.tqdm).
    loggers  : optional, list.
    **tqdm_kwargs  : passed to `tqdm_class`.
    r>   Nr   )r>   r   )copypopr$   rC   )argskwargstqdm_kwargsr>   r   pbars         r   tqdm_logging_redirectrK   c   s"     , ++--Kooi..Gx88J	T	)[	)	) T"7zJJJ 	 	JJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s6   B"A3'B3A7	7B:A7	;BBB)__doc__r(   r*   
contextlibr   typingr   r   r   r   ImportErrorstdr	   r$   r)   r   r.   r2   rC   rK   r5   r   r   <module>rQ      s,     



 % % % % % %	5555555555555 	 	 	D	 # " " " " "% % % % %'/ % % %&< < <
   10 10 10 10h     s    ''