Validation Utilities partis.pyproj.validate#

exception ValidationWarning[source]#

Bases: RuntimeWarning

exception ValidationError(msg, doc_root=None, doc_file=None, doc_path=None)[source]#

Bases: ValueError

General validation error

Parameters:

msg (str) – Error message

exception RequiredValueError(msg, doc_root=None, doc_file=None, doc_path=None)[source]#

Bases: ValidationError

exception ValidDefinitionError(msg, doc_root=None, doc_file=None, doc_path=None)[source]#

Bases: ValidationError

exception ValidPathError(msg, doc_root=None, doc_file=None, doc_path=None)[source]#

Bases: ValidationError

File is not valid

exception FileOutsideRootError(msg, doc_root=None, doc_file=None, doc_path=None)[source]#

Bases: ValidPathError

File path is outside a desired root directory

class validating(key=None, root=None, file=None)[source]#

Bases: object

Context manager to append information to a ValidationError as it propagates

Intermediate frames for internal validating routines, except for the first and last frame, are filtered out of any tracebacks.

Parameters:
  • key (None | str) – Insert the current key being validated to the head of the ‘doc_path’

  • root (None | Mapping | Sequence) – Set the root document being validated as ‘doc_root’

  • file (None | str) – Set a file as the source of the data being validated as ‘doc_file’

See also

  • ValidationError

class Optional[source]#

Bases: Special

Optional value

class OptionalNone[source]#

Bases: Special

Optional value, but is set to None if not initially set

class Required[source]#

Bases: Special

Required value

class NotSet[source]#

Bases: Special

Special value indicating a value is not set

validate(val, default, validators)[source]#

Internal method to apply default value and validators

class Validator(*args, default=NotSet)[source]#

Bases: object

Validates a value

class Restricted(*options)[source]#

Bases: Validator

Restricts a value to one of listed options

valid(*validators, default=NotSet)[source]#

Casts list of objects to Validator, if needed

union(*validators)[source]#

Value must pass at least one of listed validators

restrict(*options)[source]#

Restricts a value to one of listed options

valid_keys(obj, key_valid=None, value_valid=None, item_valid=None, allow_keys=None, require_keys=None, min_keys=None, wedge_keys=None, mutex_keys=None, deprecate_keys=None, forbid_keys=None, default=None, proxy_keys=None)[source]#

Check that a mapping does not contain un-expected keys

Parameters:
  • obj (Mapping) – Mapping object to validate

  • key_valid (None | callable) – Validates all keys

  • value_valid (None | callable) – Validates all values

  • item_valid (None | callable) – Validates all (key,value) pairs

  • allow_keys (None | list[str]) – Mapping may not contain keys that are not listed.

  • require_keys (None | list[str]) – Mapping must contain all listed keys.

  • min_keys (None | list[ list[str] ]) – Mapping must contain at least one key from each list.

  • wedge_keys (None | list[ list[str] ]) – Mapping must contain either none or all of the listed keys.

  • mutex_keys (None | list[ list[str] ]) – Mapping may contain at most one key from each list.

  • deprecate_keys (None | list[ (str, None | str | Required) ]) – First key is marked as deprecated and removed from the Mapping. If new key is given, the value is remapped to the new key. If new key is Required, an error is raised, otherwise a deprecation warning is reported.

  • forbid_keys (None | list[str]) – Mapping must not contain any of the listed keys.

  • default (None | Mapping[object, object | type | Validator]) – Default value or validator for given keys.

  • proxy_keys (None | list[ list[str] ]) –

class valid_dict(*args, **kwargs)[source]#

Bases: Mapping

Validated Mapping

_proxy_key#

If initialized with a value that is not a Mapping, this key is assigned the value before performing validation.

Type:

None | str

_key_valid#

Validates all keys

Type:

None | callable

_value_valid#

Validates all values

Type:

None | callable

_item_valid#

Validates all (key,value) pairs

Type:

None | callable

_allow_keys#

Mapping may not contain keys that are not listed.

Type:

None | list[str]

_require_keys#

Mapping must contain all listed keys.

Type:

None | list[str]

_min_keys#

Mapping must contain at least one key from each list.

Type:

None | list[ list[str] ]

_wedge_keys#

Mapping must contain either none or all of the listed keys.

Type:

None | list[ list[str] ]

_mutex_keys#

Mapping may contain at most one key from each list.

Type:

None | list[ list[str] ]

_deprecate_keys#

First key is marked as deprecated and removed from the Mapping. If new key is given, the value is remapped to the new key. If new key is Required, an error is raised, otherwise a deprecation warning is reported.

Type:

None | list[ (str, None | str | Required) ]

_forbid_keys#

Mapping must not contain any of the listed keys.

Type:

None | list[str]

_default#

Default value or validator for given keys.

Type:

None | Mapping[object, object | type | Validator]

_validator#

General validator for entire Mapping after above constraints are satisfied.

Type:

None | Validator

See also

keys() a set-like object providing a view on D's keys[source]#
values() an object providing a view on D's values[source]#
items() a set-like object providing a view on D's items[source]#
get(k[, d]) D[k] if k in D, else d.  d defaults to None.[source]#
class valid_list(vals=None)[source]#

Bases: list

Validated list

clear()[source]#

Remove all items from list.

pop(*args, **kwargs)[source]#

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

append(val)[source]#

Append object to the end of the list.

extend(vals)[source]#

Extend list by appending elements from the iterable.

mapget(obj, path, default=None)[source]#

Convenience method for extracting a value from a nested mapping