î ¼ê[[ ã@s dZddlZddlZddlZddlZddddgZdd„Zejdd d d ƒd d „ƒZdd„Z dd„Z dd„Z dS)a£Filename matching with shell patterns. fnmatch(FILENAME, PATTERN) matches according to the local convention. fnmatchcase(FILENAME, PATTERN) always takes case in account. The functions operate by translating the pattern into a regular expression. They cache the compiled regular expressions for speed. The function translate(PATTERN) returns a regular expression corresponding to PATTERN. (It does not compile it.) éNÚfilterÚfnmatchÚ fnmatchcaseÚ translatecCs1tjj|ƒ}tjj|ƒ}t||ƒS)a½Test whether FILENAME matches PATTERN. Patterns are Unix shell style: * matches everything ? matches any single character [seq] matches any character in seq [!seq] matches any char not in seq An initial period in FILENAME is not special. Both FILENAME and PATTERN are first case-normalized if the operating system requires it. If you don't want this, use fnmatchcase(FILENAME, PATTERN). )ÚosÚpathÚnormcaser)ÚnameÚpat©r ú/usr/lib/python3.4/fnmatch.pyrsÚmaxsizeéÚtypedTcCsXt|tƒr<t|dƒ}t|ƒ}t|dƒ}n t|ƒ}tj|ƒjS)Nz ISO-8859-1)Ú isinstanceÚbytesÚstrrÚreÚcompileÚmatch)r Zpat_strZres_strÚresr r r Ú_compile_pattern&s   rcCs g}tjj|ƒ}t|ƒ}tjtkrcxf|D]"}||ƒr:|j|ƒq:q:Wn9x6|D].}|tjj|ƒƒrj|j|ƒqjqjW|S)z3Return the subset of the list NAMES that match PAT.)rrrrÚ posixpathÚappend)Únamesr Úresultrr r r r r0s    cCst|ƒ}||ƒdk S)zTest whether FILENAME matches PATTERN, including case. This is a version of fnmatch() which doesn't case-normalize its arguments. N)r)r r rr r r r@s cCs´dt|ƒ}}d}x||kr«||}|d}|dkrU|d}q|dkrn|d}q|dkr•|}||kr©||d kr©|d}n||krÒ||d krÒ|d}nx*||krþ||d krþ|d}qÕW||kr|d }q¨|||…jd d ƒ}|d}|dd kred|dd…}n|ddkr‚d |}nd||f}q|tj|ƒ}qW|dS)zfTranslate a shell PATTERN to a regular expression. There is no way to quote meta-characters. rÚéÚ*z.*ú?Ú.ú[ú!ú]z\[ú\z\\ú^Nz%s[%s]z\Z(?ms))ÚlenÚreplacerÚescape)r ÚiÚnrÚcÚjZstuffr r r rJs8             ) Ú__doc__rrrÚ functoolsÚ__all__rÚ lru_cacherrrrr r r r Ú s     $