
    5pjJ                         S r SSKJrJrJr  SSKJr  SSKJr  SSK	J
r
  \
" S5      r/ SQrSS	/rS
S
S
S.S\\   S\\   \-  S
-  S\\   \-  S
-  S\\/\4   S
-  S\\S
S
4   4
S jjrS\\-  S\4S jrS\S\4S jrg
)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             #     ^#    [        U[        5      (       a  U/n[        U[        5      (       a  U/nUb$  U Vs/ s H  n[        [        U5      5      PM     nnUb$  U Vs/ s H  n[        [        U5      5      PM     nnUc  S[        S[        4S jnUnU  HV  n[        U" U5      5      mUb  [        U4S jU 5       5      (       d  M3  Ub  [        U4S jU 5       5      (       a  MR  Uv   MX     gs  snf s  snf 7f)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                     [        U [        5      (       a  U $ [        U [        5      (       a  [        U 5      $ [        SU  S35      e)Nz9Please provide `key` argument in `filter_repo_objects`: `z` is not a string.)
isinstancestrr   
ValueError)r   s    X/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/utils/_paths.py	_identity&filter_repo_objects.<locals>._identityz   sC    $$$$%%4y XY]X^^pqrr    c              3   <   >#    U  H  n[        TU5      v   M     g 7fNr   .0rpaths     r   	<genexpr>&filter_repo_objects.<locals>.<genexpr>   s     1_P^1+dA2F2FP^   c              3   <   >#    U  H  n[        TU5      v   M     g 7fr   r   r   s     r   r!   r"      s     .]_{4/C/C_r#   )r   r   _add_wildcard_to_directories_normalize_separatorsr
   any)r   r   r   r   pr   r   r    s          @r   filter_repo_objectsr)   '   s    L .#&&()/3''*+!ZhiZhUV67LQ7OPZhi"[jk[jVW78Ma8PQ[jk
{	sA 	s# 	s $SY/ %c1_P^1_._._ &3.]_.]+]+]
  jks   8C?C5	C?"C: A?C?valuec                 8    [        U 5      R                  SS5      $ )N\/)r   replace)r*   s    r   r&   r&      s     u:dC((r   patternc                 <    U R                  S5      (       a  U S-   $ U $ )Nr-   *)endswith)r/   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   <module>r<      s    = 9 9    CL	  X&  .2.2%)gA;g IOd*g #Y_t+	g
 
1#s(	d	"g q$}gT)t ) )# # r   