Selection Validators

SelectionCheck — Enumerated values

SelectionCheck limits the values that will validate.

SelectionCheck raises two exceptions:

exception NoSelectionError

NoSelectionError is raised if values is an empty list.

exception BadSelectionsError

BadSelectionsError is raised if the values are not string or unicode objects.

class SelectionCheck(*args, values[, ignoreCase, allow_none])
values

values must be a list of strings.

ignoreCase

If True, will validate despite the case of the item being validated.

allow_none

If True, will allow the selection check to accept None

If used as an attribute with required=False, then allow_none will be True

Examples

ch = SelectionCheck('type', values=['fws', 'aide', 'volunteer'])
ch('FWS') # passes
ch('fws') # passes
ch('help') # fails

ListCheck — Multiple Enumerated Values

class ListCheck( *args, [delimiter, values, allowDuplicates, minItems, maxItems, ignoreCase)
Parameters:
  • delimiter (string) – string to separate list items
  • values (list) – acceptable values for the list items
  • callback (func) – function that provides callbacks at check time
  • allow_duplicates – determines if list items must be unique
  • min_items (integer) – minimum number of items that should be in the list
  • max_items (integer) – maximum number of items that should be allowed in the list
  • ignore_case (boolean) – determines if case should matter when validating items
values

If values is an empty list, any text values will pass as long as the other attribute checks pass.

Calling a ListCheck object can have two keyword parameters.

Parameters:
  • normalize – Return a Python list
  • as_string – Return a string representation of the list

The default values for normalize and as_string are both False.

There isn’t much difference between SelectionCheck and ListCheck. Future versions may combine them into one class. A ListCheck object is not much more than a SelectionCheck object that can read more than one item.

New in version 0.7.0: The callback parameter

Table Of Contents

Previous topic

Text Validators

Next topic

Data Type Checkers

This Page