B
    \o                 @   sZ   d Z ddlZddlmZ dd Zdd ZG dd	 d	eZed
gZi Z	dd Z
dd ZdS )z
    sphinx.util.matching
    ~~~~~~~~~~~~~~~~~~~~

    Pattern-matching utility functions for Sphinx.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)
canon_pathc             C   sn  dt |  }}d}xP||k rd| | }|d7 }|dkrh||k r^| | dkr^|d7 }|d }n|d }q|dkrz|d }q|d	krT|}||k r| | d
kr|d7 }||k r| | dkr|d7 }x ||k r| | dkr|d7 }qW ||kr|d }n^| || dd}|d }|d d
kr0d|dd  }n|d dkrFd| }d||f }q|t|7 }qW |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^z%s[%s]$)lenreplacereescape)patinZrescjZstuff r   3lib/python3.7/site-packages/sphinx/util/matching.py_translate_pattern   s>    




r   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>F   s    z$compile_matchers.<locals>.<listcomp>r   )patternsr   r   r   compile_matchersD   s    r   c               @   s(   e Zd ZdZdd Zdd Z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"
    c             C   s    dd |D }t || | _d S )Nc             S   s"   g | ]}| d r|dd qS )z**/   N)
startswith)r   r   r   r   r   r   R   s    z$Matcher.__init__.<locals>.<listcomp>)r   r   )selfr   Zexpandedr   r   r   __init__P   s    zMatcher.__init__c             C   s
   |  |S )N)r   )r"   stringr   r   r   __call__U   s    zMatcher.__call__c                s    t   t fdd| jD S )Nc             3   s   | ]}| V  qd S )Nr   )r   r   )r$   r   r   	<genexpr>\   s    z Matcher.match.<locals>.<genexpr>)r   anyr   )r"   r$   r   )r$   r   r   Y   s    zMatcher.matchN)__name__
__module____qualname____doc__r#   r%   r   r   r   r   r   r   I   s   r   z**/.*c             C   s(   |t krtt|t |< t | | S )z9Return if name matches pat.  Adapted from fnmatch module.)
_pat_cacher   r   r   r   )namer   r   r   r   patmatche   s    r.   c             C   s2   |t krtt|t |< t | j}tt|| S )zZReturn the subset of the list NAMES that match PAT.

    Adapted from fnmatch module.
    )r,   r   r   r   r   listfilter)namesr   r   r   r   r   	patfilterm   s    
r2   )r+   r   Zsphinx.util.osutilr   r   r   objectr   ZDOTFILESr,   r.   r2   r   r   r   r   <module>
   s   /
