Soup.CookieJar¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
The policy the jar should follow to accept or reject cookies |
||
r/w/co |
Whether or not the cookie jar is read-only |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when jar changes. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Soup.CookieJar(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Automatic cookie handling for
Soup.Session
.A
Soup.CookieJar
stores [struct`Cookie`]s and arrange for them to be sent with the appropriate [class`Message`]s.Soup.CookieJar
implements [iface`SessionFeature`], so you can add a cookie jar to a session with [method`Session`.add_feature] or [method`Session`.add_feature_by_type].Note that the base
Soup.CookieJar
class does not support any form of long-term cookie persistence.- classmethod new()¶
- Returns:
a new
Soup.CookieJar
- Return type:
Creates a new
Soup.CookieJar
.The base
Soup.CookieJar
class does not support persistent storage of cookies; use a subclass for that.
- add_cookie(cookie)¶
- Parameters:
cookie (
Soup.Cookie
) – aSoup.Cookie
Adds cookie to self.
Emits the [signal`CookieJar`:py:func:::changed<Soup.CookieJar.signals.changed>] signal if we are modifying an existing cookie or adding a valid new cookie (‘valid’ means that the cookie’s expire date is not in the past).
cookie will be ‘stolen’ by the jar, so don’t free it afterwards.
- add_cookie_full(cookie, uri, first_party)¶
- Parameters:
cookie (
Soup.Cookie
) – aSoup.Cookie
first_party (
GLib.Uri
orNone
) – the URI for the main document
Adds cookie to self.
Emits the [signal`CookieJar`:py:func:::changed<Soup.CookieJar.signals.changed>] signal if we are modifying an existing cookie or adding a valid new cookie (‘valid’ means that the cookie’s expire date is not in the past).
first_party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.
uri will be used to reject setting or overwriting secure cookies from insecure origins.
None
is treated as secure.cookie will be ‘stolen’ by the jar, so don’t free it afterwards.
- add_cookie_with_first_party(first_party, cookie)¶
- Parameters:
first_party (
GLib.Uri
) – the URI for the main documentcookie (
Soup.Cookie
) – aSoup.Cookie
Adds cookie to self.
Emits the [signal`CookieJar`:py:func:::changed<Soup.CookieJar.signals.changed>] signal if we are modifying an existing cookie or adding a valid new cookie (‘valid’ means that the cookie’s expire date is not in the past).
first_party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.
cookie will be ‘stolen’ by the jar, so don’t free it afterwards.
For secure cookies to work properly you may want to use [method`CookieJar`.add_cookie_full].
- all_cookies()¶
- Returns:
a
GLib.SList
with all the cookies in the self.- Return type:
Constructs a [struct`GLib`.List] with every cookie inside the self.
The cookies in the list are a copy of the original, so you have to free them when you are done with them.
- delete_cookie(cookie)¶
- Parameters:
cookie (
Soup.Cookie
) – aSoup.Cookie
Deletes cookie from self.
Emits the [signal`CookieJar`:py:func:::changed<Soup.CookieJar.signals.changed>] signal.
- get_accept_policy()¶
- Returns:
the
Soup.CookieJarAcceptPolicy
set in the self- Return type:
Gets self's [enum`CookieJarAcceptPolicy`].
- get_cookie_list(uri, for_http)¶
- Parameters:
- Returns:
a
GLib.SList
with the cookies in the self that would be sent with a request to uri.- Return type:
Retrieves the list of cookies that would be sent with a request to uri as a [struct`GLib`.List] of
Soup.Cookie
objects.If for_http is
True
, the return value will include cookies marked “HttpOnly” (that is, cookies that the server wishes to keep hidden from client-side scripting operations such as the JavaScript document.cookies property). SinceSoup.CookieJar
sets the Cookie header itself when making the actual HTTP request, you should almost certainly be setting for_http toFalse
if you are calling this.
- get_cookie_list_with_same_site_info(uri, top_level, site_for_cookies, for_http, is_safe_method, is_top_level_navigation)¶
- Parameters:
top_level (
GLib.Uri
orNone
) – aGLib.Uri
for the top level documentsite_for_cookies (
GLib.Uri
orNone
) – aGLib.Uri
indicating the origin to get cookies forfor_http (
bool
) – whether or not the return value is being passed directly to an HTTP operationis_safe_method (
bool
) – if the HTTP method is safe, as defined by RFC 7231, ignored when for_http isFalse
is_top_level_navigation (
bool
) – whether or not the HTTP request is part of top level navigation
- Returns:
a
GLib.SList
with the cookies in the self that would be sent with a request to uri.- Return type:
This is an extended version of [method`CookieJar`.get_cookie_list] that provides more information required to use SameSite cookies.
See the SameSite cookies spec for more detailed information.
- get_cookies(uri, for_http)¶
- Parameters:
- Returns:
the cookies, in string form, or
None
if there are no cookies for uri.- Return type:
Retrieves (in Cookie-header form) the list of cookies that would be sent with a request to uri.
If for_http is
True
, the return value will include cookies marked “HttpOnly” (that is, cookies that the server wishes to keep hidden from client-side scripting operations such as the JavaScript document.cookies property). SinceSoup.CookieJar
sets the Cookie header itself when making the actual HTTP request, you should almost certainly be setting for_http toFalse
if you are calling this.
- is_persistent()¶
-
Gets whether self stores cookies persistenly.
- set_accept_policy(policy)¶
- Parameters:
policy (
Soup.CookieJarAcceptPolicy
) – aSoup.CookieJarAcceptPolicy
Sets policy as the cookie acceptance policy for self.
- set_cookie(uri, cookie)¶
- Parameters:
Adds cookie to self, exactly as though it had appeared in a Set-Cookie header returned from a request to uri.
Keep in mind that if the [enum`CookieJarAcceptPolicy`] set is either
Soup.CookieJarAcceptPolicy.NO_THIRD_PARTY
orSoup.CookieJarAcceptPolicy.GRANDFATHERED_THIRD_PARTY
you’ll need to use [method`CookieJar`.set_cookie_with_first_party], otherwise the jar will have no way of knowing if the cookie is being set by a third party or not.
- set_cookie_with_first_party(uri, first_party, cookie)¶
- Parameters:
Adds cookie to self, exactly as though it had appeared in a Set-Cookie header returned from a request to uri.
first_party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.
- do_changed(old_cookie, new_cookie) virtual¶
- Parameters:
old_cookie (
Soup.Cookie
) –new_cookie (
Soup.Cookie
) –
- do_is_persistent() virtual¶
-
Gets whether jar stores cookies persistenly.
- do_save() virtual¶
Signal Details¶
- Soup.CookieJar.signals.changed(cookie_jar, old_cookie, new_cookie)¶
- Signal Name:
changed
- Flags:
- Parameters:
cookie_jar (
Soup.CookieJar
) – The object which received the signalold_cookie (
Soup.Cookie
) – the oldSoup.Cookie
valuenew_cookie (
Soup.Cookie
) – the newSoup.Cookie
value
Emitted when jar changes.
If a cookie has been added, new_cookie will contain the newly-added cookie and old_cookie will be
None
. If a cookie has been deleted, old_cookie will contain the to-be-deleted cookie and new_cookie will beNone
. If a cookie has been changed, old_cookie will contain its old value, and new_cookie its new value.
Property Details¶
- Soup.CookieJar.props.accept_policy¶
- Name:
accept-policy
- Type:
- Default Value:
- Flags:
The policy the jar should follow to accept or reject cookies.