flowbber.utils.filter

Utilities for filtering data.

Functions

  • included_in(): Check if the given value is included in the given list of patterns.
  • is_wanted(): Check that the given value is included in the include list and not included
  • filter_dict(): Filter a dictionary using the provided include and exclude patterns.
  • load_filter_file(): Load a “.gitignore”-like file describing excluding (or including) fnmatch
flowbber.utils.filter.included_in(value, patterns)

Check if the given value is included in the given list of patterns.

Parameters
  • value (str) – The value to check for.
  • patterns (list) – List of patterns to check for.
Returns

True in the value is included, False otherwise.

Return type

bool

flowbber.utils.filter.is_wanted(value, include, exclude)

Check that the given value is included in the include list and not included in the exclude list.

Parameters
  • value (str) – The value to check for.
  • include (list) – List of patterns of values to include.
  • exclude (list) – List of patterns of values to exclude.
Returns

True in the value is wanted, False otherwise.

Return type

bool

flowbber.utils.filter.filter_dict(data, include, exclude, joinchar='.')

Filter a dictionary using the provided include and exclude patterns.

Parameters
  • data (dict) – The data to filter (dict or OrderedDict, type is respected).
  • include (list) – List of patterns of key paths to include.
  • exclude (list) – List of patterns of key paths to exclude.
  • joinchar (str) – String used to join the keys to form the path.
Returns

The filtered dictionary.

Return type

dict or OrderedDict

flowbber.utils.filter.load_filter_file(filepath, encoding='utf-8')

Load a “.gitignore”-like file describing excluding (or including) fnmatch patterns.

Empty lines and comments (#) are supported. Patterns returned are unique and in the same order as described in the file.

Parameters
  • filepath (str) – Path to the file. Path objects are also supported (and preferred).
  • encoding (str) – Encoding to use to decode the file.
Returns

List of unique patterns in the file.

Return type

list