
    g                     .   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     X/var/www/html/ai-engine/env/lib/python3.11/site-packages/huggingface_hub/utils/_paths.py
<listcomp>z'filter_repo_objects.<locals>.<listcomp>m   s!    RRRa6q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Tq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    $$$ $%% !4yy qY]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'$2B2B1[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.YAwtQ/?/?.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TOTTT
{	sA 	s# 	s 	s 	s 	s   s4yy %c1[1[1[1[N1[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 GCLL	 	 	  X&  7;7;(,` ` `A;` U49c>23` eDIsN34	`
 
(A38$	%` q$}` ` ` `F# #      r   