code: def set_cookie(
          self,
          name: str,
          value: Union[str, bytes],
          domain: str = None,
          expires: Union[float, Tuple, datetime.datetime] = None,
          path: str = "/",
          expires_days: int = None,
          **kwargs: Any
      ) -> None:
          
          # The cookie library only accepts type str, in both python 2 and 3
          name = escape.native_str(name)
          value = escape.native_str(value)
          if re.search(r"[\x00-\x20]", name + value):
              # Don't let us accidentally inject bad stuff
              raise ValueError("Invalid cookie %r: %r" % (name, value))
          if not hasattr(self, "_new_cookie"):
              self._new_cookie = http.cookies.SimpleCookie()
          if name in self._new_cookie:
              del self._new_cookie[name]
          self._new_cookie[name] = value
          morsel = self._new_cookie[name]
          if domain:
              morsel["domain"] = domain
          if expires_days is not None and not expires:
              expires = datetime.datetime.utcnow() + datetime.timedelta(days=expires_days)
          if expires:
              morsel["expires"] = httputil.format_timestamp(expires)
          if path:
              morsel["path"] = path
          for k, v in kwargs.items():
              if k == "max_age":
                  k = "max-age"
  
              # skip falsy values for httponly and secure flags because
              # SimpleCookie sets them regardless
              if k in ["httponly", "secure"] and not v:
                  continue
  
              morsel[k] = v
docs: Sets an outgoing cookie name/value with the given options.
  
          Newly-set cookies are not immediately visible via `get_cookie`;
          they are not present until the next request.
  
          expires may be a numeric timestamp as returned by `time.time`,
          a time tuple as returned by `time.gmtime`, or a
          `datetime.datetime` object.
  
          Additional keyword arguments are set on the cookies.Morsel
          directly.
          See https://docs.python.org/3/library/http.cookies.html#http.cookies.Morsel
          for available attributes.