System-level utilities and helper functions.
Interpret a string as a boolean.
A case-insensitive match is performed such that strings matching ‘t’, ‘true’, ‘on’, ‘y’, ‘yes’, or ‘1’ are considered True and, when strict=False, anything else returns the value specified by ‘default’.
Useful for JSON-decoded stuff and config file parsing.
If strict=True, unrecognized values, including None, will raise a ValueError which is useful when parsing values passed in from an API call. Strings yielding False are ‘f’, ‘false’, ‘off’, ‘n’, ‘no’, or ‘0’.
Interpret a string as a boolean and return either 1 or 0.
Any string value in:
(‘True’, ‘true’, ‘On’, ‘on’, ‘1’)
is interpreted as a boolean True.
Useful for JSON-decoded stuff and config file parsing
Decodes incoming text/bytes string using incoming if they’re not already unicode.
Parameters: |
|
---|---|
Returns: | text or a unicode incoming encoded representation of it. |
Raises TypeError: | |
If text is not an instance of str |
Encodes incoming text/bytes string using encoding.
If incoming is not specified, text is expected to be encoded with current python’s default encoding. (sys.getdefaultencoding)
Parameters: |
|
---|---|
Returns: | text or a bytestring encoding encoded representation of it. |
Raises TypeError: | |
If text is not an instance of str |
Converts a string into an float representation of bytes.
The units supported for IEC
Kb(it), Kib(it), Mb(it), Mib(it), Gb(it), Gib(it), Tb(it), Tib(it)
KB, KiB, MB, MiB, GB, GiB, TB, TiB
The units supported for SI
kb(it), Mb(it), Gb(it), Tb(it)
kB, MB, GB, TB
Note that the SI unit system does not support capital letter ‘K’
Parameters: |
|
---|---|
Returns: | Numerical representation of text in bytes. |
Raises ValueError: | |
If text has an invalid value. |
Normalize string.
Convert to lowercase, remove non-word characters, and convert spaces to hyphens.
Inspired by Django’s slugify filter.
Parameters: |
|
---|---|
Returns: | slugified unicode representation of value |
Raises TypeError: | |
If text is not an instance of str |