o
    Ni                     @  s   U d Z ddlmZ ddlZddlZddlmZ ddlm	Z	m
Z
 er+ddlmZmZmZ d'd
dZd(ddZG dd dZedgZi Zded< d)ddZd*ddZ		d+d,d%d&ZdS )-z.Pattern-matching utility functions for Sphinx.    )annotationsN)TYPE_CHECKING)
canon_pathpath_stabilize)CallableIterableIteratorpatstrreturnc                 C  sx  dt | }}d}||k r| | }|d7 }|dkr1||k r,| | dkr,|d7 }|d }n|d }n|dkr:|d }nz|d	kr|}||k rN| | d
krN|d7 }||k r\| | dkr\|d7 }||k rt| | dkrt|d7 }||k rt| | dksf||kr}|d }n7| || dd}|d }|d d
krd|dd  }n
|d dkrd| }| d	| d}n|t|7 }||k s|d S )zTranslate a shell-style glob pattern to a regular expression.

    Adapted from the fnmatch module, but enhanced so that single stars don't
    match slashes.
    r       *z.*z[^/]*?z[^/][!]z\[\z\\z^/N^$)lenreplacereescape)r	   inrescjstuff r    H/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/util/matching.py_translate_pattern   sB   



#r"   patternsIterable[str]+list[Callable[[str], re.Match[str] | None]]c                 C  s   dd | D S )Nc                 S  s   g | ]
}t t|jqS r    )r   compiler"   match.0r	   r    r    r!   
<listcomp>@   s    z$compile_matchers.<locals>.<listcomp>r    )r#   r    r    r!   compile_matchers=   s   r+   c                   @  s.   e Zd ZdZdddZdddZdddZdS )MatcherzA pattern matcher for Multiple shell-style glob patterns.

    Note: this modifies the patterns to work with copy_asset().
          For example, "**/index.rst" matches with "index.rst"
    exclude_patternsr$   r   Nonec                 C  s$   dd |D }t t|| | _d S )Nc                 S  s"   g | ]}| d r|dd qS )z**/   N)
startswithr(   r    r    r!   r*   K   s   " z$Matcher.__init__.<locals>.<listcomp>)r+   listr#   )selfr-   expandedr    r    r!   __init__J   s   zMatcher.__init__stringr
   boolc                 C  s
   |  |S N)r'   r2   r5   r    r    r!   __call__N   s   
zMatcher.__call__c                   s    t   t fdd| jD S )Nc                 3  s    | ]}| V  qd S r7   r    r(   r5   r    r!   	<genexpr>S   s    z Matcher.match.<locals>.<genexpr>)r   anyr#   r8   r    r:   r!   r'   Q   s   zMatcher.matchN)r-   r$   r   r.   )r5   r
   r   r6   )__name__
__module____qualname____doc__r4   r9   r'   r    r    r    r!   r,   C   s
    

r,   z**/.*zdict[str, re.Pattern[str]]
_pat_cachenamere.Match[str] | Nonec                 C  s(   |t vrtt|t |< t | | S )zgReturn if name matches the regular expression (pattern)
    ``pat```. Adapted from fnmatch module.
    )rA   r   r&   r"   r'   )rB   r	   r    r    r!   patmatch\   s   rD   names	list[str]c                 C  s2   |t vrtt|t |< t | j}tt|| S )zReturn the subset of the list ``names`` that match
    the regular expression (pattern) ``pat``.

    Adapted from fnmatch module.
    )rA   r   r&   r"   r'   r1   filter)rE   r	   r'   r    r    r!   	patfiltere   s   
rH   z**r    dirnamestr | os.PathLike[str]include_patternsr-   Iterator[str]c                 c  s"   t jt j| } t|}t|}t j| ddD ]t\}}}t j|| }|dkr,d}g }	t|D ].}
tt j	||
}
d}|D ]
}||
rKd} nqA|D ]
}||
rXd} nqN|r`|	
|
 q2g }t|D ]}tt j	||}|D ]}||r| nqt|
| qg||dd< |	E dH  qdS )ac  Get all file names in a directory, recursively.

    Filter file names by the glob-style include_patterns and exclude_patterns.
    The default values include all files ("**") and exclude nothing ("").

    Only files matching some pattern in *include_patterns* are included, and
    exclusions from *exclude_patterns* take priority over inclusions.

    T)followlinks.r   FN)ospathnormpathabspathr+   walkrelpathsortedr   joinappend)rJ   rL   r-   exclude_matchersinclude_matchersrootdirsfilesrelative_rootincluded_filesentrykeepmatcherfiltered_dirsdir_name
normalisedr    r    r!   get_matching_filesq   sJ   

rf   )r	   r
   r   r
   )r#   r$   r   r%   )rB   r
   r	   r
   r   rC   )rE   r$   r	   r
   r   rF   )rI   r    )rJ   rK   rL   r$   r-   r$   r   rM   )r@   
__future__r   os.pathrP   r   typingr   sphinx.util.osutilr   r   collections.abcr   r   r   r"   r+   r,   DOTFILESrA   __annotations__rD   rH   rf   r    r    r    r!   <module>   s$    

.


	