B @`&@sdZddlmZddlZddlZddlmZddlmZddl m Z dZ Gd d d e Z e d e Gd d d e Ze dedS)z This module implements Git's wildmatch pattern matching which itself is derived from Rsync's wildmatch. Git uses wildmatch for its ".gitignore" files. )unicode_literalsN)util)unicode) RegexPatternlatin1c@s8eZdZdZdZeddZeddZeddZ d S) GitWildMatchPatternzX The :class:`GitWildMatchPattern` class represents a compiled Git wildmatch pattern. c Csbt|trt}n(t|tr*t}|t}ntd||}|drVd}d}n|dkrjd}d}n|r4|drd}|dd}nd}|d r|dd}| d}|d s|d =n:t |dkst |d kr|ds|d d kr| d d n|d st |dkrd |d <dg}d}t |d}xt |D]\} } | d kr| d krl| |krl| dn>| d kr| dd}n$| |kr| dn| dd}nl| dkr|r| d| dd}nB|r| d| || | |kr|dkr| dd}q:W| dd|}nd}d}|dk rZ|tkrZ|t}||fS)a Convert the pattern into a regular expression. *pattern* (:class:`unicode` or :class:`bytes`) is the pattern to convert into a regular expression. Returns the uncompiled regular expression (:class:`unicode`, :class:`bytes`, or :data:`None`), and whether matched files should be included (:data:`True`), excluded (:data:`False`), or if it is a null-operation (:data:`None`). z-pattern:{!r} is not a unicode or byte string.#N/!FT\rrz**^z.+z(?:.+/)?z/.*z(?:/.+)?*z[^/]+z(?:/.*)?$) isinstancerbytesdecode_BYTES_ENCODING TypeErrorformatstrip startswithsplitleninsert enumerateappend_translate_segment_globjoinencode) clspattern return_typeregexincludeZ pattern_segsoutputZ need_slashendisegr r B/tmp/pip-unpacked-wheel-sew_71nq/pathspec/patterns/gitwildmatch.pypattern_to_regexsx                            z$GitWildMatchPattern.pattern_to_regexcCsd}d}dt|}}xb||krz||}|d7}|rLd}|t|7}q|dkrZd}q|dkrl|d7}q|d kr~|d 7}q|d krj|}||kr||d kr|d7}||kr||d kr|d7}x ||kr||d kr|d7}qW||kr`|d7}d }||d kr|d7}|d7}n||dkr:|d7}|d7}||||dd7}||7}|}n|d7}q|t|7}qW|S)a Translates the glob pattern to a regular expression. This is used in the constructor to translate a path segment glob pattern to its corresponding regular expression. *pattern* (:class:`str`) is the glob pattern. Returns the regular expression (:class:`str`). Frrr rTrz[^/]*?z[^/][r ]rz\^z\\z\[)rreescapereplace)r%r3r'r+r*charjexprr r r-r!sL       z+GitWildMatchPattern._translate_segment_globcsddfdd|DS)z Escape special characters in the given string. *s* (:class:`unicode` or :class:`bytes`) a filename or a string that you want to escape, usually before adding it to a `.gitignore` Returns the escaped string (:class:`unicode`, :class:`bytes`) z[]!*#?rc3s"|]}|krd|n|VqdS)rNr ).0x)meta_charactersr r- 'sz-GitWildMatchPattern.escape..)r")sr )r:r-r3s zGitWildMatchPattern.escapeN) __name__ __module__ __qualname____doc__ __slots__ classmethodr. staticmethodr!r3r r r r-rs   jrZ gitwildmatchcs<eZdZdZfddZeddZefddZZ S)GitIgnorePatternz The :class:`GitIgnorePattern` class is deprecated by :class:`GitWildMatchPattern`. This class only exists to maintain compatibility with v0.4. cs|tt|j||S)z Warn about deprecation. ) _deprecatedsuperrD__init__)selfargskw) __class__r r-rG2szGitIgnorePattern.__init__cCstjdtdddS)z Warn about deprecation. z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.) stacklevelN)warningswarnDeprecationWarningr r r r-rE9szGitIgnorePattern._deprecatedcs|tt|j||S)z Warn about deprecation. )rErFrDr.)r$rIrJ)rKr r-r.@sz!GitIgnorePattern.pattern_to_regex) r=r>r?r@rGrCrErBr. __classcell__r r )rKr-rD,s  rDZ gitignore)r@ __future__rr2rNrrcompatrr%rrrZregister_patternrDr r r r-s