B x `s@s@dZddlmZddlmZmZmZmZmZGddde Z dS)zR This module provides an object oriented interface for pattern matching of files. )util) Collectioniterkeys izip_longest string_typesunicodec@szeZdZdZddZddZddZdd Zd d Ze d d Z dddZ dddZ dddZ dddZdddZeZdS)PathSpeczd The :class:`PathSpec` class is a wrapper around a list of compiled :class:`.Pattern` instances. cCst|tr|nt||_dS)z Initializes the :class:`PathSpec` instance. *patterns* (:class:`~collections.abc.Collection` or :class:`~collections.abc.Iterable`) yields each compiled pattern (:class:`.Pattern`). N) isinstancerlistpatterns)selfr r 5/tmp/pip-unpacked-wheel-y3tpd19o/pathspec/pathspec.py__init__szPathSpec.__init__cCs2t|tr*t|j|j}tdd|DStSdS)z Tests the equality of this path-spec with *other* (:class:`PathSpec`) by comparing their :attr:`~PathSpec.patterns` attributes. css|]\}}||kVqdS)Nr ).0abr r r &sz"PathSpec.__eq__..N)r rrr allNotImplemented)r otherZpaired_patternsr r r__eq__s zPathSpec.__eq__cCs t|jS)zW Returns the number of compiled patterns this path-spec contains (:class:`int`). )lenr )r r r r__len__*szPathSpec.__len__cCs"t|trt|j|jStSdS)z] Combines the :attr:`Pathspec.patterns` patterns from two :class:`PathSpec` instances. N)r rr r)r rr r r__add__1s zPathSpec.__add__cCs&t|tr|j|j7_|StSdS)zi Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec` instance to this instance. N)r rr r)r rr r r__iadd__;s zPathSpec.__iadd__cs\ttrtts*tdt|sBtd|fdd|D}||S)a[ Compiles the pattern lines. *pattern_factory* can be either the name of a registered pattern factory (:class:`str`), or a :class:`~collections.abc.Callable` used to compile patterns. It must accept an uncompiled pattern (:class:`str`) and return the compiled pattern (:class:`.Pattern`). *lines* (:class:`~collections.abc.Iterable`) yields each uncompiled pattern (:class:`str`). This simply has to yield each line so it can be a :class:`file` (e.g., from :func:`open` or :class:`io.StringIO`) or the result from :meth:`str.splitlines`. Returns the :class:`PathSpec` instance. z%pattern_factory:{!r} is not callable.zlines:{!r} is not an iterable.csg|]}|r|qSr r )rline)pattern_factoryr r _sz'PathSpec.from_lines..)r rrZlookup_patterncallable TypeErrorformat _is_iterable)clsrlinesr )rr from_linesFs   zPathSpec.from_linesNcCstj||d}t|j|S)a Matches the file to this path-spec. *file* (:class:`str` or :class:`~pathlib.PurePath`) is the file path to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns :data:`True` if *file* matched; otherwise, :data:`False`. ) separators)rZnormalize_file match_filer )r filer&Z norm_filer r rr'bs zPathSpec.match_fileccsTt|std|tj||d}t|jt|}x|D]}||Vq>WdS)a  Matches the entries to this path-spec. *entries* (:class:`~collections.abc.Iterable` of :class:`~util.TreeEntry`) contains the entries to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns the matched entries (:class:`~collections.abc.Iterable` of :class:`~util.TreeEntry`). z entries:{!r} is not an iterable.)r&N)rr"r r!Z_normalize_entries match_filesr r)r entriesr&Z entry_mapZ match_pathspathr r r match_entriesrs   zPathSpec.match_entriesccsTt|std|tj||d}t|jt|}x|D]}||Vq>WdS)a  Matches the files to this path-spec. *files* (:class:`~collections.abc.Iterable` of :class:`str; or :class:`pathlib.PurePath`) contains the file paths to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). zfiles:{!r} is not an iterable.)r&N)rr"r r!Znormalize_filesr)r r)r filesr&Zfile_mapZ matched_filesr+r r rr)s   zPathSpec.match_filescCstj|||d}||S)a Walks the specified root path for all files and matches them to this path-spec. *root* (:class:`str`; or :class:`pathlib.PurePath`) is the root directory to search. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. See :func:`~pathspec.util.iter_tree_entries` for more information. *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk symbolic links that resolve to directories. See :func:`~pathspec.util.iter_tree_files` for more information. Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). )on_error follow_links)rZiter_tree_entriesr,)r rootr.r/r*r r rmatch_tree_entriesszPathSpec.match_tree_entriescCstj|||d}||S)a Walks the specified root path for all files and matches them to this path-spec. *root* (:class:`str`; or :class:`pathlib.PurePath`) is the root directory to search for files. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. See :func:`~pathspec.util.iter_tree_files` for more information. *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk symbolic links that resolve to directories. See :func:`~pathspec.util.iter_tree_files` for more information. Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). )r.r/)rZiter_tree_filesr))r r0r.r/r-r r rmatch_tree_filesszPathSpec.match_tree_files)N)N)N)NN)NN)__name__ __module__ __qualname____doc__rrrrr classmethodr%r'r,r)r1r2Z match_treer r r rr s        rN) r6rcompatrrrrrobjectrr r r rs