"""Text Utilities. Those quick short utils are meant to make it easier to work with strings. For instance: some allow smart casting values into bytes. """ def to_bytes(value): """Smart cast a value into a byte. Args: value (byte, str): a value to cast. Returns: byte: the result. """ if not value: return b'' if isinstance(value, bytes): return value return value.encode('utf8')