Create and store a cookie with modern browser attributes. Args: name: Cookie name. value: Cookie value. domain: Cookie domain. path: Cookie path. expires: Cookie expiration timestamp. http_only: Whether cookie is HTTP-o
(
self,
name: str,
value: str,
*,
domain: str = '',
path: str = '/',
expires: int | None = None,
http_only: bool = False,
secure: bool = False,
same_site: Literal['Lax', 'None', 'Strict'] | None = None,
**_kwargs: Any, # Unknown parameters will be ignored.
)
| 86 | return self._jar |
| 87 | |
| 88 | def set( |
| 89 | self, |
| 90 | name: str, |
| 91 | value: str, |
| 92 | *, |
| 93 | domain: str = '', |
| 94 | path: str = '/', |
| 95 | expires: int | None = None, |
| 96 | http_only: bool = False, |
| 97 | secure: bool = False, |
| 98 | same_site: Literal['Lax', 'None', 'Strict'] | None = None, |
| 99 | **_kwargs: Any, # Unknown parameters will be ignored. |
| 100 | ) -> None: |
| 101 | """Create and store a cookie with modern browser attributes. |
| 102 | |
| 103 | Args: |
| 104 | name: Cookie name. |
| 105 | value: Cookie value. |
| 106 | domain: Cookie domain. |
| 107 | path: Cookie path. |
| 108 | expires: Cookie expiration timestamp. |
| 109 | http_only: Whether cookie is HTTP-only. |
| 110 | secure: Whether cookie requires secure context. |
| 111 | same_site: SameSite cookie attribute value. |
| 112 | """ |
| 113 | cookie = Cookie( |
| 114 | version=0, |
| 115 | name=name, |
| 116 | value=value, |
| 117 | port=None, |
| 118 | port_specified=False, |
| 119 | domain=domain, |
| 120 | domain_specified=bool(domain), |
| 121 | domain_initial_dot=domain.startswith('.'), |
| 122 | path=path, |
| 123 | path_specified=bool(path), |
| 124 | secure=secure, |
| 125 | expires=expires, |
| 126 | discard=True, |
| 127 | comment=None, |
| 128 | comment_url=None, |
| 129 | rest={'HttpOnly': ''} if http_only else {}, |
| 130 | rfc2109=False, |
| 131 | ) |
| 132 | |
| 133 | if same_site: |
| 134 | cookie.set_nonstandard_attr('SameSite', same_site) |
| 135 | |
| 136 | self.jar.set_cookie(cookie) |
| 137 | |
| 138 | def _convert_cookie_to_dict(self, cookie: Cookie) -> CookieParam: |
| 139 | """Convert `http.cookiejar.Cookie` to dictionary format. |
no outgoing calls