def _to_bstr ( l ) : if isinstance ( l , str ) : l = l . encode ( 'ascii' , 'backslashreplace' ) elif not isinstance ( l , bytes ) : l = str ( l ) . encode ( 'ascii' , 'backslashreplace' ) return l
python btypes to string
Convert to byte string .
def _to_bstr(l):
    """Convert to byte string."""

    if isinstance(l, str):
        l = l.encode('ascii', 'backslashreplace')
    elif not isinstance(l, bytes):
        l = str(l).encode('ascii', 'backslashreplace')
    return l