Validation¶
flutils offers the following validation functions.
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 (
strorUserString) – The value to be tested.allow_underscore (
bool, optional) – A value ofFalsewill raise an error when theidentifierhas a value that starts with an underscore_. (UseFalsewhen validating potentialnamedtuplekeys) Defaults to:True.- Raises
SyntaxError – If the given identifier is invalid.
TypeError – If the given identifier is not a
strorUserString.- Return type
Example
>>> from flutils.validators import validate_identifier >>> validate_identifier('123') SyntaxError: The given 'identifier', '123', cannot start with a number