def to_bytes_safe(text, encoding="utf-8"):
    if not isinstance(text, (bytes, text_type)):
        raise TypeError("must be string type")

    if isinstance(text, text_type):
        return text.encode(encoding)

    return text
Convert the input value into bytes type.
dataset/ETHPy150Open douban/brownant/brownant/utils.py/to_bytes_safe