nvflare.fuel.utils.validation_utils module¶
- class DefaultValuePolicy[source]¶
Bases:
object
Defines policy for how to determine default value
- ALL = 'all'¶
- ANY = 'any'¶
- DISALLOW = 'disallow'¶
- EMPTY = 'empty'¶
- validate_candidate(var_name: str, candidate, base: list, default_policy: str, allow_none: bool)[source]¶
Validate specified candidate against the items in the “base” list, based on specified policy and returns determined value for the candidate.
The value of candidate could have the following cases: 1. Not explicitly specified (Python object None or empty string) In this case, the default_policy decides the final result: - ANY: returns the first item from the base - EMPTY: returns an empty str - ALL or DISALLOW: raise exception - candidate must be explicitly specified
2. A string with special value “@none” to mean “nothing” If allow_none is True, then returns an empty str; otherwise raise exception.
3. A string that is not a special value If it is in the “base”, return it; otherwise raise exception.
All other cases, raise exception.
NOTE: the final value is normalized (leading and trailing white spaces are removed).
- Parameters:
var_name – the name of the “candidate” var from the caller
candidate – the candidate to be validated
base – the base list that contains valid items
default_policy – policy for how to handle default value when “candidates” is not explicitly specified.
allow_none – whether “none” is allowed for candidates.
Returns:
- validate_candidates(var_name: str, candidates, base: list, default_policy: str, allow_none: bool)[source]¶
Validate specified candidates against the items in the “base” list, based on specified policy and returns determined value for the candidates.
The value of candidates could have the following cases: 1. Not explicitly specified (Python object None or empty list []) In this case, the default_policy decides the final result: - ANY: returns a list that contains a single item from the base - EMPTY: returns an empty list - ALL: returns the base list - DISALLOW: raise exception - candidates must be explicitly specified
2. A list of string items In this case, each item in the candidates list must be in the “base”. Duplicates are removed.
3. A string with special value “@all” to mean “all items from the base” Returns the base list.
4. A string with special value “@none” to mean “no items” If allow_none is True, then returns an empty list; otherwise raise exception.
5. A string that is not a special value If it is in the “base”, return a list that contains this item; otherwise raise exception.
- Parameters:
var_name – the name of the “candidates” var from the caller
candidates – the candidates to be validated
base – the base list that contains valid items
default_policy – policy for how to handle default value when “candidates” is not explicitly specified.
allow_none – whether “none” is allowed for candidates.
Returns: