Module utils.text.transport
Encoding utilities for interaction with web technologies.
Functions
base64_decode(s) | Decodes a base64-encoded string. |
base64_encode(s[, break_lines]) | Encodes a string using base64. |
hash(algo, s) | Calculates the checksum of a string. |
quoted_printable_decode(s) | Decodes a quoted-printable string. |
uri_decode(s) | Decodes a percent-encoded string. |
uri_encode(s[, allowed]) | Encodes a string using percent-encoding. |
Functions
- base64_decode(s)
-
Decodes a base64-encoded string.
Example:
assert(utils.text.transport.base64_decode("ZWFydGg=") == "earth")
- base64_encode(s[, break_lines])
-
Encodes a string using base64.
Example:
assert(utils.text.transport.base64_encode("earth") == "ZWFydGg=")
You may use the break_lines flag to break the lines at 72 columns. Otherwise no line-breaks are used.
- hash(algo, s)
-
Calculates the checksum of a string.
Example:
assert(utils.text.transport.hash("md5", "hello!") == "5a8dd3ad0756a93ded72b823b19dd877")
Parameters:
- algo The algorithm name: “md5”, “sha1”, “sha256” or “sha512”.
- s The data.
- quoted_printable_decode(s)
- Decodes a quoted-printable string.
- uri_decode(s)
- Decodes a percent-encoded string.
- uri_encode(s[, allowed])
-
Encodes a string using percent-encoding.
That is, it replaces any non ASCII-alphanumeric character (plus dash, underscore, dot, tilde) with percent sign (%) followed by two hex digits.
Behaves like PHP’s rawurlencode() and GLib’s g_uri_escape_string().
You may use the allowed parameter to list characters that are not to be encoded.
Example:
assert(utils.text.transport.uri_encode("/path/to file?", "/") == "/path/to%20file%3F")