;ς
ΞΡAHc           @   s   d  Z  d Z d Z d k Z d k Z d k Z d k Z d k l Z	 e
 d  Z d   Z d   Z d   Z d	   Z e d
 j o e   n d S(   s¦   mglob - enhanced file list expansion module

Use as stand-alone utility (for xargs, `backticks` etc.), 
or a globbing library for own python programs. Globbing the sys.argv is something 
that almost every Windows script has to perform manually, and this module is here
to help with that task. Also Unix users will benefit from enhanced modes 
such as recursion, exclusion, directory omission...

Unlike glob.glob, directories are not included in the glob unless specified 
with 'dir:'

'expand' is the function to use in python programs. Typical use
to expand argv (esp. in windows)::

    try:
        import mglob 
        files = mglob.expand(sys.argv[1:])
    except ImportError:
        print "mglob not found; try 'easy_install mglob' for extra features"
        files = sys.argv[1:] 

Note that for unix, shell expands *normal* wildcards (*.cpp, etc.) in argv.
Therefore, you might want to use quotes with normal wildcards to prevent this 
expansion, in order for mglob to see the wildcards and get the wanted behaviour.
Not quoting the wildcards is harmless and typically has equivalent results, though.

Author: Ville Vainio <vivainio@gmail.com>
License: MIT Open Source license

s      This program allows specifying filenames with "mglob" mechanism.
    Supported syntax in globs (wilcard matching patterns)::
    
     *.cpp ?ellowo*                
         - obvious. Differs from normal glob in that dirs are not included.
           Unix users might want to write this as: "*.cpp" "?ellowo*"
     rec:/usr/share=*.txt,*.doc    
         - get all *.txt and *.doc under /usr/share, 
           recursively
     rec:/usr/share
         - All files under /usr/share, recursively
     rec:*.py
         - All .py files under current working dir, recursively
     foo                           
         - File or dir foo
     !*.bak readme*                   
         - readme*, exclude files ending with .bak
     !.svn/ !.hg/ !*_Data/ rec:.
         - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
           Trailing / is the key, \ does not work!
     dir:foo                       
         - the directory foo if it exists (not files in foo)
     dir:*                         
         - all directories in current folder
     foo.py bar.* !h* rec:*.py
         - Obvious. !h* exclusion only applies for rec:*.py.
           foo.py is *not* included twice.
     @filelist.txt
         - All files listed in 'filelist.txt' file, on separate lines.
 s   0.2N(   s   Setc            s  t  |  t  o |  i   }  n t     t    d g  d  }	    d   }
 g  } x£|  D]} t i i t i i |   } | i   i d  oμ | d i d  } t |  d j o | \ } } n t |  d j oK t i i | d	  o | d	 d f \ } } qWd
 | d	 f \ } } n* t |  d	 j o d
 d f \ } } n | i d  } | i |
 |	 | |    q` | i d  o t i i | d  o- | i |
 t | d  i   i     q` | i d  o  i | d  q` | i   i d  o3 | i |
 t t i i t i | d     q` t i i |  o | o: | i |
 t t i i t i | t i! d     q` d | j p
 d | j o/ | i |
 t t i i t i |     q` | i |
 | g   q` W| Sd S(   s&   Expand the glob(s) in flist.
    
    flist may be either a whitespace-separated list of globs/files
    or an array of globs/files.
    
    if exp_dirs is true, directory names in glob are expanded to the files
    contained in them - otherwise, directory names are returned as is.
    
    s   *c         #   s'  g  i  }   D], } | i d  o | d | d  q q ~ } xέ t i |   D]Μ \ }
 }	 } |
 i d d  d } t } x, | D]$ } t i | |  o t } Pq q W| o qS n xa | D]Y } t } x, | D]$ }  t i | |   o t } PqΥ qΥ W| o t i i |
 |  VqΒ qΒ WqS Wd  S(   Ns   /s   *s   \(   s   appends   _[1]s
   denied_sets   ds   endswiths   denied_dirss   oss   walks   ps   dps   dnamess   fnamess   replaces   dp_norms   Falses   denys   deny_pats   fnmatchs   Trues   fs   matcheds   patss   paths   join(   s   ps   patss   deny_pats   denied_dirss   ds   fs   fnamess   denys   _[1]s   dnamess   dps   dp_norms   matched(   s
   denied_set(    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   recfind[   s,    C  	  	c         #   s   x |  D] } t i i |  } |   j o q n   i |  t } x8  D]0 } t i t i i |  |  o t } PqM qM W| o | Vq q Wd  Sd  S(   N(   s   seqs   its   oss   paths   abspaths   ps   done_sets   adds   Falses   denys
   denied_sets   deny_pats   fnmatchs   basenames   True(   s   seqs   denys   its   deny_pats   p(   s   done_sets
   denied_set(    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   once_filtert   s      	s   rec:i   s   =i   i   i    s   .s   ,s   @s   !s   dir:s   ?N("   s
   isinstances   flists
   basestrings   splits   sets   done_sets
   denied_sets   recfinds   once_filters   ress   ents   oss   paths
   expandusers
   expandvarss   lowers
   startswiths   fieldss   lens   pths   patlists   isdirs   pathlists   patss   extends   isfiles   opens   reads
   splitliness   adds   filters   globs   exp_dirss   sep(   s   flists   exp_dirss   done_sets   fieldss   patlists   pths   patss   ress   pathlists   recfinds   once_filters   ents
   denied_set(    (   s   done_sets
   denied_setsG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   expandL   sF    	 		  '-3:/c           C   s-   t  d  t  d d d g  j p t  d  S(   Ns,   *.py ~/.ipython/*.py rec:/usr/share/doc-bases   *.pys   ~/.ipython/*.pys   rec:/usr/share/doc-base(   s   expands   AssertionError(    (    (    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   test°   s    c           C   sA   t  t i  d j  o t GHd  Sn d i t t i d   Gd  S(   Ni   s   
i   (   s   lens   syss   argvs
   globsyntaxs   joins   expand(    (    (    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   mainΆ   s    c         C   s<   d k  l } | i   o | t |   Sn d GHt GHd  S(   N(   s   SLists   Please specify pattern!(   s   IPython.genutilss   SLists   args   strips   expands
   globsyntax(   s   selfs   args   SList(    (    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   mglob_f½   s
    c         C   s   t  t _ |  i d t  d S(   s    register %mglob for IPython s   mglobN(   s
   globsyntaxs   mglob_fs   __doc__s   ips   expose_magic(   s   ip(    (    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   init_ipythonΔ   s     	s   __main__(   s   __doc__s
   globsyntaxs   __version__s   oss   globs   fnmatchs   syss   setss   Sets   sets   Falses   expands   tests   mains   mglob_fs   init_ipythons   __name__(   s   mains   sets   init_ipythons   globs
   globsyntaxs   syss   tests   mglob_fs   fnmatchs   __version__s   oss   expand(    (    sG   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/external/mglob.pys   ?    s   !$d				