fluentfs.filelike.text_file_iterator.TextFileIterator¶
- class fluentfs.filelike.text_file_iterator.TextFileIterator(it: Iterable[T])¶
Bases:
FileIterator
[TextFile
]- __init__(it: Iterable[T]) None ¶
Methods
__init__
(it)exclude_base
(base_paths)Filter the files by whether their paths don't match some base path(s).
exclude_base_path
(base_paths)Filter the files by whether their paths don't match some base path(s).
exclude_glob
(pattern)Filter the files by whether their paths don't match some glob(s).
exclude_name_regex
(regex)Filter the files by whether their names don't match some regex(es).
exclude_path_regex
(regex)Filter the files by whether their paths don't match some regex(es).
filter
(fun)filter_base
(base_paths)Filter the files by whether their paths match some base path(s).
filter_base_path
(base_paths)Filter the files by whether their paths match some base path(s).
filter_ext
(extension)Filter the files by extension.
filter_extension
(extension)Filter the files by extension.
filter_glob
(pattern)Filter the files by whether their paths match some glob(s).
filter_name_regex
(regex)Filter the files by whether their names match some regex(es).
filter_not_base
(base_paths)Filter the files by whether their paths don't match some base path(s).
filter_not_base_path
(base_paths)Filter the files by whether their paths don't match some base path(s).
filter_not_glob
(pattern)Filter the files by whether their paths don't match some glob(s).
filter_not_name_regex
(regex)Filter the files by whether their names don't match some regex(es).
filter_not_path_regex
(regex)Filter the files by whether their paths don't match some regex(es).
filter_path_regex
(regex)Filter the files by whether their paths match some regex(es).
for_each
(fun)include_base
(base_paths)Filter the files by whether their paths match some base path(s).
include_base_path
(base_paths)Filter the files by whether their paths match some base path(s).
include_ext
(extension)Filter the files by extension.
include_extension
(extension)Filter the files by extension.
include_glob
(pattern)Filter the files by whether their paths match some glob(s).
include_name_regex
(regex)Filter the files by whether their names match some regex(es).
include_or_exclude_base_path
(base_paths, include)Include or exclude all files whose paths match some base path(s).
include_or_exclude_glob
(patterns, include)Include or exclude files that match some glob pattern(s).
include_or_exclude_path_regex
(regex, include)Include or exclude all files match one of the given regexes.
include_path_regex
(regex)Filter the files by whether their paths match some regex(es).
len
()list
()map
(fun)Map the files to their byte counts.
map_cc
()Map the files to their character counts.
Map the files to their character counts.
map_empty_line_count
()map_lc
()Map the files to their line counts.
Map the files to their line counts.
map_name
()Map the files to their names.
map_non_empty_line_count
()map_path
()Map the files to their paths.
map_self
(fun)map_wc
()Map the files to their word counts.
Map the files to their word counts.
max
()min
()reduce
(fun, start)sort
([key])sort_asc
([key])sort_desc
([key])sum
()t
([encoding, raise_on_decode_error])table
(col_names, row_fun)text_file_iterator
([encoding, ...])top_n
(n)- exclude_base(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that don’t match the given base path(s).
- exclude_base_path(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that don’t match the given base path(s).
- exclude_glob(pattern: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some glob(s).
See the documentation of matches_glob for more information.
- Parameters:
pattern – Either a single glob pattern or a list of glob patterns.
- Returns:
A file iterator containing the files that don’t match the given glob(s).
- exclude_name_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their names don’t match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose names don’t match the regex(es).
- exclude_path_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose paths don’t match the regex(es).
- filter_base(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that match the given base path(s).
- filter_base_path(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that match the given base path(s).
- filter_ext(extension: Union[str, List[str]]) TFileIterator ¶
Filter the files by extension.
- Parameters:
extension – Either a single extension or a list of extensions. Note that extensions must be given without the preceding dot, e.g. “txt” instead of “.txt”.
- Returns:
A file iterator containing the files that have the given extension.
- filter_extension(extension: Union[str, List[str]]) TFileIterator ¶
Filter the files by extension.
- Parameters:
extension – Either a single extension or a list of extensions. Note that extensions must be given without the preceding dot, e.g. “txt” instead of “.txt”.
- Returns:
A file iterator containing the files that have the given extension.
- filter_glob(pattern: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some glob(s).
See the documentation of matches_glob for more information.
- Parameters:
pattern – Either a single glob pattern or a list of glob patterns.
- Returns:
A file iterator containing the files that match the given glob(s).
- filter_name_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their names match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose names match the regex(es).
- filter_not_base(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that don’t match the given base path(s).
- filter_not_base_path(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that don’t match the given base path(s).
- filter_not_glob(pattern: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some glob(s).
See the documentation of matches_glob for more information.
- Parameters:
pattern – Either a single glob pattern or a list of glob patterns.
- Returns:
A file iterator containing the files that don’t match the given glob(s).
- filter_not_name_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their names don’t match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose names don’t match the regex(es).
- filter_not_path_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths don’t match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose paths don’t match the regex(es).
- filter_path_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose paths match the regex(es).
- include_base(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that match the given base path(s).
- include_base_path(base_paths: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some base path(s).
See the documentation of matches_base_path for more information.
- Parameters:
base_paths – Either a single base path or a list of base paths.
- Returns:
A file iterator containing the files that match the given base path(s).
- include_ext(extension: Union[str, List[str]]) TFileIterator ¶
Filter the files by extension.
- Parameters:
extension – Either a single extension or a list of extensions. Note that extensions must be given without the preceding dot, e.g. “txt” instead of “.txt”.
- Returns:
A file iterator containing the files that have the given extension.
- include_extension(extension: Union[str, List[str]]) TFileIterator ¶
Filter the files by extension.
- Parameters:
extension – Either a single extension or a list of extensions. Note that extensions must be given without the preceding dot, e.g. “txt” instead of “.txt”.
- Returns:
A file iterator containing the files that have the given extension.
- include_glob(pattern: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some glob(s).
See the documentation of matches_glob for more information.
- Parameters:
pattern – Either a single glob pattern or a list of glob patterns.
- Returns:
A file iterator containing the files that match the given glob(s).
- include_name_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their names match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose names match the regex(es).
- include_or_exclude_base_path(base_paths: Union[str, List[str]], include: bool) TFileIterator ¶
Include or exclude all files whose paths match some base path(s).
This is useful e.g. if you have a scenario where you are given a bunch of directories along with a flag specifying whether they should be excluded or included. Without this function you would potentially have to construct two different function chains for each case.
- Parameters:
base_paths – Either a single base path or a list of base paths.
include – True, to include the matching files, False to exclude them.
- Returns:
A file iterator containing the non-excluded files.
- include_or_exclude_glob(patterns: Union[str, List[str]], include: bool) TFileIterator ¶
Include or exclude files that match some glob pattern(s).
- Parameters:
patterns – Either a single glob pattern or a list of glob patterns.
include – True, to include the matching files, False to exclude them.
- Returns:
A file iterator containing the non-excluded files.
- include_or_exclude_path_regex(regex: Union[str, List[str]], include: bool) TFileIterator ¶
Include or exclude all files match one of the given regexes.
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
include – True, if regexes should be included, False otherwise.
- Returns:
A file iterator containing the non-excluded files.
- include_path_regex(regex: Union[str, List[str]]) TFileIterator ¶
Filter the files by whether their paths match some regex(es).
- Parameters:
regex – Either a single regular expression or a list of regular expressions.
- Returns:
A file iterator containing the files whose paths match the regex(es).
- map_byte_count() FunctionalIterator[int] ¶
Map the files to their byte counts.
- Returns:
A functional iterator containing the byte counts.
- map_cc() FunctionalIterator[int] ¶
Map the files to their character counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().char_count).
- Returns:
A functional iterator containing the character counts.
- map_char_count() FunctionalIterator[int] ¶
Map the files to their character counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().char_count).
- Returns:
A functional iterator containing the character counts.
- map_lc() FunctionalIterator[int] ¶
Map the files to their line counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().line_count).
- Returns:
A functional iterator containing the line counts.
- map_line_count() FunctionalIterator[int] ¶
Map the files to their line counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().line_count).
- Returns:
A functional iterator containing the line counts.
- map_name() FunctionalIterator[str] ¶
Map the files to their names.
- Returns:
A functional iterator containing the file name.
- map_path() FunctionalIterator[str] ¶
Map the files to their paths.
- Returns:
A functional iterator containing the file path.
- map_wc() FunctionalIterator[int] ¶
Map the files to their word counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().word_count).
- Returns:
A functional iterator containing the word counts.
- map_word_count() FunctionalIterator[int] ¶
Map the files to their word counts.
Note that it is implicitly assumed that all the files are valid text files. This function is equivalent to map(lambda file: file.text_file().word_count).
- Returns:
A functional iterator containing the word counts.