Data Type Checkers

Other standard datatypes have their own checkers.

BoolCheck — Boolean Validation

BoolCheck checks against a number of boolean-equivalent expressions.

class xcheck.BoolCheck(name[, none_is_false])

The optional attribute on top of the standard attributes:

none_is_false [default True]

If True, accepts None or “None” and treates as False.

BoolCheck accepts the following values and normalizes them as True

  • True, “TRUE”, “True”, “true”, “T”, “t”, “YES”, “Yes”, “yes”, “Y”, “y”, “1”

BoolCheck accepts the following values and normalizes them as False

  • False, “FALSE”, “False”, “false”, “F”, “f”, “NO”, “No”, “no”, “N”, “n”, “0”

IntCheck — Integer Validation

class xcheck.IntCheck(name, **kwargs)

IntCheck(name[, min, max])

IntCheck checks attributes and elements containing integer data.

Parameters:
  • name (string) – name of the xml tag
  • min (integer or NINF) – minimum value for the checker
  • max (integer or INF) – maximum value for the checker

The max and min attributes are inclusive, they default to NINF and INF, respectively.

Calling an IntCheck instance supports the as_string keyword.

The following example shows the many ways IntCheck accepts data:

from xcheck import IntCheck, ET

value = IntCheck('value', min=2, max=12)
text = '<value>5</value>'
node = ET.fromstring(text)

print value(9)
print value('9')
print value('9.0')
print value(text)
print value(node)

All of the above lines will print True.

DecimalCheck — Float Validation

class xcheck.DecimalCheck(name, **kwargs)

DecimalCheck(name[, min, max])

DicimalCheck checks attributes and elements containing float data.

Parameters:
  • name (string) – name of the xml tag
  • min (integer or NINF) – minimum value for the checker
  • max (integer or INF) – maximum value for the checker

The max and min attributes are inclusive, they default to NINF and INF, respectively.

DateTimeCheck — DateTime validation

class xcheck.DatetimeCheck(name, **kwargs)

DateTimeCheck(name[, keywords]) Checks date and time formatted strings, date objects, and time objects.

Parameters:
  • allow_none (Boolean (default False)) – allows NoneType or equivalent string to be treated as False
  • format (str (default “%a %b %d %H:%M:%S %Y”)) – the format to use while checking (see Python documentation)
  • formats (list of strings) – several string formats for alternate use
  • formatlist – alias for formats
  • min_datetime (datetime.date (default Jan. 1, 1900)) – minimum date
  • max_datetime (datetime.date (default datetime.date.max)) – maximum date

Additional attributes in __call__

Parameters:
  • as_datetime – normalizes the value to a datetime.datetime object
  • as_struct – normalizes the value to atime.struct_time object
  • as_string – normalzes the value to a string
DateTimeCheck ignores the basic use of normalize. If any of as_datetime,
as_struct, or as_string are true, normalize will be set to True.