o ~_9@sjddlZddlmZddlmZddlmZGdddeZGdddeZd d Zdd d Z ddZ dS)N)map)range)strc@eZdZdZdS) GlobbingErrorz3Something has gone wrong when parsing a glob stringN__name__ __module__ __qualname____doc__r r 5/usr/lib/python3/dist-packages/duplicity/globmatch.pyr!rc@r)FilePrefixErrorz?Signals that a specified file doesn't start with correct prefixNrr r r r r&rrcsb|ddddvrtd|fddttD}|ddkr*d|d<ttt|S) z9Return list of regexps equivalent to prefixes of glob_str/z*Consecutive '/'s found in globbing string cs"g|] }dd|dqS)rNr)join).0i glob_partsr r 4s"z+_glob_get_prefix_regexs..r)splitrrlenlistr glob_to_regex)glob_strprefixesr rr _glob_get_prefix_regexs+s  r FcsttsJddkrdnddkrdddd|r%tjfdd }|d tr=|d td dkrOdd d |ddtfdd}|S)aAReturn a function test_fn(path) which tests whether path matches glob, as per the Unix shell rules, taking as arguments a path, a glob string and include (0 indicating that the glob string is an exclude glob and 1 indicating that it is an include glob, returning: 0 - if the file should be excluded 1 - if the file should be included 2 - if the folder should be scanned for any included/excluded files None - if the selection function has nothing to say about the file Note: including a folder implicitly includes everything within it. Frz/**rTNrcst|tjBS)N)recompileS)r)flagsr r Xsz%select_fn_from_glob..z^%s($|/)z^%s($)**z^(%s)$|cs~|jddkr|jdksJd|jd|jr1s!S|jr/|r-SdSSdkr=|jr=dSdS)Nrrzppath.name should never end in '/' during normal operation for normal paths (except '/' alone) path.name here is z and glob is rr()uc_namematchisdir)path) glob_comp_reglob_comp_re_exactglob_ends_w_slashrinclude scan_comp_rer r test_fnus(  z$select_fn_from_glob..test_fn) isinstancerr! IGNORECASErfindrr )rr1 ignore_casere_compr3r )r%r.r/r0rr1r2r select_fn_from_glob;s*      r9cCstt|tsJdt|d}}}||kr|||||d}}|d}|dkr3|d}|d}n|dkr<|d}nx|d krE|d }no|d kr|}||krY||d vrY|d}||krg||d krg|d}||kr||d kr|d}||kr||d ksq||kr|d}n,|||dd}|d}|dd vrd|dd}|d |d }n|t|}||ks|S)aEReturned regular expression equivalent to shell glob pat Currently only the ?, *, [], and ** expressions are supported. Ranges like [a-z] are currently unsupported. There is no way to quote these special characters. This function taken with minor modifications from efnmatch.py by Donovan Baarda. rrr(rr'z.**z[^/]*?z[^/][z!^]z\[\z\\^N)r4rrreplacer!escape)patrnrescsjstuffr r r rs>      r)F) r!builtinsrrr Exceptionrrr r9rr r r r s     [