ó
Ŭ]c           @   sÌ   d  Z  d d l Z d d l Z y d d l m Z Wn! e k
 rU d d l m Z n Xd d d d g Z d	   Z e	 e	 d d
  Z e d d d e	  d    Z e	 e	 d d  Z e	 d  Z d   Z d S(   s£  Filename matching with shell patterns.

fnmatch(FILENAME, PATTERN) matches according to the local convention.
fnmatchcase(FILENAME, PATTERN) always takes case in account.

The functions operate by translating the pattern into a regular
expression.  They cache the compiled regular expressions for speed.

The function translate(PATTERN) returns a regular expression
corresponding to PATTERN.  (It does not compile it.)
i˙˙˙˙N(   t	   lru_cachei   t   filtert   fnmatcht   fnmatchcaset	   translatec         C   sL   | d  k r- t j d | p! t j |   }  n | rH t j j |   }  n  |  S(   Ns   \/(   t   Nonet   ret   subt   ost   sept   patht   normcase(   R
   t
   norm_pathsR	   (    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyt   _norm_paths   s
    !c         C   sD   g  |  | f D] } t  | | |  ^ q \ }  } t |  | d | S(   sô  Test whether FILENAME matches PATTERN.

    Patterns are Unix shell style:

    *       matches everything
    ?       matches any single character
    [seq]   matches any character in seq
    [!seq]  matches any char not in seq

    An initial period in FILENAME is not special.
    Both FILENAME and PATTERN are first case-normalized
    if the operating system requires it.
    If you don't want this, use fnmatchcase(FILENAME, PATTERN).

    :param slashes:
    :param norm_paths:
        A tri-state boolean:
        when true, invokes `os.path,.normcase()` on both paths,
        when `None`, just equalize slashes/backslashes to `os.sep`,
        when false, does not touch paths at all.

        Note that a side-effect of `normcase()` on *Windows* is that
        it converts to lower-case all matches of `?glob()` functions.
    :param case_sensitive:
        defines the case-sensitiviness of regex doing the matches
    :param sep:
        in case only slahes replaced, what sep-char to substitute with;
        if false, `os.sep` is used.

    Notice that by default, `normcase()` causes insensitive matching
    on *Windows*, regardless of `case_insensitive` param.
    Set ``norm_paths=None, case_sensitive=False`` to preserve
    verbatim mathces.
    t   case_sensitive(   R   R   (   t   namet   patR   R   R	   t   p(    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyR      s    #.t   maxsizei   t   typedc         C   sp   t  |  t  r< |  j d  } t |  } | j d  } n t |   } | rT d n t j } t j | |  j S(   Ns
   ISO-8859-1i    (	   t
   isinstancet   bytest   decodeR   t   encodeR   t
   IGNORECASEt   compilet   match(   R   R   t   pat_strt   res_strt   rest   flags(    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyt   _compile_patternG   s    c   	         s   g  } t  |     } t | |  } xa |  D]Y } | t  |      } | r. | j | t    f d   | j   D  f  q. q. W| S(   s3   Return the subset of the list NAMES that match PAT.c         3   s!   |  ] } t  |     Vq d  S(   N(   R   (   t   .0R   (   R   R	   (    s,   lib/python2.7/site-packages/glob2/fnmatch.pys	   <genexpr>\   s    (   R   R   t   appendt   tuplet   groups(	   t   namesR   R   R   R	   t   resultR   R   t   m(    (   R   R	   s,   lib/python2.7/site-packages/glob2/fnmatch.pyR   S   s    	0c         C   s   t  | |  } | |   d k	 S(   s   Test whether FILENAME matches PATTERN, including case.

    This is a version of fnmatch() which doesn't case-normalize
    its arguments.
    N(   R   R   (   R   R   R   R   (    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyR   `   s    c         C   sŻ  d t  |   } } d } x| | k  r˘|  | } | d } | d k rU | d } q | d k rn | d } q | d k r| } | | k  rİ |  | d	 k rİ | d } n  | | k  rÒ |  | d
 k rÒ | d } n  x* | | k  rŝ |  | d
 k rŝ | d } qĠ W| | k r| d } q|  | | !j d d  } | d } | d d	 k r\d | d } n | d d k ryd | } n  d | | f } q | t j |  } q Wd | d S(   sf   Translate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.
    i    t    i   t   *s   (.*)t   ?s   (.)t   [t   !t   ]s   \[s   \s   \\t   ^s   %s([%s])s   (?ms)s   \Z(   t   lent   replaceR   t   escape(   R   t   it   nR   t   ct   jt   stuff(    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyR   j   s8    


(   t   __doc__R   R   t	   functoolsR    t   ImportErrort   compatt   __all__R   t   TrueR   R   R   R   R   R   (    (    (    s,   lib/python2.7/site-packages/glob2/fnmatch.pyt   <module>   s   	)
