grab.util.cookies
This 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: HTTPMessage | 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.