code: def to_bytes(s):  # pragma: nocover
      
      if isinstance(s, bytes):
          return s
      if isinstance(s, str) or is_unicode(s):
          return s.encode("utf-8")
      try:
          return unicode(s).encode("utf-8")
      except NameError:
          return str(s).encode("utf-8")
docs: Convert an item into bytes.