code: def encode_cookie_value(data, quote=default_cookie_quote):
      
      if data is None:
          return None
  
      # encode() to ASCII bytes so quote won't crash on non-ASCII.
      # but doing that to bytes objects is nonsense.
      # On Python 2 encode crashes if s is bytes containing non-ASCII.
      # On Python 3 encode crashes on all byte objects.
      if not isinstance(data, bytes):
          data = data.encode("utf-8")
  
      # URL encode data so it is safe for cookie value
      quoted = quote(data)
  
      # Don't force to bytes, so that downstream can use proper string API rather
      # than crippled bytes, and to encourage encoding to be done just once.
      return quoted
docs: URL-encode strings to make them safe for a cookie value.
  
      By default this uses urllib quoting, as used in many other cookie
      implementations and in other Python code, instead of an ad hoc escaping
      mechanism which includes backslashes (these also being illegal chars in RFC
      6265).