ninjecto.utils.types

Utilities to convert string to other data types.

Functions

ninjecto.utils.types.booleanize(value)

Convert a string to a boolean.

Raises
ValueError if unable to convert.
Parameters
value (str) – String to convert.
Returns
True if value in lowercase matches “true” or “yes”; False if value in lowercase matches “false”or “no”.
Return type
bool
ninjecto.utils.types.autocast(value)

Try to convert a string to some basic data types.

Parameters
value (str) – The string to try to convert.
Returns
This function will try to convert a string to a:
  • datetime, if string is in ISO8601 with timezone format.
  • int, if succeeds.
  • float, if succeeds.
  • boolean, using the booleanize() function.

If all the above fails, the source string is returned as-is.

Return type
Any of the above.