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

MockRequest

Wraps a requests.Request to mimic a urllib2.Request.

MockResponse

Wraps a httplib.HTTPMessage to mimic a urllib.addinfourl.

Functions

create_cookie(→ http.cookiejar.Cookie)

Create cookielib.Cookie instance.

build_cookie_header(→ None | str)

Build HTTP Cookie header value for given cookies.

build_jar(→ http.cookiejar.CookieJar)

extract_response_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.

property unverifiable: bool[source]
property origin_req_host: str[source]
property host: str[source]
get_type() str[source]
get_host() str[source]
get_origin_req_host() str[source]
get_full_url() str[source]
is_unverifiable() bool[source]
has_header(name: str) bool[source]
get_header(name: str, default: Any = None) str[source]
abstract add_header(key: str, val: str) None[source]

Cookielib has no legitimate use for this method.

Add it back if you find one.

add_unredirected_header(name: str, value: str) None[source]
get_new_headers() dict[str, str][source]
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.

info() http.client.HTTPMessage | urllib3._collections.HTTPHeaderDict[source]

Create cookielib.Cookie instance.

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]