Soup.CookieJar¶
| Subclasses: | Soup.CookieJarDB, Soup.CookieJarText |
|---|
Methods¶
| Inherited: | GObject.Object (37), Soup.SessionFeature (5) |
|---|---|
| Structs: | GObject.ObjectClass (5) |
| class | new () |
add_cookie (cookie) |
|
add_cookie_full (cookie, uri, first_party) |
|
add_cookie_with_first_party (first_party, cookie) |
|
all_cookies () |
|
delete_cookie (cookie) |
|
get_accept_policy () |
|
get_cookie_list (uri, for_http) |
|
get_cookie_list_with_same_site_info (uri, top_level, site_for_cookies, for_http, is_safe_method, is_top_level_navigation) |
|
get_cookies (uri, for_http) |
|
is_persistent () |
|
save () |
|
set_accept_policy (policy) |
|
set_cookie (uri, cookie) |
|
set_cookie_with_first_party (uri, first_party, cookie) |
Virtual Methods¶
| Inherited: | GObject.Object (7), Soup.SessionFeature (8) |
|---|
do_changed (old_cookie, new_cookie) |
|
do_is_persistent () |
|
do_save () |
Properties¶
| Name | Type | Flags | Short Description |
|---|---|---|---|
accept-policy |
Soup.CookieJarAcceptPolicy |
r/w | The policy the jar should follow to accept or reject cookies |
read-only |
bool |
r/w/co | Whether or not the cookie jar is read-only |
Class Details¶
-
class
Soup.CookieJar(**kwargs)¶ Bases: GObject.Object,Soup.SessionFeatureAbstract: No Structure: Soup.CookieJarClass-
classmethod
new()¶ Returns: a new Soup.CookieJarReturn type: Soup.CookieJarCreates a new
Soup.CookieJar. The baseSoup.CookieJarclass does not support persistent storage of cookies; use a subclass for that.New in version 2.24.
Parameters: cookie ( Soup.Cookie) – aSoup.CookieAdds cookie to self, emitting the ‘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.
New in version 2.26.
Parameters: - cookie (
Soup.Cookie) – aSoup.Cookie - uri (
Soup.URIorNone) – the URI setting the cookie - first_party (
Soup.URIorNone) – the URI for the main document
Adds cookie to self, emitting the ‘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.
Noneis treated as secure.cookie will be ‘stolen’ by the jar, so don’t free it afterwards.
New in version 2.68.
- cookie (
Parameters: - first_party (
Soup.URI) – the URI for the main document - cookie (
Soup.Cookie) – aSoup.Cookie
Adds cookie to self, emitting the ‘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
Soup.CookieJar.add_cookie_full().New in version 2.40.
- first_party (
Returns: a GLib.SListwith all the cookies in the self.Return type: [ Soup.Cookie]Constructs a
GLib.SListwith 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.New in version 2.26.
Parameters: cookie ( Soup.Cookie) – aSoup.CookieDeletes cookie from self, emitting the ‘changed’ signal.
New in version 2.26.
-
get_accept_policy()¶ Returns: the Soup.CookieJarAcceptPolicyset in the selfReturn type: Soup.CookieJarAcceptPolicyGets self’s
Soup.CookieJarAcceptPolicyNew in version 2.30.
Parameters: Returns: a
GLib.SListwith 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
GLib.SListofSoup.Cookieobjects.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.CookieJarsets the Cookie header itself when making the actual HTTP request, you should almost certainly be setting for_http toFalseif you are calling this.New in version 2.40.
Parameters: - uri (
Soup.URI) – aSoup.URI - top_level (
Soup.URIorNone) – aSoup.URIfor the top level document - site_for_cookies (
Soup.URIorNone) – aSoup.URIindicating the origin to get cookies for - for_http (
bool) – whether or not the return value is being passed directly to an HTTP operation - is_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.SListwith the cookies in the self that would be sent with a request to uri.Return type: This is an extended version of
Soup.CookieJar.get_cookie_list() that provides more information required to use SameSite cookies. See the SameSite cookies spec for more detailed information.New in version 2.70.
- uri (
Parameters: Returns: the cookies, in string form, or
Noneif 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.CookieJarsets the Cookie header itself when making the actual HTTP request, you should almost certainly be setting for_http toFalseif you are calling this.New in version 2.24.
-
is_persistent()¶ Returns: Trueif self storage is persistent orFalseotherwise.Return type: boolGets whether self stores cookies persistenly.
New in version 2.40.
-
save()¶ This function exists for backward compatibility, but does not do anything any more; cookie jars are saved automatically when they are changed.
New in version 2.24.
Deprecated since version ???: This is a no-op.
-
set_accept_policy(policy)¶ Parameters: policy ( Soup.CookieJarAcceptPolicy) – aSoup.CookieJarAcceptPolicySets policy as the cookie acceptance policy for self.
New in version 2.30.
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
Soup.CookieJarAcceptPolicyset is eitherSoup.CookieJarAcceptPolicy.NO_THIRD_PARTYorSoup.CookieJarAcceptPolicy.GRANDFATHERED_THIRD_PARTYyou’ll need to useSoup.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.New in version 2.24.
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.
New in version 2.30.
-
do_changed(old_cookie, new_cookie) virtual¶ Parameters: - old_cookie (
Soup.Cookie) – - new_cookie (
Soup.Cookie) –
- old_cookie (
-
do_is_persistent() virtual¶ Returns: Trueif jar storage is persistent orFalseotherwise.Return type: boolGets whether jar stores cookies persistenly.
New in version 2.40.
-
do_save() virtual¶ This function exists for backward compatibility, but does not do anything any more; cookie jars are saved automatically when they are changed.
New in version 2.24.
Deprecated since version ???: This is a no-op.
-
classmethod
Signal Details¶
-
Soup.CookieJar.signals.changed(cookie_jar, old_cookie, new_cookie)¶ Signal Name: changedFlags: Parameters: - cookie_jar (
Soup.CookieJar) – The object which received the signal - old_cookie (
Soup.Cookie) – the oldSoup.Cookievalue - new_cookie (
Soup.Cookie) – the newSoup.Cookievalue
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.- cookie_jar (
Property Details¶
-
Soup.CookieJar.props.accept_policy¶ Name: accept-policyType: Soup.CookieJarAcceptPolicyDefault Value: Soup.CookieJarAcceptPolicy.ALWAYSFlags: READABLE,WRITABLEThe policy the jar should follow to accept or reject cookies
New in version 2.30.