grab.util.cookies
¶
THe module provides things to operate with cookies.
Manuals:
- Some code got from
https://github.com/kennethreitz/requests/blob/master/requests/cookies.py
Module Contents¶
Classes¶
Wraps a requests.Request to mimic a urllib2.Request. |
|
Wraps a httplib.HTTPMessage to mimic a urllib.addinfourl. |
Functions¶
|
Create cookielib.Cookie instance. |
|
Build HTTP Cookie header value for given cookies. |
|
|
- class grab.util.cookies.MockRequest(url: str, headers: dict[str, str])[source]¶
Wraps a requests.Request to mimic a urllib2.Request.
The code in cookielib.CookieJar expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via get_new_headers() and interpreting them appropriately. You probably want get_cookie_header, defined below.
- class grab.util.cookies.MockResponse(headers: http.client.HTTPMessage | urllib3._collections.HTTPHeaderDict)[source]¶
Wraps a httplib.HTTPMessage to mimic a urllib.addinfourl.
…what? Basically, expose the parsed HTTP headers from the server response the way cookielib expects to see them.
- grab.util.cookies.create_cookie(*, name: str, value: str, domain: str, comment: None | str = None, comment_url: None | str = None, discard: bool = True, domain_initial_dot: None | bool = None, domain_specified: None | bool = None, expires: None | int = None, path: str = '/', path_specified: None | bool = None, port: None | int = None, port_specified: None | bool = None, rest: None | dict[str, Any] = None, rfc2109: bool = False, secure: bool = False, version: int = 0, httponly: None | bool = None) → http.cookiejar.Cookie[source]¶
Create cookielib.Cookie instance.
- grab.util.cookies.build_cookie_header(cookiejar: http.cookiejar.CookieJar, url: str, headers: collections.abc.Mapping[str, str]) → None | str[source]¶
Build HTTP Cookie header value for given cookies.
- grab.util.cookies.build_jar(cookies: collections.abc.Sequence[http.cookiejar.Cookie]) → http.cookiejar.CookieJar[source]¶
- grab.util.cookies.extract_response_cookies(req_url: str, req_headers: collections.abc.Mapping[str, Any] | http.client.HTTPMessage | urllib3._collections.HTTPHeaderDict, response_headers: http.client.HTTPMessage | urllib3._collections.HTTPHeaderDict) → collections.abc.Sequence[http.cookiejar.Cookie][source]¶