ó
Ý‹]c           @@  sü   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 y d d l
 m Z Wn e k
 r‡ e Z n Xd e f d	 „  ƒ  YZ e ƒ  Z e j Z e j Z [ e j d
 ƒ Z e j d
 ƒ Z d „  Z d „  Z d d „ Z d S(   s   Filename globbing utility.i    (   t   absolute_importN(   t   joini   (   t   fnmatch(   t   imapt   Globberc           B@  s¤   e  Z e e j ƒ Z e e j j ƒ Z e e j j ƒ Z e e j j ƒ Z	 e
 d d  „ Z e
 e
 e e e d d „ Z e
 e
 e e e d d „ Z d „  Z d „  Z RS(   c   
      c@  sÄ   y |  j  | ƒ } Wn t j k
 r, } d SXg  } x | D] } | j | ƒ q: W| | f Vxa | D]Y } t | | g d | ƒ} | s— |  j | ƒ rc x" |  j | | ƒ D] }	 |	 Vqª Wqc qc Wd S(   sì   A simplified version of os.walk (code copied) that uses
        ``self.listdir``, and the other local filesystem methods.

        Because we don't care about file/directory distinctions, only
        a single list is returned.
        Nt   sep(   t   listdirt   ost   errort   appendt   _join_pathst   islinkt   walk(
   t   selft   topt   followlinksR   t   namest   errt   itemst   namet   new_patht   x(    (    s)   lib/python2.7/site-packages/glob2/impl.pyR      s    c         C@  s"   t  |  j | | | | | | ƒ ƒ S(   s…  Return a list of paths matching a pathname pattern.

        The pattern may contain simple shell-style wildcards a la
        fnmatch. However, unlike fnmatch, filenames starting with a
        dot are special cases that are not matched by '*' and '?'
        patterns.

        If ``include_hidden`` is True, then files and folders starting with
        a dot are also returned.
        (   t   listt   iglob(   R   t   pathnamet   with_matchest   include_hiddent	   recursivet
   norm_pathst   case_sensitiveR   (    (    s)   lib/python2.7/site-packages/glob2/impl.pyt   glob0   s    c   	      C@  s8   |  j  | t | | | | ƒ } | r( | St d „  | ƒ S(   s…  Return an iterator which yields the paths matching a pathname
        pattern.

        The pattern may contain simple shell-style wildcards a la
        fnmatch. However, unlike fnmatch, filenames starting with a
        dot are special cases that are not matched by '*' and '?'
        patterns.

        If ``with_matches`` is True, then for each matching path
        a 2-tuple will be returned; the second element if the tuple
        will be a list of the parts of the path that matched the individual
        wildcards.

        If ``include_hidden`` is True, then files and folders starting with
        a dot are also returned.
        c         S@  s   |  d S(   Ni    (    (   t   s(    (    s)   lib/python2.7/site-packages/glob2/impl.pyt   <lambda>U   t    (   t   _iglobt   TrueR   (	   R   R   R   R   R   R   R   R   t   result(    (    s)   lib/python2.7/site-packages/glob2/impl.pyR   ?   s
    c      	   c@  sü   t  | ƒ s- |  j | ƒ r) | d f Vn  d St j j | ƒ \ } } | | k r~ t  | ƒ r~ |  j | t | | | | ƒ }	 n | d f g }	 xh |	 D]` \ } }
 xQ |  j | | | | | | | ƒ D]- \ } } t | | g d | ƒ|
 | f VqÃ Wq” Wd S(   si  Internal implementation that backs :meth:`iglob`.

        ``rootcall`` is required to differentiate between the user's call to
        iglob(), and subsequent recursive calls, for the purposes of resolving
        certain special cases of ** wildcards. Specifically, "**" is supposed
        to include the current directory for purposes of globbing, but the
        directory itself should never be returned. So if ** is the lastmost
        part of the ``pathname`` given the user to the root call, we want to
        ignore the current directory. For this, we need to know which the root
        call is.
        NR   (    (    (	   t	   has_magict   existsR   t   patht   splitR"   t   Falset   resolve_patternR
   (   R   R   t   rootcallR   R   R   R   t   dirnamet   basenamet   dirst
   dir_groupsR   t   groups(    (    s)   lib/python2.7/site-packages/glob2/impl.pyR"   W   s    c         @  sà  t  j d d k r: t | t ƒ r} t t j d ƒ ‰  q} nC t | t ƒ r} t ˆ  t ƒ r} t ˆ  t  j ƒ  pt t  j ƒ  ƒ ‰  n  t	 | ƒ sæ | d k r´ |  j
 ˆ  ƒ râ | d
 f g Sn. |  j t ˆ  | g d ˆ ƒƒ râ | d f g Sg  Sˆ  sø t j ‰  n  yŽ | d k rv| rd g n g  } xN |  j ˆ  d ˆ ƒD]7 \ ‰ }	 ‡  ‡ ‡ f d †  }
 | j t |
 |	 ƒ ƒ q2Wd } n |  j ˆ  ƒ } Wn t j k
 rg  SX| rÇt | ƒ rÇt d	 „  | ƒ } n  t j | | | | ˆ ƒ S(   sw  Apply ``pattern`` (contains no path elements) to the
        literal directory in ``dirname``.

        If pattern=='', this will filter for directories. This is
        a special case that happens when the user's glob expression ends
        with a slash (in which case we only want directories). It simpler
        and faster to filter here than in :meth:`_iglob`.
        i    i   t   ASCIIR!   R   s   **c         @  s$   t  ˆ t ˆ  ƒ d |  g d ˆ ƒS(   Ni   R   (   R
   t   len(   R   (   R,   R   R   (    s)   lib/python2.7/site-packages/glob2/impl.pyR    «   R!   t   *c         S@  s   |  p t  |  ƒ S(   N(   t	   _ishidden(   R   (    (    s)   lib/python2.7/site-packages/glob2/impl.pyR    ¹   R!   (    (    (   t   syst   version_infot
   isinstancet   bytesR   t   curdirt   unicodet   getfilesystemencodingt   getdefaultencodingR%   t   isdirR&   R
   R   t   extendt   mapR   R   R4   t   filterR   (   R   R,   t   patternt   globstar_with_rootR   R   R   R   R   t   entriest   _mkabs(    (   R,   R   R   s)   lib/python2.7/site-packages/glob2/impl.pyR*   „   s8    !"	N(   t   __name__t
   __module__t   staticmethodR   R   R'   R=   R   t   lexistsR&   R)   t   NoneR   R#   R   R   R"   R*   (    (    (    s)   lib/python2.7/site-packages/glob2/impl.pyR      s   			-s   [*?[]c         C@  s:   t  |  t ƒ r! t j |  ƒ } n t j |  ƒ } | d  k	 S(   N(   R7   R8   t   magic_check_bytest   searcht   magic_checkRI   (   R   t   match(    (    s)   lib/python2.7/site-packages/glob2/impl.pyR%   Ç   s    c         C@  s   |  d d d f k S(   Ni    t   .RN   (    (   R'   (    (    s)   lib/python2.7/site-packages/glob2/impl.pyR4   Ï   s    c         C@  s.   t  |  Œ  } | r* t j d | | ƒ } n  | S(   Ns   \/(   R   t   ret   sub(   t   pathsR   R'   (    (    s)   lib/python2.7/site-packages/glob2/impl.pyR
   Ó   s    (   t   __doc__t
   __future__R    R5   R   RO   t   os.pathR   R!   R   t	   itertoolsR   t   ImportErrorR?   t   objectR   t   default_globberR   R   t   compileRL   RJ   R%   R4   RI   R
   (    (    (    s)   lib/python2.7/site-packages/glob2/impl.pyt   <module>   s(   
¬					