MCPcopy
hub / github.com/tornadoweb/tornado / clear_cookie

Method clear_cookie

tornado/web.py:761–787  ·  view source on GitHub ↗

Deletes the cookie with the given name. This method accepts the same arguments as `set_cookie`, except for ``expires`` and ``max_age``. Clearing a cookie requires the same ``domain`` and ``path`` arguments as when it was set. In some cases the ``samesite`` and ``secu

(self, name: str, **kwargs: Any)

Source from the content-addressed store, hash-verified

759 )
760
761 def clear_cookie(self, name: str, **kwargs: Any) -> None:
762 """Deletes the cookie with the given name.
763
764 This method accepts the same arguments as `set_cookie`, except for
765 ``expires`` and ``max_age``. Clearing a cookie requires the same
766 ``domain`` and ``path`` arguments as when it was set. In some cases the
767 ``samesite`` and ``secure`` arguments are also required to match. Other
768 arguments are ignored.
769
770 Similar to `set_cookie`, the effect of this method will not be
771 seen until the following request.
772
773 .. versionchanged:: 6.3
774
775 Now accepts all keyword arguments that ``set_cookie`` does.
776 The ``samesite`` and ``secure`` flags have recently become
777 required for clearing ``samesite="none"`` cookies.
778 """
779 for excluded_arg in ["expires", "max_age"]:
780 if excluded_arg in kwargs:
781 raise TypeError(
782 f"clear_cookie() got an unexpected keyword argument '{excluded_arg}'"
783 )
784 expires = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(
785 days=365
786 )
787 self.set_cookie(name, value="", expires=expires, **kwargs)
788
789 def clear_all_cookies(self, **kwargs: Any) -> None:
790 """Attempt to delete all the cookies the user sent with this request.

Callers 5

clear_all_cookiesMethod · 0.95
getMethod · 0.80
getMethod · 0.80
getMethod · 0.80

Calls 1

set_cookieMethod · 0.95

Tested by

no test coverage detected