byteify¶
-
privex.helpers.common.byteify(data: Optional[Union[str, bytes]], encoding='utf-8', if_none=None) → bytes[source]¶ Convert a piece of data into bytes if it isn’t already:
>>> byteify("hello world") b"hello world"
By default, if
dataisNone, then aTypeErrorwill be raised bybytes().If you’d rather convert
Noneinto a blank bytes string, useif_node="", like so:>>> byteify(None) TypeError: encoding without a string argument >>> byteify(None, if_none="") b''