Validation¶
flutils offers the following validation functions.
flutils.validators.
validate_identifier
(identifier, allow_underscore=True)[source]¶Validate the given string is a proper identifier.
This validator will also raise an error if the given identifier is a keyword or a builtin identifier.
Parameters:
- identifier (
str
orUserString
) – The value to be tested.- allow_underscore (
bool
, optional) – A value ofFalse
will raise an error when theidentifier
has a value that starts with an underscore_
. (UseFalse
when validating potentialnamedtuple
keys) Defaults to:True
.Raises:
SyntaxError
– If the given identifier is invalid.TypeError
– If the given identifier is not astr
orUserString
.Return type: Example
>>> from flutils.validators import validate_identifier >>> validate_identifier('123') SyntaxError: The given 'identifier', '123', cannot start with a number