String tools
| FUNCTION | DESCRIPTION |
|---|---|
interpret_as_bool |
Interpret a boolean or a string representation of a boolean as a boolean |
sanitize_string |
Make string safe to be used in file/folder names and subprocess commands. |
validate_cmd |
Assert that the provided |
Functions:¶
interpret_as_bool(value)
¶
Interpret a boolean or a string representation of a boolean as a boolean value.
Accepts either a boolean (True or False) or a case-insensitive string
representation of a boolean ("true" or "false").
Returns the corresponding boolean value.
Source code in fractal_server/string_tools.py
sanitize_string(value)
¶
Make string safe to be used in file/folder names and subprocess commands.
Make the string lower-case, and replace any special character with an underscore, where special characters are:
>>> string.punctuation
'!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~'
>>> string.whitespace
' \t\n\r\x0b\x0c'
| PARAMETER | DESCRIPTION |
|---|---|
|
Input string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Sanitized value |
Source code in fractal_server/string_tools.py
validate_cmd(command, *, allow_char=None, attribute_name='Command')
¶
Assert that the provided command does not contain any of the forbidden
characters for commands
(fractal_server.string_tools.NOT_ALLOWED_FOR_COMMANDS)
| PARAMETER | DESCRIPTION |
|---|---|
|
command to validate.
TYPE:
|
|
chars to accept among the forbidden ones
TYPE:
|
|
Name of the attribute, to be used in error message.
TYPE:
|