code: 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
docs: Convert to byte string.