movement.io.validators.ValidFile#

class movement.io.validators.ValidFile(path, *, expected_permission='r', expected_suffix=NOTHING)[source]#

Class for validating file paths.

Parameters:
  • path (str or pathlib.Path) – Path to the file.

  • expected_permission ({"r", "w", "rw"}) – Expected access permission(s) for the file. If “r”, the file is expected to be readable. If “w”, the file is expected to be writable. If “rw”, the file is expected to be both readable and writable. Default: “r”.

  • expected_suffix (list of str) – Expected suffix(es) for the file. If an empty list (default), this check is skipped.

Raises:
  • IsADirectoryError – If the path points to a directory.

  • PermissionError – If the file does not have the expected access permission(s).

  • FileNotFoundError – If the file does not exist when expected_permission is “r” or “rw”.

  • FileExistsError – If the file exists when expected_permission is “w”.

  • ValueError – If the file does not have one of the expected suffix(es).

__init__(path, *, expected_permission='r', expected_suffix=NOTHING)#

Method generated by attrs for class ValidFile.

Methods

__init__(path, *[, expected_permission, ...])

Method generated by attrs for class ValidFile.

file_exists_when_expected(attribute, value)

Ensure that the file exists (or not) as needed.

file_has_access_permissions(attribute, value)

Ensure that the file has the expected access permission(s).

file_has_expected_suffix(attribute, value)

Ensure that the file has one of the expected suffix(es).

path_is_not_dir(attribute, value)

Ensure that the path does not point to a directory.

Attributes

path

expected_permission

expected_suffix