| 1 |
|
| 2 |
) |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
def sanitizer(name): |
| 12 |
""" |
| 13 |
Sanitizes a string supposed to be an entity name. That is, |
| 14 |
invalid characters like slashes are substituted with underscores. |
| 15 |
|
| 16 |
:param name: A string representing the name. |
| 17 |
|
| 18 |
:returns: The sanitized name. |
| 19 |
:rtype: str |
| 20 |
""" |
| 21 |
return name.replace("/", "_") |
| 22 |
|
| 23 |
|
| 24 |
def check(name): |
| 25 |
""" |
| 26 |
Checks a string whether is needs to be sanitized. |
| 27 |
|
| 28 |
:param name: The name. |
| 29 |
|
| 30 |
:returns: True if the name is valid, false otherwise. |
| 31 |
:rtype: bool |
| 32 |
""" |
| 33 |
if isinstance(name, bytes): |
| 34 |
name = name.decode() |
| 35 |
return "/" not in name |