o ?Og@sdZddlZddlZddlZddlZddlZddlZddlZgdZddddddZ dddddd Z d d Z d d Z ddZ ddZddZddZddZddZddZddZddZd d!Zed"Zed#Zd$d%Zd&d'Zd(d)Zd*d+Zejeed,dBZ dS)-zFilename globbing utility.N)globiglobescapeFroot_dirdir_fd recursivecCstt||||dS)ayReturn 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 recursive is true, the pattern '**' will match any files and zero or more directories and subdirectories. r)listr)pathnamerrrr +/opt/alt/python310/lib64/python3.10/glob.pyr s rcCstd||td|||||durt|}n|dd}t||||d}|r4|rRt|ddrRzt|}|rEt|f|}W|SW|St yQY|Sw|S)aReturn 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 recursive is true, the pattern '**' will match any files and zero or more directories and subdirectories. z glob.globz glob.glob/2NrF) sysauditosfspath_iglob _isrecursivenext itertoolschain StopIteration)r rrritsr r r rs&    rc cstj|\}}t|s-|rJ|r tt|||r|VdStt|||r+|VdS|sM|rAt|rAt||||EdHdSt ||||EdHdS||kr^t|r^t ||||d}n|g}t|rq|rnt|rnt}nt }nt }|D]}|t|||||D] } tj || VqqudS)NT) rpathsplit has_magic_lexists_join_isdirr_glob2_glob1r_glob0join) r rrrdironlydirnamebasenamedirsZ glob_in_dirnamer r r r5s<  rcCs.t|||}t|sdd|D}t||S)Ncss|] }t|s|VqdSN) _ishidden).0xr r r `sz_glob1..)_listdirr*fnmatchfilter)r%patternrr$namesr r r r!]s  r!cCs2|rtt|||r |gSgSt||r|gSgSr))rrr)r%r&rr$r r r r"cs r"cCt||ddSNF)r"r%r1r r r glob0pr6cCr3r4)r!r5r r r glob1sr7r8ccs2t|sJ|ddVt|||EdHdS)Nr)r _rlistdir)r%r1rr$r r r r ys r c cs,zd}d}|dur"|rtj|t|d}}n|}t|tr!tj}n|r'|}nt|tr3ttjd}ntj}zJt|-}|D]"}z|rH|rW|durS||j Vn|j VWq?t yaYq?wWdn1slwYW|dur~t |WdSWdS|durt |wwt yYdSw)NrASCII) ropen_dir_open_flags isinstancebytesfsencodecurdirscandiris_dirr(OSErrorclose)r%rr$fdr@argrentryr r r _iterdirsN        rIcCs>tt||| }t|WdS1swYdSr)) contextlibclosingrIr )r%rr$rr r r r.s$r.ccsZt|||}|D]!}t|s*|V|rt||n|}t|||D]}t||Vq!q dSr))r.r*rr9)r%rr$r2r,ryr r r r9s r9c CsB|dur tj|Sz tj||dWdSttfy YdSw)Nr:FT)rrlexistslstatrD ValueError)r rr r r rs rc CsL|dur tj|Sz tj||d}Wn ttfyYdSwt|jS)Nr:F)rrisdirstatrDrOS_ISDIRst_mode)r rstr r r rs  rcCs|r|s|p|Stj||Sr))rrr#)r%r&r r r rsrz([*?[])s([*?[])cCs.t|trt|}|duSt|}|duSr))r>r?magic_check_bytessearch magic_check)rmatchr r r rs   rcCs |ddvS)Nr)..r )rr r r r*s r*cCst|tr |dkS|dkS)Ns**z**)r>r?)r1r r r rs rcCsBtj|\}}t|trtd|}||Std|}||S)z#Escape all special characters. s[\1]z[\1])rr splitdriver>r?rUsubrW)r Zdriver r r rs    r O_DIRECTORY)!__doc__rJrrer/rrQr__all__rrrr!r"r6r8r rIr.r9rrrcompilerWrUrr*rrO_RDONLYgetattrr=r r r r s< ( "