Indicates a string is safe to use and will not compromise security. NOTE: The caller is reponsible for checking that the string is actually safe. This function serves only to mark the string as such. Can work with format strings as well. For example: :: >>> safe("{} i
(base_str, *args, **kwargs)
| 46 | |
| 47 | @mod.export() |
| 48 | def safe(base_str, *args, **kwargs): |
| 49 | """ |
| 50 | Indicates a string is safe to use and will not compromise security. |
| 51 | |
| 52 | NOTE: The caller is reponsible for checking that the string is actually safe. |
| 53 | This function serves only to mark the string as such. |
| 54 | |
| 55 | Can work with format strings as well. For example: |
| 56 | :: |
| 57 | |
| 58 | >>> safe("{} is my name", "polygraphy") |
| 59 | "'polygraphy' is my name" |
| 60 | """ |
| 61 | args = [repr(arg) for arg in args] |
| 62 | kwargs = {key: repr(val) for key, val in kwargs.items()} |
| 63 | return Script.String(base_str.format(*args, **kwargs), safe=True) |
| 64 | |
| 65 | |
| 66 | def ensure_safe(inp): |