³ò
OÉcIc           @   sï   d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 f  d „  ƒ  YZ d f  d „  ƒ  YZ d e	 i f d „  ƒ  YZ d S(   s³   Iterate exactly the requested files in a directory

Parses includes and excludes to yield correct files.  More
documentation on what this code does can be found on the man page.

iÿÿÿÿ(   t
   generatorsNt   SelectErrorc           B   s   e  Z d  Z RS(   s(   Some error dealing with the Select class(   t   __name__t
   __module__t   __doc__(    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR       s   t   FilePrefixErrorc           B   s   e  Z d  Z RS(   s?   Signals that a specified file doesn't start with correct prefix(   R   R   R   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   $   s   t   GlobbingErrorc           B   s   e  Z d  Z RS(   s3   Something has gone wrong when parsing a glob string(   R   R   R   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   (   s   t   Selectc           B   sb  e  Z d  Z e i d e i e i Bƒ Z d „  Z d$ d „ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d$ d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d  „  Z' d! „  Z( d" „  Z) d# „  Z* RS(%   s.  Iterate appropriate RPaths in given directory

	This class acts as an iterator on account of its next() method.
	Basically, it just goes through all the files in a directory in
	order (depth-first) and subjects each file to a bunch of tests
	(selection functions) in order.  The first test that includes or
	excludes the file means that the file gets included (iterated) or
	excluded.  The default is include, so with no tests we would just
	iterate all the files in the directory in order.

	The one complication to this is that sometimes we don't know
	whether or not to include a directory until we examine its
	contents.  For instance, if we want to include all the **.py
	files.  If /home/ben/foo.py exists, we should also include /home
	and /home/ben, but if these directories contain no **.py files,
	they shouldn't be included.  For this reason, a test may not
	include or exclude a directory, but merely "scan" it.  If later a
	file in the directory gets included, so does the directory.

	As mentioned above, each test takes the form of a selection
	function.  The selection function takes an rpath, and returns:

	None - means the test has nothing to say about the related file
	0 - the file is excluded by the test
	1 - the file is included
	2 - the test says the file (must be directory) should be scanned

	Also, a selection function f has a variable f.exclude which should
	be true iff f could potentially exclude some file.  This is used
	to signal an error if the last function only includes, which would
	be redundant and presumably isn't what the user intends.

	s   (.*[*?[\\]|ignorecase\:)c         C   s?   t  | t i ƒ p t ‚ g  |  _ | |  _ |  i i |  _ d S(   s0   Select initializer.  rpath is the root directoryN(   t
   isinstancet   rpatht   RPatht   AssertionErrort   selection_functionst   patht   prefix(   t   selft   rootrp(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   __init__R   s    		c            s^   | p ˆ  i  } n ˆ  i i ƒ  ˆ  i ˆ  i | ƒ ˆ  _ ˆ  i i ˆ  _ ‡  f d †  ˆ  _ ˆ  S(   s¬   Initialize more variables, get ready to iterate

		Selection function sel_func is called on each rpath and is
		usually self.Select.  Returns self just for convenience.

		c              s   ˆ  S(    (    (    (   R   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   <lambda>d   s    (   R   R	   t   setdatat   Iterate_fastt   itert   nextt   __iter__(   R   t   sel_func(    (   R   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   set_iterY   s     c      
   #   sH  ‡ f d †  ‰ ‡  ‡ ‡ f d †  } ˆ Vˆ i  ƒ  p d Sn | ˆ ƒ g } g  } xî | oæ y | d i ƒ  \ ‰ } Wn5 t j
 o) | i ƒ  | o | i ƒ  qV qV n X| d j oR | o x | D] } | VqÊ W| 2n ˆ Vˆ i  ƒ  o | i | ˆ ƒ ƒ q?qV | d j o$ | i ˆ ƒ | i | ˆ ƒ ƒ qV qV Wd S(   s*   Like Iterate, but don't recur, saving timec            s$   t  i i d ˆ  i | f |  ƒ d  S(   Nt	   ListError(   t   logt   ErrorLogt   write_if_opent   indext   None(   t   exct   filename(   R	   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   error_handleri   s    c         3   s¢   x› ˆ i  |  ƒ D]Š } t i ˆ |  i | f ƒ } | ob | i ƒ  oU ˆ  | ƒ } | d j o | d f Vqš | d j o | i ƒ  o | d f Vqš q q Wd S(   sè   Generate relevant files in directory rpath

			Returns (rpath, num) where num == 0 means rpath should be
			generated normally, num == 1 means the rpath is a directory
			and should be included iff something inside is included.

			i   i    i   N(   t   listdirt   robustt   check_common_errort   appendt   lstatt   isdir(   R	   R!   t	   new_rpatht   s(   R   R"   R   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   diryieldn   s     	  Niÿÿÿÿi    i   (   R(   R   t   StopIterationt   popR&   (   R   R	   R   R+   t   diryield_stackt   delayed_rp_stackt   valt
   delayed_rp(    (   R   R   R"   R	   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   g   s8       
   	 c         c   s  | | ƒ } | d j o d Snì | d j o? | V| i  ƒ  o) x& |  i | | | ƒ D] } | VqV Wqn  | d j ot | i  ƒ  oc |  i | | | ƒ } y | i ƒ  } Wn t j
 o d Sn X| V| Vx | D] } | Vq× Wqn d p t d t | ƒ f ‚ d S(   s  Return iterator yielding rpaths in rpath

		rec_func is usually the same as this function and is what
		Iterate uses to find files in subdirectories.  It is used in
		iterate_starting_from.

		sel_func is the selection function to use on the rpaths.  It
		is usually self.Select.

		i    Ni   i   s   Invalid selection result %s(   R(   t   iterate_in_dirR   R,   R   t   str(   R   t   rpt   rec_funcR   R*   t   rp2t   iidt   first(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   Iterate“   s,        	  c            s2   ‡  f d †  } t  i | ˆ  i ƒ } | i ƒ  | S(   s'   List directory rpath with error loggingc            s   t  i i d ˆ  |  ƒ g  S(   NR   (   R   R   R   (   R    (   t   dir_rp(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR"   ±   s    (   R$   R%   R#   t   sort(   R   R:   R"   t   dir_listing(    (   R:   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR#   ¯   s    
c         #   su   ‡  f d †  } x_ |  i  ˆ  ƒ D]N } t i | ˆ  i | g ƒ } | o& x# | | | | ƒ D] } | VqZ Wq q Wd S(   s&   Iterate the rpaths in directory rpath.c            s$   t  i i d ˆ  i | f |  ƒ d  S(   NR   (   R   R   R   R   R   (   R    R!   (   R	   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR"   º   s    N(   R#   R$   R%   R&   (   R   R	   R5   R   R"   R!   t   new_rpR4   (    (   R	   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR2   ¸   s      c            sS   ‡  f d †  } t  i t ˆ  g ƒ } x t D] } | | i | ƒ q+ W| i ƒ  d S(   s<   Filter rorp_iter using Select below, removing excluded rorpsc         3   s>   x7 |  D]/ } t  i ˆ  i  i ˆ  i  i | i | i ƒ Vq Wd S(   s<   Return rp iter by adding indicies of rorp_iter to self.rpathN(   R	   R
   t   connt   baseR   t   data(   t	   rorp_itert   rorp(   R   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt	   getrpiterÈ   s     N(   t   rorpitert   IterTreeReducert   FilterIterITRBt   rp_iterR   t   Finish(   R   RA   RC   t   ITRR4   (    (   R   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt
   FilterIterÆ   s      c         C   sk   d } x^ |  i  D]S } | | ƒ } | d j o d Sq | d j o | Sq | d j o
 d } q q Wd S(   sA   Run through the selection functions and return dominant val 0/1/2i    i   i   (   R   (   R   R4   t   scannedt   sft   result(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   Ò   s    
    c      
   C   sÝ  d } y€xy| D]q\ } } | d j o |  i  |  i | d ƒ ƒ q | d j o |  i  |  i | d ƒ ƒ q | d j o |  i  |  i d ƒ ƒ q | d j o |  i  |  i d ƒ ƒ q | d j o |  i  |  i d ƒ ƒ q | d j o |  i  |  i d ƒ ƒ q | d j o. |  i  |  i | | d | ƒ ƒ | d	 7} q | d
 j o1 t |  i  |  i	 | | d | ƒ ƒ | d	 7} q | d j o |  i  |  i
 d ƒ ƒ q | d j o |  i  |  i | d ƒ ƒ q | d j o |  i  |  i d ƒ ƒ q | d j o |  i  |  i | d	 ƒ ƒ q | d j o. |  i  |  i | | d	 | ƒ ƒ | d	 7} q | d j o1 t |  i  |  i	 | | d	 | ƒ ƒ | d	 7} q | d j o |  i  |  i | d	 ƒ ƒ q | d j o |  i  |  i d	 ƒ ƒ q | d j o |  i  |  i d	 ƒ ƒ q | d j o |  i  |  i d	 | ƒ ƒ q | d j o |  i  |  i d | ƒ ƒ q d p t d | ‚ q WWn" t j
 o } |  i | ƒ n X| t | ƒ j p t ‚ |  i ƒ  |  i ƒ  d S(   sÕ  Create selection functions based on list of tuples

		The tuples have the form (option string, additional argument)
		and are created when the initial commandline arguments are
		read.  The reason for the extra level of processing is that
		the filelists may only be openable by the main connection, but
		the selection functions need to be on the backup reader or
		writer side.  When the initial arguments are parsed the right
		information is sent over the link.

		i    s	   --excludes   --exclude-if-presents   --exclude-device-filess   --exclude-symbolic-linkss   --exclude-socketss   --exclude-fifoss   --exclude-filelisti   s   --exclude-globbing-filelists   --exclude-other-filesystemss   --exclude-regexps   --exclude-special-filess	   --includes   --include-filelists   --include-globbing-filelists   --include-regexps   --include-special-filess   --include-symbolic-linkss   --max-file-sizes   --min-file-sizes   Bad selection option %sN(   t   add_selection_funct   glob_get_sft   presence_get_sft   devfiles_get_sft   symlinks_get_sft   sockets_get_sft   fifos_get_sft   filelist_get_sft   mapt   filelist_globbing_get_sfst   other_filesystems_get_sft   regexp_get_sft   special_get_sft   size_get_sfR   R   t   parse_catch_errort   lent   parse_last_excludest   parse_rbdir_exclude(   R   t	   argtuplest	   filelistst   filelists_indext   optt   argt   e(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt	   ParseArgsÜ   st     		 
c         C   s`   t  | t ƒ o! t i i d | |  i f ƒ n, t  t t ƒ o t i i d | ƒ n ‚  d S(   s   Deal with selection error excsÜ   Fatal Error: The file specification
    '%s'
cannot match any files in the base directory
    '%s'
Useful file specifications begin with the base directory or some
pattern (such as '**') which matches the base directory.s*   Fatal Error while processing expression
%sN(   R   R   R   t   Logt
   FatalErrorR   Re   R   (   R   R    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR\   "  s    	c         C   s    |  i  |  i d d ƒ d ƒ d S(   s7   Add exclusion of rdiff-backup-data dir to front of lists   rdiff-backup-datai    i   N(   s   rdiff-backup-data(   RN   t   glob_get_tuple_sf(   R   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR_   2  s    c         C   sE   |  i  o7 |  i  d i o% t i i d |  i  d i f ƒ n d S(   s;   Exit with error if last selection function isn't an excludeiÿÿÿÿsÈ   Last selection expression:
    %s
only specifies that files be included.  Because the default is to
include all files, the expression is redundant.  Exiting because this
probably isn't what you meant.N(   R   t   excludeR   Rg   Rh   t   name(   R   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR^   7  s
    
	c         C   s2   | o |  i  i d | ƒ n |  i  i | ƒ d S(   s6   Add another selection function at the end or beginningi    N(   R   t   insertR&   (   R   R   t   add_to_start(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRN   C  s     c            s’   t  i d | d ƒ ˆ i | | | ƒ \ ‰ } t  i d | d ƒ ˆ i ƒ  d g ‰  ‡  ‡ ‡ f d †  } | p
 | d j | _ d | | _ | S(   s+  Return selection function by reading list of files

		The format of the filelist is documented in the man page.
		filelist_fp should be an (open) file object.
		inc_default should be true if this is an include list,
		false for an exclude list.
		filelist_name is just a string used for logging.

		s   Reading filelist %si   s   Sorting filelist %si    c            s|   xu ˆ  d t  ˆ ƒ j o d  Sn ˆ i |  ˆ ˆ  d ƒ \ } } | o( ˆ  d c d 7<| d  j o q qq n | Sq d  S(   Ni    i   (   R]   R   t   filelist_pair_match(   R4   t   includet   move_on(   t   iR   t
   tuple_list(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   selection_functionY  s       s
   Filelist: (   R   Rg   t   filelist_readR;   Rj   Rk   (   R   t   filelist_fpt   inc_defaultt   filelist_namet   something_excludedRs   (    (   Rq   R   Rr   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRU   H  s    

	
c            sü   d g ‰ ‡  ‡ ‡ f d †  } d g  } } t i o d p d } xˆ | i ƒ  i | ƒ D]q } | p qX n y ˆ i | | ƒ }	 Wn" t j
 o }
 | |
 ƒ qX n X| i |	 ƒ |	 d p
 d } qX qX W| i ƒ  o t	 i
 d ˆ  d ƒ n | | f S(	   s=   Read filelist from fp, return (tuplelist, something_excluded)i    c            sn   ˆ d c d 7<ˆ d d j  oI t  i d |  ˆ  ˆ i f d ƒ ˆ d d j o t  i d d ƒ qj n d S(	   s   Warn if prefix is incorrecti    i   i   s`   Warning: file specification '%s' in filelist %s
doesn't start with correct prefix %s.  Ignoring.i   i   s(   Future prefix errors will not be logged.N(   R   Rg   R   (   R    (   Rw   R   t   prefix_warnings(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   incr_warningsj  s    	t    s   
i   s   Error closing filelist %si   N(   R   t   Globalst   null_separatort   readt   splitt   filelist_parse_lineR   R&   t   closeR   Rg   (   R   Ru   Ro   Rw   Rz   Rx   Rr   t	   separatort   linet   tupleR    (    (   Rw   Ry   R   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRt   g  s&    	
   
 c      	   C   s«   | d  d j o d } | d } n& | d  d j o d } | d } n | i  |  i ƒ p t | ƒ ‚ n | t |  i ƒ } t t d „  | i d ƒ ƒ ƒ } | | f S(   s$  Parse a single line of a filelist, returning a pair

		pair will be of form (index, include), where index is another
		tuple, and include is 1 if the line specifies that we are
		including a file.  The default is given as an argument.
		prefix is the string that the index is relative to.

		i   s   + i   s   - i    c         S   s   |  S(    (    (   t   x(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ”  s    t   /(   t
   startswithR   R   R]   R„   t   filterR   (   R   Rƒ   Ro   R   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR€   ‚  s    	 !c         C   sá   | \ } } | d j o] | | i  j  o d Sn | | i  j o d SqÝ | t | i  ƒ  | i  j o d SqÝ d Snh | d j oB | i  t | ƒ  | j o d	 SqÝ | | i  j  o d
 SqÝ d Sn d p t d | f ‚ d S(   s:  Matches a filelist tuple against a rpath

		Returns a pair (include, move_on).  include is None if the
		tuple doesn't match either way, and 0/1 if the tuple excludes
		or includes the rpath.

		move_on is true if the tuple cannot match a later index, and
		so we should move on to the next tuple in the index.

		i   i    s   Include is %s, should be 0 or 1N(   Ni   (   i   i   (   i   N(   NN(   i    N(   Ni   (   NN(   R   R   R]   R   (   R   R4   t   pairR   Ro   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRn   —  s        c         c   sÂ   t  i d | d ƒ t i o d p d } x | i ƒ  i | ƒ D]y } | p qA n | d  d j o |  i | d d ƒ VqA | d  d j o |  i | d d	 ƒ VqA |  i | | ƒ VqA Wd
 S(   s  Return list of selection functions by reading fileobj

		filelist_fp should be an open file object
		inc_default is true iff this is an include list
		list_name is just the name of the list, used for logging
		See the man page on --[include/exclude]-globbing-filelist

		s   Reading globbing filelist %si   R{   s   
i   s   + i   s   - i    N(   R   Rg   R|   R}   R~   R   RO   (   R   Ru   Rv   t	   list_nameR‚   Rƒ   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRW   °  s    	    c            sY   ˆ  d j p ˆ  d j p t  ‚ |  i i ƒ  ‰ ‡  ‡ f d †  } ˆ  | _ d | _ | S(   s=   Return selection function matching files on other filesystemsi    i   c            s#   |  i  ƒ  ˆ j o d  Sn ˆ  Sd  S(   N(   t	   getdevlocR   (   R4   (   Ro   t   root_devloc(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   Å  s     s   Match other filesystems(   R   R	   R‹   Rj   Rk   (   R   Ro   R   (    (   Ro   RŒ   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRX   Á  s    !
	c            s‚   ˆ d j p ˆ d j p t  ‚ y t i | ƒ ‰  Wn t i d | d ƒ ‚  n X‡  ‡ f d †  } ˆ | _ d | | _ | S(   s0   Return selection function given by regexp_stringi    i   s%   Error compiling regular expression %sc            s#   ˆ  i  |  i ƒ o ˆ Sn d  Sd  S(   N(   t   searchR   R   (   R4   (   t   regexpRo   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   Ô  s     s   Regular expression: %s(   R   t   ret   compileR   Rg   Rj   Rk   (   R   t   regexp_stringRo   R   (    (   RŽ   Ro   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRY   Ì  s    ! 
c            sN   ˆ d j p ˆ d j p t  ‚ ‡  ‡ f d †  } ˆ | _ d ˆ  | _ | S(   s4   Return selection function given by a file if presenti    i   c            s<   |  i  ƒ  o+ |  i ƒ  o |  i ˆ  ƒ i ƒ  o ˆ Sn d  S(   N(   R(   t   readableR&   R'   R   (   R4   (   t   presence_filenameRo   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   à  s    s   Presence file: %s(   R   Rj   Rk   (   R   R“   Ro   R   (    (   R“   Ro   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRP   Ü  s
    !
c            s;   ‡  ‡ f d †  } ˆ | _  ˆ o d p d | | _ | S(   sŸ   Returns a selection function that uses pred to test
		
		RPath is matched if pred returns true on it.  Name is a string
		summarizing the test to the user.

		c            s   ˆ  |  ƒ o ˆ Sn d  S(   N(   R   (   R4   (   t   predRo   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ñ  s     s   include s   exclude (   Rj   Rk   (   R   R”   Ro   Rk   R   (    (   R”   Ro   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt
   gen_get_sfê  s    
c         C   s   |  i  t i i | d ƒ S(   s2   Return a selection function matching all dev filess   device files(   R•   R	   t   RORPatht   isdev(   R   Ro   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRQ   ø  s    c         C   s   |  i  t i i | d ƒ S(   s1   Return a selection function matching all symlinkss   symbolic links(   R•   R	   R–   t   issym(   R   Ro   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRR   ü  s    c         C   s   |  i  t i i | d ƒ S(   s0   Return a selection function matching all socketss   socket files(   R•   R	   R–   t   issock(   R   Ro   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRS      s    c         C   s   |  i  t i i | d ƒ S(   s.   Return a selection function matching all fifoss
   fifo files(   R•   R	   R–   t   isfifo(   R   Ro   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRT     s    c            s8   ‡  f d †  } ˆ  | _  ˆ  o d p d d | _ | S(   s=   Return sel function matching sockets, symlinks, sockets, devsc            sD   |  i  ƒ  p' |  i ƒ  p |  i ƒ  p |  i ƒ  o ˆ  Sn d  Sd  S(   N(   R˜   R™   Rš   R—   R   (   R4   (   Ro   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   
  s    4Ro   Rj   s    special files(   Rj   Rk   (   R   Ro   R   (    (   Ro   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRZ     s    
c            sw   t  | ƒ ‰  ˆ  d j p t ‚ | o ‡  f d †  } n ‡  f d †  } d | _ d | o d p d ˆ  f | _ | S(   s+   Return selection function given by filesizei    c            s   |  i  ƒ  ˆ  j S(    (   t   getsize(   R4   (   t   size(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR     s    c            s   |  i  ƒ  ˆ  j S(    (   R›   (   R4   (   Rœ   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR     s    i   s
   %s size %dt   Maximumt   Minimum(   t   intR   Rj   Rk   (   R   t   min_maxt   sizestrR   (    (   Rœ   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR[     s     	!c            s«   ˆ  d j p ˆ  d j p t  ‚ | d j o ‡  f d †  } n< |  i i | ƒ p |  i | ˆ  ƒ } n |  i | ˆ  ƒ } ˆ  | _ d ˆ  o d p d | f | _ | S(   s.   Return selection function given by glob stringi    i   s   **c            s   ˆ  S(    (    (   R4   (   Ro   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR     s    s   Command-line %s glob: %sRo   Rj   (   R   t   glob_ret   matcht   glob_get_filename_sft   glob_get_normal_sfRj   Rk   (   R   t   glob_strRo   R   (    (   Ro   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRO     s    ! 
c         C   sa   | i  |  i ƒ p t | ƒ ‚ n t t d „  | t |  i ƒ i d ƒ ƒ ƒ } |  i | | ƒ S(   sý   Get a selection function given a normal filename

		Some of the parsing is better explained in
		filelist_parse_line.  The reason this is split from normal
		globbing is things are a lot less complicated if no special
		globbing characters are used.

		c         S   s   |  S(    (    (   R…   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   4  s    R†   (   R‡   R   R   R„   Rˆ   R]   R   Ri   (   R   R!   Ro   R   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR¤   )  s
    	"c            sj   ‡  f d †  } ‡  f d †  } | d j o
 | } n | d j o
 | } n | | _  d ˆ  f | _ | S(   s(   Return selection function based on tuplec            sG   |  i  ˆ  t |  i  ƒ  j p |  i  t ˆ  ƒ  ˆ  j o d Sn d  Sd  S(   Ni   (   R   R]   R   (   R4   (   R„   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   include_sel_func:  s    c            s*   |  i  t ˆ  ƒ  ˆ  j o d Sn d  Sd  S(   Ni    (   R   R]   R   (   R4   (   R„   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   exclude_sel_func@  s    i   i    s   Tuple select %s(   Rj   Rk   (   R   R„   Ro   R§   R¨   R   (    (   R„   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRi   8  s     
 

c            s   | i  ƒ  i d ƒ o d „  } | t d ƒ } n
 d „  } | d |  i | ƒ ƒ ‰  | i d ƒ d j o | | i d ƒ d  } n | d d	 i |  i | ƒ ƒ ƒ ‰ ‡  ‡ f d
 †  } ‡  f d †  } | |  i ƒ p t | ƒ ‚ n | o | Sn | Sd S(   s  Return selection function based on glob_str

		The basic idea is to turn glob_str into a regular expression,
		and just use the normal regular expression.  There is a
		complication because the selection function should return '2'
		(scan) for directories which may contain a file which matches
		the glob_str.  So we break up the glob string into parts, and
		any file which matches an initial sequence of glob parts gets
		scanned.

		Thanks to Donovan Baarda who provided some code which did some
		things similar to this.

		s   ignorecase:c         S   s   t  i |  t  i t  i Bƒ S(    (   R   R   t   It   S(   t   r(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   [  s    c         S   s   t  i |  t  i ƒ S(    (   R   R   Rª   (   R«   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ]  s    s   ^%s($|/)s   **iÿÿÿÿi   s   ^(%s)$t   |c            s>   ˆ  i  |  i ƒ o d Sn  ˆ i  |  i ƒ o d Sn d  Sd  S(   Ni   i   (   R£   R   R   (   R4   (   t   glob_comp_ret   scan_comp_re(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR§   h  s
      c            s#   ˆ  i  |  i ƒ o d Sn d  Sd  S(   Ni    (   R£   R   R   (   R4   (   R­   (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR¨   m  s     N(	   t   lowerR‡   R]   t
   glob_to_ret   findt   joint   glob_get_prefix_resR	   R   (   R   R¦   Ro   t   re_compR§   R¨   (    (   R­   R®   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR¥   K  s     		  c            sŠ   | i  d ƒ ‰  d ˆ  d d !j o t d | ƒ ‚ n t ‡  f d †  t t ˆ  ƒ ƒ ƒ } | d d j o d | d <n t |  i | ƒ S(   s9   Return list of regexps equivalent to prefixes of glob_strR†   t    i   iÿÿÿÿs*   Consecutive '/'s found in globbing string c            s   d  i  ˆ  |  d  ƒ S(   R†   i   (   R²   (   Rq   (   t
   glob_parts(    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ~  s    i    (   R   R   RV   t   rangeR]   R°   (   R   R¦   t   prefixes(    (   R¶   s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR³   w  s     c   	      C   s  d t  | ƒ d } } } xê| | j  oÜ| | | | | d !} } | d } | d j o% | t i | d ƒ } | d } q | d j o | d } | d } q | d	 j o | d
 } q | d j o | d } q | d j o| } | | j  o | | d j o | d } n | | j  o | | d j o | d } n x- | | j  o | | d j o | d } qKW| | j o | d } q| | | !i d d ƒ } | d } | d d j o d | d } n | d | d } q | t i | ƒ } q W| S(   sW  Returned regular expression equivalent to shell glob pat

		Currently only the ?, *, [], and ** expressions are supported.
		Ranges like [a-z] are also currently unsupported.  These special
		characters can be quoted by prepending them with a backslash.

		This function taken with minor modifications from efnmatch.py
		by Donovan Baarda.

		i    Rµ   i   i   s   \iÿÿÿÿs   **s   .*t   *s   [^/]*t   ?s   [^/]t   [s   !^t   ]s   \[s   \\t   ^(   R]   R   t   escapet   replace(	   R   t   patRq   t   nt   rest   cR*   t   jt   stuff(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR°   „  sB     

       
 N(+   R   R   R   R   R   R©   Rª   R¢   R   R   R   R   R9   R#   R2   RJ   R   Rf   R\   R_   R^   RN   RU   Rt   R€   Rn   RW   RX   RY   RP   R•   RQ   RR   RS   RT   RZ   R[   RO   R¤   Ri   R¥   R³   R°   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   -   sH   !		,						
	F																	
	
				,	RJ   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s?   Filter rorp_iter using a Select object, removing excluded rorpsc         C   sL   | |  _  | i |  _ g  |  _ t i t | i |  i g ƒ |  _ d |  _	 d S(   s™   Constructor

		Input is the Select object to use and the iter of rorps to be
		filtered.  The rorps will be converted to rps using the Select
		base.

		i    N(
   RA   R	   t   base_rpt   stored_rorpsRD   RE   RF   R   RI   t   itr_finished(   R   t   selectRA   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ¬  s    			c         C   s   |  S(   N(    (   R   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   »  s    c         C   s²   xŸ |  i  p” y |  i i ƒ  } Wn: t j
 o. |  i o ‚  q |  i i ƒ  d |  _ q Xt i |  i	 i
 |  i	 i | i | i ƒ } |  i | i | | ƒ q W|  i  i d ƒ S(   s$   Return next object, or StopIterationi   i    (   RÇ   RA   R   R,   RÈ   RI   RH   R	   R
   RÆ   R>   R?   R   R@   R-   (   R   t	   next_rorpt   next_rp(    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   ½  s     
 
 (   R   R   R   R   R   R   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRJ   ª  s   		RF   c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÁ   ITRBranch used in above FilterIter class

	The reason this is necessary is because for directories sometimes
	we don't know whether a rorp is excluded until we see what is in
	the directory.

	c         C   s)   | | |  _  |  _ d |  _ d |  _ d S(   sÎ   Initialize FilterIterITRB.  Called by IterTreeReducer.

		select should be the relevant Select object used to test the
		rps.  rorp_cache is the list rps should be appended to if they
		aren't excluded.

		N(   RÉ   t
   rorp_cacheR   t   branch_excludedt
   base_queue(   R   RÉ   RÌ   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyR   Ô  s    	c         C   s   | i  ƒ  S(   N(   R(   (   R   R   RË   RÊ   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   can_fast_processà  s    c         C   sŽ   |  i  o d Sn |  i | ƒ } | d j o> |  i o  |  i i |  i ƒ d |  _ n |  i i | ƒ n | d j p t d | f ‚ d S(   s5   For ordinary files, just append if select is positiveNi   i    s   Unexpected select value %s(   RÍ   RÉ   RÎ   RÌ   R&   R   R   (   R   R   RË   RÊ   R*   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   fast_processã  s    
 
c         C   sn   |  i  | ƒ } | d j o d |  _ nB | d j o |  i i | ƒ n! | d j p
 t | ‚ | |  _ d  S(   Ni    i   i   (   RÉ   RÍ   RÌ   R&   R   RÎ   (   R   R   RË   RÊ   R*   (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyt   start_processî  s      (   R   R   R   R   RÏ   RÐ   RÑ   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pyRF   Ì  s
   			(   R   t
   __future__R    R   t   FilenameMappingR$   R	   R|   R   RD   t	   ExceptionR   R   R   R   RJ   t	   ITRBranchRF   (    (    (    s;   /var/lib/python-support/python2.5/rdiff_backup/selection.pys   <module>   s   Hÿ ÿ "