string_tools
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'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
Input string |
required |
Returns:
Type | Description |
---|---|
str
|
Sanitized value |
Source code in fractal_server/string_tools.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
slugify_task_name_for_source_v1(task_name)
¶
NOTE: this function is used upon creation of tasks' sources, therefore
for the moment we cannot replace it with its more comprehensive version
from fractal_server.string_tools.sanitize_string
, nor we can remove it.
As of 2.3.1, we are renaming it to slugify_task_name_for_source
, to make
it clear that it should not be used for other purposes.
As of 2.7.0, we are renaming it to slugify_task_name_for_source_v1
, to
make it clear that it is not used for v2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_name |
str
|
|
required |
Return
Slug-ified task name.
Source code in fractal_server/string_tools.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
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)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
str
|
command to validate. |
required |
allow_char |
Optional[str]
|
chars to accept among the forbidden ones |
None
|
attribute_name |
str
|
Name of the attribute, to be used in error message. |
'Command'
|
Source code in fractal_server/string_tools.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|