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
data
isNone
, then aTypeError
will be raised bybytes()
.If you’d rather convert
None
into a blank bytes string, useif_node=""
, like so:>>> byteify(None) TypeError: encoding without a string argument >>> byteify(None, if_none="") b''