§
    ¬˜ºh²  ã                   ó.  — d Z ddlmZ ddlmZ ddlmZmZmZmZm	Z	m
Z
mZ  e
d¦  «        Zg d¢ZddgZd	d	d	d
œdee         de	eee         ef                  de	eee         ef                  de	eegef                  deed	d	f         f
d„Zdedefd„Zd	S )z6Contains utilities to handle paths in Huggingface Hub.é    ©Úfnmatch)ÚPath)ÚCallableÚ	GeneratorÚIterableÚListÚOptionalÚTypeVarÚUnionÚT)ú.gitz.git/*z*/.gitz
**/.git/**z.cache/huggingfacez.cache/huggingface/*z*/.cache/huggingfacez**/.cache/huggingface/**r   z.cacheN)Úallow_patternsÚignore_patternsÚkeyÚitemsr   r   r   Úreturnc             #   óp  ‡K  — t          |t          ¦  «        r|g}t          |t          ¦  «        r|g}|�d„ |D ¦   «         }|�d„ |D ¦   «         }|€dt          dt          fd„}|}| D ]M} ||¦  «        Š|�t          ˆfd„|D ¦   «         ¦  «        sŒ+|�t          ˆfd„|D ¦   «         ¦  «        rŒI|V — ŒNdS )	aÀ  Filter repo objects based on an allowlist and a denylist.

    Input must be a list of paths (`str` or `Path`) or a list of arbitrary objects.
    In the later case, `key` must be provided and specifies a function of one argument
    that is used to extract a path from each element in iterable.

    Patterns are Unix shell-style wildcards which are NOT regular expressions. See
    https://docs.python.org/3/library/fnmatch.html for more details.

    Args:
        items (`Iterable`):
            List of items to filter.
        allow_patterns (`str` or `List[str]`, *optional*):
            Patterns constituting the allowlist. If provided, item paths must match at
            least one pattern from the allowlist.
        ignore_patterns (`str` or `List[str]`, *optional*):
            Patterns constituting the denylist. If provided, item paths must not match
            any patterns from the denylist.
        key (`Callable[[T], str]`, *optional*):
            Single-argument function to extract a path from each item. If not provided,
            the `items` must already be `str` or `Path`.

    Returns:
        Filtered list of objects, as a generator.

    Raises:
        :class:`ValueError`:
            If `key` is not provided and items are not `str` or `Path`.

    Example usage with paths:
    ```python
    >>> # Filter only PDFs that are not hidden.
    >>> list(filter_repo_objects(
    ...     ["aaa.PDF", "bbb.jpg", ".ccc.pdf", ".ddd.png"],
    ...     allow_patterns=["*.pdf"],
    ...     ignore_patterns=[".*"],
    ... ))
    ["aaa.pdf"]
    ```

    Example usage with objects:
    ```python
    >>> list(filter_repo_objects(
    ... [
    ...     CommitOperationAdd(path_or_fileobj="/tmp/aaa.pdf", path_in_repo="aaa.pdf")
    ...     CommitOperationAdd(path_or_fileobj="/tmp/bbb.jpg", path_in_repo="bbb.jpg")
    ...     CommitOperationAdd(path_or_fileobj="/tmp/.ccc.pdf", path_in_repo=".ccc.pdf")
    ...     CommitOperationAdd(path_or_fileobj="/tmp/.ddd.png", path_in_repo=".ddd.png")
    ... ],
    ... allow_patterns=["*.pdf"],
    ... ignore_patterns=[".*"],
    ... key=lambda x: x.repo_in_path
    ... ))
    [CommitOperationAdd(path_or_fileobj="/tmp/aaa.pdf", path_in_repo="aaa.pdf")]
    ```
    Nc                 ó,   — g | ]}t          |¦  «        ‘ŒS © ©Ú_add_wildcard_to_directories©Ú.0Úps     úd/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/huggingface_hub/utils/_paths.pyú
<listcomp>z'filter_repo_objects.<locals>.<listcomp>m   s!   € ÐRÐRÐR¸aÕ6°qÑ9Ô9ÐRÐRÐRó    c                 ó,   — g | ]}t          |¦  «        ‘ŒS r   r   r   s     r   r   z'filter_repo_objects.<locals>.<listcomp>o   s!   € ÐTÐTÐT¸qÕ7¸Ñ:Ô:ÐTÐTÐTr   Úitemr   c                 óž   — t          | t          ¦  «        r| S t          | t          ¦  «        rt          | ¦  «        S t          d| › d�¦  «        ‚)Nz9Please provide `key` argument in `filter_repo_objects`: `z` is not a string.)Ú
isinstanceÚstrr   Ú
ValueError)r    s    r   Ú	_identityz&filter_repo_objects.<locals>._identitys   sR   € Ý˜$¥Ñ$Ô$ð Ø�Ý˜$¥Ñ%Ô%ð !Ý˜4‘y”yÐ ÝÐqÐY]ÐqÐqÐqÑrÔrÐrr   c              3   ó8   •K  — | ]}t          ‰|¦  «        V — Œd S ©Nr   ©r   ÚrÚpaths     €r   ú	<genexpr>z&filter_repo_objects.<locals>.<genexpr>€   s-   øè è € Ð1[Ð1[Àqµ'¸$ÀÑ2BÔ2BÐ1[Ð1[Ð1[Ð1[Ð1[Ð1[r   c              3   ó8   •K  — | ]}t          ‰|¦  «        V — Œd S r'   r   r(   s     €r   r+   z&filter_repo_objects.<locals>.<genexpr>„   s-   øè è € Ð.YÐ.YÀA­w°t¸QÑ/?Ô/?Ð.YÐ.YÐ.YÐ.YÐ.YÐ.Yr   )r"   r#   r   Úany)r   r   r   r   r%   r    r*   s         @r   Úfilter_repo_objectsr.   '   s/  øè è € õ~ �.¥#Ñ&Ô&ð *Ø(Ð)ˆå�/¥3Ñ'Ô'ð ,Ø*Ð+ˆàÐ!ØRÐRÀ>ÐRÑRÔRˆØÐ"ØTÐTÀOÐTÑTÔTˆà
€{ð	s�Að 	s¥#ð 	sð 	sð 	sð 	sð ˆàð ð ˆØˆs�4‰yŒyˆð Ð%­cÐ1[Ð1[Ð1[Ð1[ÈNÐ1[Ñ1[Ô1[Ñ.[Ô.[Ð%Øð Ð&­3Ð.YÐ.YÐ.YÐ.YÈÐ.YÑ.YÔ.YÑ+YÔ+YÐ&Øàˆ
ˆ
ˆ
ˆ
ðð r   Úpatternc                 ó(   — | d         dk    r| dz   S | S )Néÿÿÿÿú/Ú*r   )r/   s    r   r   r   Š   s    € Øˆr„{�cÒÐØ˜‰}ÐØ€Nr   )Ú__doc__r   Úpathlibr   Útypingr   r   r   r	   r
   r   r   r   ÚDEFAULT_IGNORE_PATTERNSÚFORBIDDEN_FOLDERSr#   r.   r   r   r   r   ú<module>r9      si  ðð =Ð <à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ Pð €GˆC�L„L€ð	ð 	ð 	Ð ð ˜XÐ&Ð ð 7;Ø7;Ø(,ð`ð `ð `Ø�AŒ;ð`ð ˜U 4¨¤9¨c >Ô2Ô3ð`ð ˜e D¨¤I¨s NÔ3Ô4ð	`ð
 
�(˜A˜3 ˜8Ô$Ô	%ð`ð ˆq�$˜ˆ}Ôð`ð `ð `ð `ðF¨#ð °#ð ð ð ð ð ð r   