ó
öŔ\c           @   sŚ   d  Z  d d l Z d d l m Z e rS d d l m Z m Z m Z m	 Z	 m
 Z
 n  d   Z d   Z d e f d     YZ e d	 g  Z i  Z d
   Z d   Z d S(   sŮ   
    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.
i˙˙˙˙N(   t
   canon_path(   t   Callablet   Dictt   Listt   Matcht   Patternc         C   sŢ  d t  |   } } d } xş| | k  rŐ|  | } | d 7} | d k r | | k  r{ |  | d k r{ | d 7} | d } qŇ| d } q | d k rĄ | d } q | d	 k rż| } | | k  rÜ |  | d
 k rÜ | d 7} n  | | k  r|  | d k r| d 7} n  x* | | k  r1|  | d k r1| d 7} qW| | k rK| d } qŇ|  | | !j d d  } | d } | d d
 k rd | d } n | d d k rŹd | } n  d | | f } q | t j |  7} q W| d S(   sŁ   Translate a shell-style glob pattern to a regular expression.

    Adapted from the fnmatch module, but enhanced so that single stars don't
    match slashes.
    i    t    i   t   *s   .*s   [^/]*t   ?s   [^/]t   [t   !t   ]s   \[s   \s   \\s   ^/t   ^s   %s[%s]t   $(   t   lent   replacet   ret   escape(   t   patt   it   nt   rest   ct   jt   stuff(    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   _translate_pattern   s>    



c         C   s)   g  |  D] } t  j t |   j ^ q S(   N(   R   t   compileR   t   match(   t   patternsR   (    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   compile_matchersD   s    t   Matcherc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sž   A 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   sC   g  | D] } | j  d  r | d ^ q } t | |  |  _ d  S(   Ns   **/i   (   t
   startswithR   R   (   t   selfR   R   t   expanded(    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   __init__P   s    ,c         C   s   |  j  |  S(   N(   R   (   R    t   string(    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   __call__U   s    c            s)   t       t   f d   |  j D  S(   Nc         3   s   |  ] } |    Vq d  S(   N(    (   t   .0R   (   R#   (    s3   lib/python2.7/site-packages/sphinx/util/matching.pys	   <genexpr>\   s    (   R    t   anyR   (   R    R#   (    (   R#   s3   lib/python2.7/site-packages/sphinx/util/matching.pyR   Y   s    (   t   __name__t
   __module__t   __doc__R"   R$   R   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyR   I   s   		s   **/.*c         C   s9   | t  k r( t j t |   t  | <n  t  | j |   S(   s9   Return if name matches pat.  Adapted from fnmatch module.(   t
   _pat_cacheR   R   R   R   (   t   nameR   (    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   patmatche   s    c         C   sH   | t  k r( t j t |   t  | <n  t  | j } t t | |    S(   sZ   Return the subset of the list NAMES that match PAT.

    Adapted from fnmatch module.
    (   R*   R   R   R   R   t   listt   filter(   t   namesR   R   (    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt	   patfilterm   s    (   R)   R   t   sphinx.util.osutilR    t   Falset   typingR   R   R   R   R   R   R   t   objectR   t   DOTFILESR*   R,   R0   (    (    (    s3   lib/python2.7/site-packages/sphinx/util/matching.pyt   <module>
   s   +	/		