o $a @sUdZddlZddlmZmZmZmZmZmZm Z ddl m Z de de fddZ d ee deee geee ffd d ZGd d d ZedgZiZee e fed<de de deee fddZdee de dee fddZdS)z sphinx.util.matching ~~~~~~~~~~~~~~~~~~~~ Pattern-matching utility functions for Sphinx. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)CallableDictIterableListMatchOptionalPattern) canon_pathpatreturncCstdt|}}d}||kr||}|d7}|dkr1||kr,||dkr,|d7}|d}n|d}n|dkr:|d}nx|d kr|}||krN||d krN|d7}||kr\||d kr\|d7}||krt||d krt|d7}||krt||d ksf||kr}|d }n5|||d d}|d}|dd krd|dd}n |ddkrd |}d||f}n|t|7}||ks |dS)zTranslate a shell-style glob pattern to a regular expression. Adapted from the fnmatch module, but enhanced so that single stars don't match slashes. r*z.*z[^/]*?z[^/][!]z\[\z\\z^/N^z%s[%s]$)lenreplacereescape)r inrescjstuffr 6/usr/lib/python3/dist-packages/sphinx/util/matching.py_translate_patternsB      #r"patternscCsdd|DS)NcSsg|] }tt|jqSr )rcompiler"match.0r r r r! @sz$compile_matchers..r )r#r r r!compile_matchers?sr)c@sJeZdZdZdeeddfddZdedefdd Zdedefd d Z dS) MatcherzA pattern matcher for Multiple shell-style glob patterns. Note: this modifies the patterns to work with copy_asset(). For example, "**/index.rst" matches with "index.rst" r#r NcCs dd|D}t|||_dS)NcSs"g|] }|dr|ddqS)z**/N) startswithr&r r r!r(Ks"z$Matcher.__init__..)r)r#)selfr#expandedr r r!__init__JszMatcher.__init__stringcCs ||SN)r%r-r0r r r!__call__Ns zMatcher.__call__cs ttfdd|jDS)Nc3s|]}|VqdSr1r r&r0r r! Ssz Matcher.match..)r anyr#r2r r4r!r%Qsz Matcher.match) __name__ __module__ __qualname____doc__rstrr/boolr3r%r r r r!r*Cs r*z**/.* _pat_cachenamecCs(|tvr tt|t|<t||S)zbReturn if name matches the regular expression (pattern) ``pat```. Adapted from fnmatch module.)r=rr$r"r%)r>r r r r!patmatch\sr?namescCs2|tvr tt|t|<t|j}tt||S)zReturn the subset of the list ``names`` that match the regular expression (pattern) ``pat``. Adapted from fnmatch module. )r=rr$r"r%listfilter)r@r r%r r r! patfilterds rC)r:rtypingrrrrrrrsphinx.util.osutilr r;r"r)r*DOTFILESr=__annotations__r?rCr r r r!s $ ,. "