Ë
    -Œ:j&4  ã                   ó$  — U d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ i Zeeef   ed
<    G d„ d«      Zd'dedz  ddfd„Zd'dedz  defd„Zdededz  fd„Z G d„ de«      Zej=                   ej>                  «       «        G d„ d«      Z e	deez  deejB                     fd„«       Z"ddœde#e   dededz  defd„Z$ddddddddœdeded edz  d!ed"ed#ededz  d$e#e   dz  d%edz  dee   fd&„Z%y)(u	  Utility helpers to handle progress bars in `huggingface_hub`.

Example:
    1. Use `huggingface_hub.utils.tqdm` as you would use `tqdm.tqdm` or `tqdm.auto.tqdm`.
    2. To disable progress bars, either use `disable_progress_bars()` helper or set the
       environment variable `HF_HUB_DISABLE_PROGRESS_BARS` to 1.
    3. To re-enable progress bars, use `enable_progress_bars()`.
    4. To check whether progress bars are disabled, use `are_progress_bars_disabled()`.

NOTE: Environment variable `HF_HUB_DISABLE_PROGRESS_BARS` has the priority.

Example:
    ```py
    >>> from huggingface_hub.utils import are_progress_bars_disabled, disable_progress_bars, enable_progress_bars, tqdm

    # Disable progress bars globally
    >>> disable_progress_bars()

    # Use as normal `tqdm`
    >>> for _ in tqdm(range(5)):
    ...    pass

    # Still not showing progress bars, as `disable=False` is overwritten to `True`.
    >>> for _ in tqdm(range(5), disable=False):
    ...    pass

    >>> are_progress_bars_disabled()
    True

    # Re-enable progress bars globally
    >>> enable_progress_bars()

    # Progress bar will be shown !
    >>> for _ in tqdm(range(5)):
    ...   pass
    100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 5/5 [00:00<00:00, 117817.53it/s]
    ```

Group-based control:
    ```python
    # Disable progress bars for a specific group
    >>> disable_progress_bars("peft.foo")

    # Check state of different groups
    >>> assert not are_progress_bars_disabled("peft"))
    >>> assert not are_progress_bars_disabled("peft.something")
    >>> assert are_progress_bars_disabled("peft.foo"))
    >>> assert are_progress_bars_disabled("peft.foo.bar"))

    # Enable progress bars for a subgroup
    >>> enable_progress_bars("peft.foo.bar")

    # Check if enabling a subgroup affects the parent group
    >>> assert are_progress_bars_disabled("peft.foo"))
    >>> assert not are_progress_bars_disabled("peft.foo.bar"))

    # No progress bar for `name="peft.foo"`
    >>> for _ in tqdm(range(5), name="peft.foo"):
    ...     pass

    # Progress bar will be shown for `name="peft.foo.bar"`
    >>> for _ in tqdm(range(5), name="peft.foo.bar"):
    ...     pass
    100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 5/5 [00:00<00:00, 117817.53it/s]

    ```
é    N)ÚIterator)ÚcontextmanagerÚnullcontext)ÚPath)ÚContextManager)Útqdmé   )ÚHF_HUB_DISABLE_PROGRESS_BARSÚprogress_bar_statesc                   ó8   — e Zd ZdZddedz  ddfd„Zd	d„Zd
d„Zy)Údisable_progress_barsa&  
    Disable progress bars either globally or for a specified group.

    This function updates the state of progress bars based on a group name.
    If no group name is provided, all progress bars are disabled. The operation
    respects the `HF_HUB_DISABLE_PROGRESS_BARS` environment variable's setting.

    Works as both a regular call and a context manager:
        disable_progress_bars()           # disables until enable_progress_bars()
        with disable_progress_bars():     # disables for the block, re-enables on exit
            ...

    Args:
        name (`str`, *optional*):
            The name of the group for which to disable the progress bars. If None,
            progress bars are disabled globally.

    Raises:
        Warning: If the environment variable precludes changes.
    NÚnameÚreturnc                 óF  — || _         t        du rt        j                  d«       d| _        y t        |«       | _        |€t        j                  «        dt        d<   y t        D �cg c]  }|j                  |› d�«      sŒ|‘Œ }}|D ]	  }t        |= Œ dt        |<   y c c}w )NFzlCannot disable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=0` is set and has priority.Ú_globalú.)	r   r
   ÚwarningsÚwarnÚ_should_reenableÚare_progress_bars_disabledr   ÚclearÚ
startswith)Úselfr   ÚkeyÚkeys_to_removes       ú\/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/utils/tqdm.pyÚ__init__zdisable_progress_bars.__init__‚   s©   € ØˆŒ	ä'¨5Ñ0Ü�M‰MØ~ôð %*ˆDÔ!Øä$>¸tÓ$DÐ DˆÔØˆ<Ü×%Ñ%Ô'Ø-2Ô 	Ò*ä-@Ö_ cÀCÇNÁNÐVZÐU[Ð[\ÐS]ÕD^šcÐ_ˆNÐ_Ø%ò -�Ü'¨Ñ,ð-à(-Ô Ò%ùò `s   Á&BÂ Bc                 ó   — | S ©N© ©r   s    r   Ú	__enter__zdisable_progress_bars.__enter__–   ó   € Øˆó    c                 óH   — | j                   rt        | j                  «       y y r   )r   Úenable_progress_barsr   )r   Úexcs     r   Ú__exit__zdisable_progress_bars.__exit__™   s   € Ø× Ò Ü  §¡Õ+ð !r$   r   )r   r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r"   r(   r    r$   r   r   r   l   s(   „ ññ*.˜S 4™Zð .°4ó .ó(ô,r$   r   r   r   c                 ó  — t         du rt        j                  d«       y| €t        j	                  «        dt        d<   yt        D �cg c]  }|j                  | › d�«      sŒ|‘Œ }}|D ]	  }t        |= Œ dt        | <   yc c}w )a  
    Enable progress bars either globally or for a specified group.

    This function sets the progress bars to enabled for the specified group or globally
    if no group is specified. The operation is subject to the `HF_HUB_DISABLE_PROGRESS_BARS`
    environment setting.

    Args:
        name (`str`, *optional*):
            The name of the group for which to enable the progress bars. If None,
            progress bars are enabled globally.

    Raises:
        Warning: If the environment variable precludes changes.
    TzkCannot enable progress bars: environment variable `HF_HUB_DISABLE_PROGRESS_BARS=1` is set and has priority.Nr   r   )r
   r   r   r   r   r   )r   r   r   s      r   r&   r&   ž   s‹   € ô  $ tÑ+Ü�‰Øyô	
ð 	à€|Ü×!Ñ!Ô#Ø)-Ô˜IÒ&ä)<Ö[ #ÀÇÁÐRVÐQWÐWXÈzÕ@Zš#Ð[ˆÐ[Ø!ò 	)ˆCÜ# CÑ(ð	)à$(Ô˜DÒ!ùò \s   ÁA?Á!A?c                 óè   — t         du ry| €t        j                  dd«       S | r8| t        v r
t        |     S dj                  | j	                  d«      dd «      } | rŒ8t        j                  dd«       S )aæ  
    Check if progress bars are disabled globally or for a specific group.

    This function returns whether progress bars are disabled for a given group or globally.
    It checks the `HF_HUB_DISABLE_PROGRESS_BARS` environment variable first, then the programmatic
    settings.

    Args:
        name (`str`, *optional*):
            The group name to check; if None, checks the global setting.

    Returns:
        `bool`: True if progress bars are disabled, False otherwise.
    TNr   r   éÿÿÿÿ)r
   r   ÚgetÚjoinÚsplit©r   s    r   r   r   ¾   s~   € ô $ tÑ+Øà€|Ü&×*Ñ*¨9°dÓ;Ð;Ð;á
ØÔ&Ñ&Ü*¨4Ñ0Ð0Ð0Ø�x‰x˜Ÿ
™
 3›¨¨Ð,Ó-ˆò ô
 #×&Ñ& y°$Ó7Ð7Ð7r$   Ú	log_levelc                 ó^   — | t         j                  k(  ryt        j                  d«      dk(  ryy)zí
    Determine if tqdm progress bars should be disabled based on logging level and environment settings.

    see https://github.com/huggingface/huggingface_hub/pull/2000 and https://github.com/huggingface/huggingface_hub/pull/2698.
    TÚTQDM_POSITIONz-1FN)ÚloggingÚNOTSETÚosÚgetenv)r5   s    r   Úis_tqdm_disabledr<   Û   s*   € ð ”G—N‘NÒ"ØÜ	‡y�y�Ó! TÒ)ØØr$   c                   ó6   ‡ — e Zd ZdZˆ fd„Zdeddfˆ fd„Zˆ xZS )r   z«
    Class to override `disable` argument in case progress bars are globally disabled.

    Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.
    c                 óh   •— |j                  dd «      }t        |«      rd|d<   t        ‰| �  |i |¤Ž y )Nr   TÚdisable)Úpopr   Úsuperr   )r   ÚargsÚkwargsr   Ú	__class__s       €r   r   ztqdm.__init__ï   s7   ø€ Ø�z‰z˜& $Ó'ˆÜ% dÔ+Ø $ˆF�9ÑÜ‰Ñ˜$Ð) &Ó)r$   Úattrr   Nc                 óP   •— 	 t         ‰| �  |«       y# t        $ r	 |dk7  r‚ Y yw xY w)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603Ú_lockN)rA   Ú__delattr__ÚAttributeError)r   rE   rD   s     €r   rH   ztqdm.__delattr__õ   s3   ø€ ð	Ü‰GÑ Õ%øÜò 	Ø�wŠØñ ð	ús   ƒ “%¤%)r)   r*   r+   r,   r   r-   rH   Ú__classcell__)rD   s   @r   r   r   è   s%   ø„ ñô*ð ð ¨÷ ñ r$   r   c                   ó@   — e Zd ZdZd„ Zd„ Zd„ Zd	deez  dz  ddfd„Z	y)
Úsilent_tqdmz#Fake tqdm object that does nothing.c                  ó   — y r   r    )r   rB   rC   s      r   r   zsilent_tqdm.__init__  ó   € Ør$   c                 ó   — | S r   r    r!   s    r   r"   zsilent_tqdm.__enter__  r#   r$   c                  ó   — y r   r    )r   Úexc_typeÚ	exc_valueÚ	tracebacks       r   r(   zsilent_tqdm.__exit__  rN   r$   ÚnNr   c                  ó   — y r   r    )r   rT   s     r   Úupdatezsilent_tqdm.update  rN   r$   )é   )
r)   r*   r+   r,   r   r"   r(   ÚintÚfloatrV   r    r$   r   rL   rL     s0   „ Ù-òòòñ˜˜e™ dÑ*ð °4ô r$   rL   Úpathc              #   óv  ‡‡K  — t        | t        «      rt        | «      } | j                  d«      5 }| j	                  «       j
                  }t        dd|d| j                  ¬«      Š|j                  Šd
dt        dz  dt        fˆˆfd	„}||_        |–— ‰j                  «        ddd«       y# 1 sw Y   yxY w­w)uQ  
    Open a file as binary and wrap the `read` method to display a progress bar when it's streamed.

    First implemented in `transformers` in 2019 but removed when switched to git-lfs. Used in `huggingface_hub` to show
    progress bar when uploading an LFS file to the Hub. See github.com/huggingface/transformers/pull/2078#discussion_r354739608
    for implementation details.

    Note: currently implementation handles only files stored on disk as it is the most common use case. Could be
          extended to stream any `BinaryIO` object but we might have to debug some corner cases.

    Example:
    ```py
    >>> with tqdm_stream_file("config.json") as f:
    >>>     httpx.put(url, data=f)
    config.json: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 8.19k/8.19k [00:02<00:00, 3.72kB/s]
    ```
    ÚrbÚBTr   )ÚunitÚ
unit_scaleÚtotalÚinitialÚdescÚsizeNr   c                 óL   •—  ‰| «      }‰j                  t        |«      «       |S r   )rV   Úlen)rc   ÚdataÚf_readÚpbars     €€r   Ú_inner_readz%tqdm_stream_file.<locals>._inner_read7  s!   ø€ Ù˜$“<ˆDØ�K‰Kœ˜D›	Ô"ØˆKr$   )r0   )Ú
isinstancer-   r   ÚopenÚstatÚst_sizer   r   ÚreadrX   ÚbytesÚclose)rZ   ÚfÚ
total_sizeri   rg   rh   s       @@r   Útqdm_stream_filers     s¤   ùè ø€ ô& �$œÔÜ�D‹zˆà	�‰�4‹ð ˜AØ—Y‘Y“[×(Ñ(ˆ
ÜØØØØØ—‘ô
ˆð —‘ˆñ	œc D™jð 	´%ö 	ð
 ˆŒàŠà�
‰
Œ÷+÷ ñ üs   „-B9±A3B-Â$	B9Â-B6Â2B9r4   Úclsc                 ó~   — t        | t        «      rt        | t        «      s | di |¤ŽS t	        |«      } | d||dœ|¤ŽS )aÇ  Create a progress bar.

    For our `tqdm` subclass (or subclasses of it): respects all disable signals
    (`HF_HUB_DISABLE_PROGRESS_BARS`, `disable_progress_bars()`, log level) and uses
    `disable=None` for TTY auto-detection (see https://github.com/huggingface/huggingface_hub/pull/2000),
    unless `TQDM_POSITION=-1` forces bars on (https://github.com/huggingface/huggingface_hub/pull/2698).

    For other classes: does not inject `disable` or `name`. the custom class is fully
    responsible for its own behavior. Vanilla tqdm defaults to `disable=False` (bar shows).
    Omits `name` which vanilla tqdm rejects with `TqdmKeyError`. See https://github.com/huggingface/huggingface_hub/issues/4050.
    )r?   r   r    )rj   ÚtypeÚ
issubclassr   r<   )rt   r5   r   rC   r?   s        r   Ú_create_progress_barrx   C  sD   € ô �sœDÔ!¤j°´dÔ&;Ù‰}�V‰}Ðô ˜yÓ)€GÙÐ4�w TÑ4¨VÑ4Ð4r$   r]   T)r`   ra   r^   r_   r   Ú
tqdm_classÚ	_tqdm_barrb   r`   ra   r^   r_   ry   rz   c        	   
      óR   — |�t        |«      S t        |xs t        ||||||| ¬«      S )N)rt   r5   r   r^   r_   r`   ra   rb   )r   rx   r   )	rb   r5   r`   ra   r^   r_   r   ry   rz   s	            r   Ú_get_progress_bar_contextr|   Y  sA   € ð ÐÜ˜9Ó%Ð%ô
  ØÒœ$ØØØØØØØô	ð 	r$   r   )&r,   Úior8   r:   Ú	threadingr   Úcollections.abcr   Ú
contextlibr   r   Úpathlibr   Útypingr   Ú	tqdm.autor   Úold_tqdmÚ	constantsr
   r   Údictr-   ÚboolÚ__annotations__r   r&   r   rX   r<   Úset_lockÚRLockrL   ÚBufferedReaderrs   rv   rx   r|   r    r$   r   ú<module>rŒ      s½  ðòBóH 
Û Û 	Û Û Ý $ß 2Ý Ý !å &å 4ð (*Ð �T˜#˜t˜)‘_Ó )÷/,ñ /,ñd)˜s T™zð )°Tó )ñ@8 S¨4¡Zð 8¸4ó 8ð:
 ð 
¨¨t©ó 
ôˆ8ô ð4 ‡�ˆoˆi�o‰oÓÔ  ÷ñ ð  ð*˜4 #™:ð *¨(°2×3DÑ3DÑ*Eò *ó ð*ðZ UYò 5  h¡ð 5¸Cð 5ÀsÈTÁzð 5Ðgoó 5ð4 ØØØØØ(,Ø!òà
ðð ðð �‰:ð	ð
 ðð ðð ðð �‰*ðð �X‘ Ñ%ðð �d‰{ðð �DÑôr$   