HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/.local/lib/python3.10/site-packages/tqdm/contrib/__pycache__/logging.cpython-310.pyc
o

���g��@s�dZddlZddlZddlmZzddlmZmZmZm	Z	Wn	e
y'YnwddlmZ
Gdd�dej�Zd	d
�Zdd�Zede
fd
d��Zedd��ZdS)zB
Helper functionality for interoperability with stdlib `logging`.
�N)�contextmanager)�Iterator�List�Optional�Type�)�tqdmcs(eZdZef�fdd�	Zdd�Z�ZS)�_TqdmLoggingHandlercst���||_dS�N)�super�__init__�
tqdm_class)�selfr
��	__class__��G/home/arjun/.local/lib/python3.10/site-packages/tqdm/contrib/logging.pyrs

z_TqdmLoggingHandler.__init__c	CsTz|�|�}|jj||jd�|��WdSttfy�|�|�YdS)N)�file)�formatr
�write�stream�flush�KeyboardInterrupt�
SystemExit�handleError)r�record�msgrrr�emits
z_TqdmLoggingHandler.emit)�__name__�
__module__�__qualname__�std_tqdmrr�
__classcell__rrrrr	s�r	cCst|tj�o|jtjtjhvSr
)�
isinstance�logging�
StreamHandlerr�sys�stdout�stderr)�handlerrrr�_is_console_logging_handler#s�r*cCs|D]
}t|�r|SqdSr
�r*)�handlersr)rrr�(_get_first_found_console_logging_handler(s
��r-c	cs��|dur	tjg}dd�|D�}z;|D]%}t|�}t|j�}|dur,|�|j�|j|_dd�|jD�|g|_qdVWt||�D]\}}||_qBdSt||�D]\}}||_qQw)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
    ```
    NcSsg|]}|j�qSr)r,)�.0�loggerrrr�
<listcomp>Rsz)logging_redirect_tqdm.<locals>.<listcomp>cSsg|]}t|�s|�qSrr+)r.r)rrrr0Zs��)	r$�rootr	r-r,�setFormatter�	formatterr�zip)�loggersr
�original_handlers_listr/�tqdm_handler�orig_handler�original_handlersrrr�logging_redirect_tqdm.s,�"
����r:c	os��|��}|�dd�}|�dt�}||i|���*}t||d��|VWd�n1s-wYWd�dSWd�dS1sEwYdS)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`.
    r5Nr
)r5r
)�copy�popr!r:)�args�kwargs�tqdm_kwargsr5r
�pbarrrr�tqdm_logging_redirectcs���"�rA)�__doc__r$r&�
contextlibr�typingrrrr�ImportError�stdrr!r%r	r*r-r:rArrrr�<module>s&��4