watson.validators.string

class watson.validators.string.Csrf(token=None, message='Cross-Site request forgery attempt detected, invalid token specified "{token}"')[source]

Validates a csrf token.

Example:

validator = Csrf()
validator('submitted token')
__init__(token=None, message='Cross-Site request forgery attempt detected, invalid token specified "{token}"')[source]
class watson.validators.string.Length(min=-1, max=-1, message='"{value}" does not meet the required length')[source]

Validates the length of a string.

Example:

validator = Length(1, 10)
validator('Test')  # True
validator('Testing maximum')  # raises ValueError
__init__(min=-1, max=-1, message='"{value}" does not meet the required length')[source]

Initializes the validator.

Min, max, length are interpolated into the message.

Parameters:
  • min (int) – The minimum length of the string.
  • max (int) – The maximum length of the string.
  • message (string) – The message to be used if the validator fails.
class watson.validators.string.RegEx(regex, flags=0, message='"{value}" does not match pattern "{pattern}"')[source]

Validates a value based on a regular expression.

Example:

validator = RegEx('Match')
validator('Match')  # True
validator('Other')  # raises ValueError
__init__(regex, flags=0, message='"{value}" does not match pattern "{pattern}"')[source]
class watson.validators.string.Required(message='Value is required')[source]

Validates whether or not a value exists.

Example:

validator = Required()
validator('Test')  # True
validator('')  # raises ValueError
__init__(message='Value is required')[source]