§
    }ŠtjJ  ã                   ó  — d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
  e
d¦  «        Zg d¢Zdd	gZd
d
d
dœdee         dee         ez  d
z  dee         ez  d
z  deegef         d
z  deed
d
f         f
d„Zdeez  defd„Zdedefd„Zd
S )z6Contains utilities to handle paths in Huggingface Hub.é    )ÚCallableÚ	GeneratorÚIterable©Úfnmatchcase)ÚPath)ÚTypeVarÚ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             #   óŠ  ‡K  — t          |t          ¦  «        r|g}t          |t          ¦  «        r|g}|�d„ |D ¦   «         }|�d„ |D ¦   «         }|€dt          dt          fd„}|}| D ]Z}t           ||¦  «        ¦  «        Š|�t	          ˆfd„|D ¦   «         ¦  «        sŒ8|�t	          ˆfd„|D ¦   «         ¦  «        rŒV|V — Œ[d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 Standard Wildcards (globbing patterns), NOT regular expressions. The pattern matching is based on
    Python's `fnmatch.fnmatchcase`, so it is case-sensitive on every platform. Backslashes are treated as path separators
    and normalized to forward slashes in both patterns and paths before matching, so patterns built with `os.path.join`
    on Windows work as expected.

    Note that it matches `*` across path boundaries, unlike traditional Unix shell globbing. For example, `"data/*.json"`
    will match both `data/file.json` and `data/subdir/file.json`.

    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.path_in_repo
    ... ))
    [CommitOperationAdd(path_or_fileobj="/tmp/aaa.pdf", path_in_repo="aaa.pdf")]
    ```
    Nc                 óF   — g | ]}t          t          |¦  «        ¦  «        ‘ŒS © ©Ú_add_wildcard_to_directoriesÚ_normalize_separators©Ú.0Úps     úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/huggingface_hub/utils/_paths.pyú
<listcomp>z'filter_repo_objects.<locals>.<listcomp>t   s+   € ÐiÐiÐiÐUVÕ6Õ7LÈQÑ7OÔ7OÑPÔPÐiÐiÐió    c                 óF   — g | ]}t          t          |¦  «        ¦  «        ‘ŒS r   r   r   s     r   r   z'filter_repo_objects.<locals>.<listcomp>v   s+   € ÐkÐkÐkÐVWÕ7Õ8MÈaÑ8PÔ8PÑQÔQÐkÐkÐkr   Ú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>._identityz   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_È1µ+¸dÀAÑ2FÔ2FÐ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-   øè è € Ð.]Ð.]È­{¸4ÀÑ/CÔ/CÐ.]Ð.]Ð.]Ð.]Ð.]Ð.]r   )r    r!   r
   r   Úany)r   r   r   r   r#   r   r(   s         @r   Úfilter_repo_objectsr,   '   s:  øè è € õL �.¥#Ñ&Ô&ð *Ø(Ð)ˆå�/¥3Ñ'Ô'ð ,Ø*Ð+ˆàÐ!ØiÐiÐZhÐiÑiÔiˆØÐ"ØkÐkÐ[jÐkÑkÔkˆà
€{ð	s�Að 	s¥#ð 	sð 	sð 	sð 	sð ˆàð ð ˆÝ$ S S¨¡Y¤YÑ/Ô/ˆð Ð%­cÐ1_Ð1_Ð1_Ð1_ÐP^Ð1_Ñ1_Ô1_Ñ._Ô._Ð%Øð Ð&­3Ð.]Ð.]Ð.]Ð.]È_Ð.]Ñ.]Ô.]Ñ+]Ô+]Ð&Øàˆ
ˆ
ˆ
ˆ
ðð r   Úvaluec                 óH   — t          | ¦  «                             dd¦  «        S )Nú\ú/)r!   Úreplace)r-   s    r   r   r   ‘   s    € õ ˆu‰:Œ:×Ò˜d CÑ(Ô(Ð(r   Úpatternc                 ó:   — |                       d¦  «        r| dz   S | S )Nr0   Ú*)Úendswith)r2   s    r   r   r   ˜   s'   € Ø×Ò˜ÑÔð Ø˜‰}ÐØ€Nr   )Ú__doc__Úcollections.abcr   r   r   Úfnmatchr   Úpathlibr   Útypingr	   r
   ÚDEFAULT_IGNORE_PATTERNSÚFORBIDDEN_FOLDERSÚlistr!   r,   r   r   r   r   r   ú<module>r>      s  ðð =Ð <à 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð €GˆC�L„L€ð	ð 	ð 	Ð ð ˜XÐ&Ð ð .2Ø.2Ø%)ðgð gð gØ�AŒ;ðgð ˜”I ‘O dÑ*ðgð ˜#”Y ‘_ tÑ+ð	gð
 
�1�#�s�(Ô	˜dÑ	"ðgð ˆq�$˜ˆ}Ôðgð gð gð gðT)  t¡ð )°ð )ð )ð )ð )ð¨#ð °#ð ð ð ð ð ð r   