code: def force_bytes(value):
      
      if IS_PY3:
          if isinstance(value, str):
              value = value.encode('utf-8', 'backslashreplace')
      else:
          if isinstance(value, unicode):  # NOQA: F821
              value = value.encode('utf-8')
  
      return value
docs: Forces a Unicode string to become a bytestring.