.. versionadded:: 2014.7.0 value The value to be encoded. encoder : base64 The encoder to use on the subsequent string. CLI Example: .. code-block:: bash salt '*' random.str_encode 'I am a new string' base64
(value, encoder="base64")
| 44 | |
| 45 | |
| 46 | def str_encode(value, encoder="base64"): |
| 47 | """ |
| 48 | .. versionadded:: 2014.7.0 |
| 49 | |
| 50 | value |
| 51 | The value to be encoded. |
| 52 | |
| 53 | encoder : base64 |
| 54 | The encoder to use on the subsequent string. |
| 55 | |
| 56 | CLI Example: |
| 57 | |
| 58 | .. code-block:: bash |
| 59 | |
| 60 | salt '*' random.str_encode 'I am a new string' base64 |
| 61 | """ |
| 62 | if isinstance(value, str): |
| 63 | value = value.encode(__salt_system_encoding__) |
| 64 | if encoder == "base64": |
| 65 | try: |
| 66 | out = base64.b64encode(value) |
| 67 | out = out.decode(__salt_system_encoding__) |
| 68 | except TypeError: |
| 69 | raise SaltInvocationError("Value must be an encode-able string") |
| 70 | else: |
| 71 | try: |
| 72 | out = value.encode(encoder) |
| 73 | except LookupError: |
| 74 | raise SaltInvocationError("You must specify a valid encoder") |
| 75 | except AttributeError: |
| 76 | raise SaltInvocationError("Value must be an encode-able string") |
| 77 | return out |
| 78 | |
| 79 | |
| 80 | def get_str( |
nothing calls this directly
no test coverage detected