Ë
    /æjÏ  ã                   ó  — d Z ddl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ee	z  dedefd„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y)z6Contains utilities to handle paths in Huggingface Hub.é    N)ÚCallableÚ	GeneratorÚIterable©Úfnmatchcase)ÚPath)ÚTypeVarÚT)ú.gitz.git/*z*/.gitz
**/.git/**z.cache/huggingfacez.cache/huggingface/*z*/.cache/huggingfacez**/.cache/huggingface/**r   z.cacheÚpathÚ
max_lengthÚreturnc                 óþ   — t        | «      } t        j                  dk7  r| S t        j                  j	                  | «      }t        |«      |k  s|j                  d«      r| S |j                  d«      rd|dd z   S d|z   S )a“  Return `path` in its Windows extended-length form if it is too long, unchanged otherwise.

    Some Windows versions do not allow for paths longer than 255 characters (247 for directories, i.e. MAX_PATH minus
    room for an 8.3 file name). In this case, we must specify them as extended paths by using the `\\?\` prefix, which
    only works on absolute paths. Network shares take the `\\?\UNC\server\share\...` form: prefixing them verbatim
    would produce an invalid `\\?\\\server\...` path.

    Args:
        path (`str` or `Path`):
            The path to convert. Returned unchanged on non-Windows platforms, if it is short enough, or if it is
            already an extended path.
        max_length (`int`, *optional*):
            Length above which the path must be converted. Defaults to 255, the limit for files. Pass 247 for paths
            whose parent directories are created by the caller.
    Úntz\\?\z\\z\\?\UNC\é   N)ÚstrÚosÚnamer   ÚabspathÚlenÚ
startswith)r   r   Úabsolute_paths      ú_/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/huggingface_hub/utils/_paths.pyÚas_extended_pathr   (   sy   € ô  ˆt‹9€DÜ	‡w�w�$‚ØˆÜ—G‘G—O‘O DÓ)€MÜ
ˆ=Ó˜ZÒ'¨=×+CÑ+CÀIÔ+NØˆØ×Ñ Ô'Ø ¨a¨bÐ 1Ñ1Ð1Ø�}Ñ$Ð$ó    )Úallow_patternsÚignore_patternsÚkeyÚitemsr   r   r   c             #   ó¶  ‡K  — t        |t        «      r|g}t        |t        «      r|g}|�!|D �cg c]  }t        t        |«      «      ‘Œ }}|�!|D �cg c]  }t        t        |«      «      ‘Œ }}|€dt        dt        fd„}|}| D ]E  }t         ||«      «      Š|�t        ˆfd„|D «       «      sŒ+|�t        ˆfd„|D «       «      rŒB|–— ŒG yc c}w c c}w ­w)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")]
    ```
    NÚitemr   c                 óz   — 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.)Ú
isinstancer   r   Ú
ValueError)r!   s    r   Ú	_identityz&filter_repo_objects.<locals>._identity–   s=   € Ü˜$¤Ô$Ø�Ü˜$¤Ô%Ü˜4“yÐ ÜÐXÐY]ÐX^Ð^pÐqÓrÐrr   c              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­w©Nr   ©Ú.0Úrr   s     €r   ú	<genexpr>z&filter_repo_objects.<locals>.<genexpr>£   s   øè ø€ Ò1_È1´+¸dÀA×2FÑ1_ùó   ƒc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­wr'   r   r(   s     €r   r+   z&filter_repo_objects.<locals>.<genexpr>§   s   øè ø€ Ò.]È¬{¸4À×/CÑ.]ùr,   )r#   r   Ú_add_wildcard_to_directoriesÚ_normalize_separatorsr
   Úany)r   r   r   r   Úpr%   r!   r   s          @r   Úfilter_repo_objectsr2   C   sø   øè ø€ ôL �.¤#Ô&Ø(Ð)ˆä�/¤3Ô'Ø*Ð+ˆàÐ!ØZhÖiÐUVÔ6Ô7LÈQÓ7OÕPÐiˆÐiØÐ"Ø[jÖkÐVWÔ7Ô8MÈaÓ8PÕQÐkˆÐkà
€{ð	sœAð 	s¤#ó 	sð ˆàò ˆÜ$¡S¨£YÓ/ˆð Ð%¬cÓ1_ÐP^Ô1_Ô._Øð Ð&¬3Ó.]È_Ô.]Ô+]Øà‹
ñùò jùâkùs   ƒ-C°CÁCÁCÁ.A+CÚvaluec                 ó8   — t        | «      j                  dd«      S )Nú\ú/)r   Úreplace)r3   s    r   r/   r/   ­   s   € ô ˆu‹:×Ñ˜d CÓ(Ð(r   Úpatternc                 ó2   — | j                  d«      r| dz   S | S )Nr6   Ú*)Úendswith)r8   s    r   r.   r.   ´   s   € Ø×Ñ˜ÔØ˜‰}ÐØ€Nr   )éÿ   )Ú__doc__r   Úcollections.abcr   r   r   Úfnmatchr   Úpathlibr   Útypingr	   r
   ÚDEFAULT_IGNORE_PATTERNSÚFORBIDDEN_FOLDERSr   Úintr   Úlistr2   r/   r.   © r   r   ú<module>rG      s  ðñ =ã 	ß 9Ñ 9Ý Ý Ý ñ ˆCƒL€ò	Ð ð ˜XÐ&Ð ñ%˜3 ™:ð %°3ð %Àó %ð< .2Ø.2Ø%)ògØ�A‰;ðgð ˜‘I ‘O dÑ*ðgð ˜#‘Y ‘_ tÑ+ð	gð
 
�1�#�s�(Ñ	˜dÑ	"ðgð ˆq�$˜ˆ}ÑógðT)  t¡ð )°ó )ð¨#ð °#ô r   