Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests
| 189 | |
| 190 | |
| 191 | class RequestsCookieJar(CookieJar, MutableMapping[str, str | None]): # type: ignore[misc] |
| 192 | """Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict |
| 193 | interface. |
| 194 | |
| 195 | This is the CookieJar we create by default for requests and sessions that |
| 196 | don't specify one, since some clients may expect response.cookies and |
| 197 | session.cookies to support dict operations. |
| 198 | |
| 199 | Requests does not use the dict interface internally; it's just for |
| 200 | compatibility with external client code. All requests code should work |
| 201 | out of the box with externally provided instances of ``CookieJar``, e.g. |
| 202 | ``LWPCookieJar`` and ``FileCookieJar``. |
| 203 | |
| 204 | Unlike a regular CookieJar, this class is pickleable. |
| 205 | |
| 206 | .. warning:: dictionary operations that are normally O(1) may be O(n). |
| 207 | """ |
| 208 | |
| 209 | _policy: CookiePolicy |
| 210 | |
| 211 | def get( # type: ignore[override] |
| 212 | self, |
| 213 | name: str, |
| 214 | default: str | None = None, |
| 215 | domain: str | None = None, |
| 216 | path: str | None = None, |
| 217 | ) -> str | None: |
| 218 | """Dict-like get() that also supports optional domain and path args in |
| 219 | order to resolve naming collisions from using one cookie jar over |
| 220 | multiple domains. |
| 221 | |
| 222 | .. warning:: operation is O(n), not O(1). |
| 223 | """ |
| 224 | try: |
| 225 | return self._find_no_duplicates(name, domain, path) |
| 226 | except KeyError: |
| 227 | return default |
| 228 | |
| 229 | def set( |
| 230 | self, name: str, value: str | Morsel[dict[str, str]] | None, **kwargs: Any |
| 231 | ) -> Cookie | None: |
| 232 | """Dict-like set() that also supports optional domain and path args in |
| 233 | order to resolve naming collisions from using one cookie jar over |
| 234 | multiple domains. |
| 235 | """ |
| 236 | # support client code that unsets cookies by assignment of a None value: |
| 237 | if value is None: |
| 238 | remove_cookie_by_name( |
| 239 | self, name, domain=kwargs.get("domain"), path=kwargs.get("path") |
| 240 | ) |
| 241 | return |
| 242 | |
| 243 | if isinstance(value, Morsel): |
| 244 | c = morsel_to_cookie(value) |
| 245 | else: |
| 246 | c = create_cookie(name, value, **kwargs) |
| 247 | self.set_cookie(c) |
| 248 | return c |
no outgoing calls
no test coverage detected