Callbacks¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- Soup.AddressCallback(addr, status, *user_data)¶
- Parameters:
addr (
Soup.Address
) – theSoup.Address
that was resolvedstatus (
int
) –Soup.Status.OK
,Soup.Status.CANT_RESOLVE
, orSoup.Status.CANCELLED
user_data (
object
orNone
) – the user data that was passed toSoup.Address.resolve_async
()
The callback function passed to
Soup.Address.resolve_async
().
- Soup.AuthDomainBasicAuthCallback(domain, msg, username, password, *user_data)¶
- Parameters:
domain (
Soup.AuthDomainBasic
) – the domainmsg (
Soup.Message
) – the message being authenticatedusername (
str
) – the username provided by the clientpassword (
str
) – the password provided by the clientuser_data (
object
orNone
) – the data passed toSoup.AuthDomainBasic.set_auth_callback
()
- Returns:
True
if username and password are valid- Return type:
Callback used by
Soup.AuthDomainBasic
for authentication purposes. The application should verify that username and password and valid and returnTrue
orFalse
.If you are maintaining your own password database (rather than using the password to authenticate against some other system like PAM or a remote server), you should make sure you know what you are doing. In particular, don’t store cleartext passwords, or easily-computed hashes of cleartext passwords, even if you don’t care that much about the security of your server, because users will frequently use the same password for multiple sites, and so compromising any site with a cleartext (or easily-cracked) password database may give attackers access to other more-interesting sites as well.
- Soup.AuthDomainDigestAuthCallback(domain, msg, username, *user_data)¶
- Parameters:
domain (
Soup.AuthDomainDigest
) – the domainmsg (
Soup.Message
) – the message being authenticatedusername (
str
) – the username provided by the clientuser_data (
object
orNone
) – the data passed toSoup.AuthDomainDigest.set_auth_callback
()
- Returns:
the encoded password, or
None
if username is not a valid user. domain will free the password when it is done with it.- Return type:
Callback used by
Soup.AuthDomainDigest
for authentication purposes. The application should look up username in its password database, and return the corresponding encoded password (seeSoup.AuthDomainDigest.encode_password
()).
- Soup.AuthDomainFilter(domain, msg, *user_data)¶
- Parameters:
domain (
Soup.AuthDomain
) – aSoup.AuthDomain
msg (
Soup.Message
) – aSoup.Message
user_data (
object
orNone
) – the data passed toSoup.AuthDomain.set_filter
()
- Returns:
- Return type:
The prototype for a
Soup.AuthDomain
filter; seeSoup.AuthDomain.set_filter
() for details.
- Soup.AuthDomainGenericAuthCallback(domain, msg, username, *user_data)¶
- Parameters:
domain (
Soup.AuthDomain
) – aSoup.AuthDomain
msg (
Soup.Message
) – theSoup.Message
being authenticatedusername (
str
) – the username from msguser_data (
object
orNone
) – the data passed toSoup.AuthDomain.set_generic_auth_callback
()
- Returns:
- Return type:
The prototype for a
Soup.AuthDomain
generic authentication callback.The callback should look up the user’s password, call
Soup.AuthDomain.check_password
(), and use the return value from that method as its own return value.In general, for security reasons, it is preferable to use the auth-domain-specific auth callbacks (eg,
Soup.AuthDomainBasicAuthCallback
andSoup.AuthDomainDigestAuthCallback
), because they don’t require keeping a cleartext password database. Most users will use the same password for many different sites, meaning if any site with a cleartext password database is compromised, accounts on other servers might be compromised as well. For many of the cases whereSoup.Server
is used, this is not really relevant, but it may still be worth considering.
- Soup.ChunkAllocator(msg, max_len, *user_data)¶
- Parameters:
msg (
Soup.Message
) – theSoup.Message
the chunk is being allocated formax_len (
int
) – the maximum length that will be read, or 0.user_data (
object
orNone
) – the data passed toSoup.Message.set_chunk_allocator
()
- Returns:
the new buffer (or
None
)- Return type:
Soup.Buffer
orNone
The prototype for a chunk allocation callback. This should allocate a new
Soup.Buffer
and return it for the I/O layer to read message body data off the network into.If max_len is non-0, it indicates the maximum number of bytes that could be read, based on what is known about the message size. Note that this might be a very large number, and you should not simply try to allocate that many bytes blindly. If max_len is 0, that means that libsoup does not know how many bytes remain to be read, and the allocator should return a buffer of a size that it finds convenient.
If the allocator returns
None
, the message will be paused. It is up to the application to make sure that it gets unpaused when it becomes possible to allocate a new buffer.Deprecated since version ???: Use
Soup.Request
if you want to read into your own buffers.
- Soup.LoggerFilter(logger, msg, *user_data)¶
- Parameters:
logger (
Soup.Logger
) – theSoup.Logger
msg (
Soup.Message
) – the message being loggeduser_data (
object
orNone
) – the data passed toSoup.Logger.set_request_filter
() orSoup.Logger.set_response_filter
()
- Returns:
a
Soup.LoggerLogLevel
value indicating how much of the message to log- Return type:
The prototype for a logging filter. The filter callback will be invoked for each request or response, and should analyze it and return a
Soup.LoggerLogLevel
value indicating how much of the message to log. Eg, it might choose betweenSoup.LoggerLogLevel.BODY
andSoup.LoggerLogLevel.HEADERS
depending on the Content-Type.
- Soup.LoggerPrinter(logger, level, direction, data, *user_data)¶
- Parameters:
logger (
Soup.Logger
) – theSoup.Logger
level (
Soup.LoggerLogLevel
) – the level of the information being printed.direction (
int
) – a single-character prefix to datadata (
str
) – data to printuser_data (
object
orNone
) – the data passed toSoup.Logger.set_printer
()
The prototype for a custom printing callback.
level indicates what kind of information is being printed. Eg, it will be
Soup.LoggerLogLevel.HEADERS
if data is header data.direction is either ‘<’, ‘>’, or ‘ ‘, and data is the single line to print; the printer is expected to add a terminating newline.
To get the effect of the default printer, you would do:
<informalexample><programlisting> printf (“%c %s\n”, direction, data); </programlisting></informalexample>
- Soup.MessageHeadersForeachFunc(name, value, *user_data)¶
- Parameters:
name (
str
) – the header namevalue (
str
) – the header valueuser_data (
object
orNone
) – the data passed toSoup.MessageHeaders.foreach
()
The callback passed to
Soup.MessageHeaders.foreach
().
- Soup.PasswordManagerCallback(password_manager, msg, auth, retrying, *user_data)¶
- Parameters:
password_manager (
Soup.PasswordManager
) –msg (
Soup.Message
) –auth (
Soup.Auth
) –retrying (
bool
) –
- Soup.ProxyResolverCallback(proxy_resolver, msg, arg, addr, *user_data)¶
- Parameters:
proxy_resolver (
Soup.ProxyResolver
) –msg (
Soup.Message
) –arg (
int
) –addr (
Soup.Address
) –
Deprecated since version 2.28: Use
Soup.ProxyURIResolver
instead
- Soup.ProxyURIResolverCallback(resolver, status, proxy_uri, *user_data)¶
- Parameters:
resolver (
Soup.ProxyURIResolver
) – theSoup.ProxyURIResolver
status (
int
) – aSoup.Status
user_data (
object
orNone
) – data passed toSoup.ProxyURIResolver.get_proxy_uri_async
()
Callback for
Soup.ProxyURIResolver.get_proxy_uri_async
()
- Soup.ServerCallback(server, msg, path, query, client, *user_data)¶
- Parameters:
server (
Soup.Server
) – theSoup.Server
msg (
Soup.Message
) – the message being processedpath (
str
) – the path component of msg's Request-URIquery ({
str
:str
} orNone
) – the parsed query component of msg's Request-URIclient (
Soup.ClientContext
) – additional contextual information about the clientuser_data (
object
orNone
) – the data passed toSoup.Server.add_handler
() orSoup.Server.add_early_handler
().
A callback used to handle requests to a
Soup.Server
.path and query contain the likewise-named components of the Request-URI, subject to certain assumptions. By default,
Soup.Server
decodes all percent-encoding in the URI path, such that “/foo% 2Fbar” is treated the same as “/foo/bar”. If your server is serving resources in some non-POSIX-filesystem namespace, you may want to distinguish those as two distinct paths. In that case, you can set theSoup.SERVER_RAW_PATHS
property when creating theSoup.Server
, and it will leave those characters undecoded. (You may want to callSoup.URI.normalize
() to decode any percent-encoded characters that you aren’t handling specially.)query contains the query component of the Request-URI parsed according to the rules for HTML form handling. Although this is the only commonly-used query string format in HTTP, there is nothing that actually requires that HTTP URIs use that format; if your server needs to use some other format, you can just ignore query, and call
Soup.Message.get_uri
() and parse the URI’s query field yourself.See
Soup.Server.add_handler
() andSoup.Server.add_early_handler
() for details of what handlers can/should do.
- Soup.ServerWebsocketCallback(server, connection, path, client, *user_data)¶
- Parameters:
server (
Soup.Server
) – theSoup.Server
connection (
Soup.WebsocketConnection
) – the newly created WebSocket connectionpath (
str
) – the path component of msg's Request-URIclient (
Soup.ClientContext
) – additional contextual information about the clientuser_data (
object
orNone
) – the data passed to soup_server_add_handler
A callback used to handle WebSocket requests to a
Soup.Server
. The callback will be invoked after sending the handshake response back to the client (and is only invoked if the handshake was successful).path contains the path of the Request-URI, subject to the same rules as
Soup.ServerCallback
(qv).
- Soup.SessionCallback(session, msg, *user_data)¶
- Parameters:
session (
Soup.Session
) – the sessionmsg (
Soup.Message
) – the message that has finisheduser_data (
object
orNone
) – the data passed toSoup.Session.queue_message
Prototype for the callback passed to
Soup.Session.queue_message
(), qv.
- Soup.SessionConnectProgressCallback(session, event, connection, *user_data)¶
- Parameters:
session (
Soup.Session
) – theSoup.Session
event (
Gio.SocketClientEvent
) – aGio.SocketClientEvent
connection (
Gio.IOStream
) – the current state of the network connectionuser_data (
object
orNone
) – the data passed toSoup.Session.connect_async
().
Prototype for the progress callback passed to
Soup.Session.connect_async
().New in version 2.62.
- Soup.SocketCallback(sock, status, *user_data)¶
- Parameters:
sock (
Soup.Socket
) – theSoup.Socket
status (
int
) – an HTTP status code indicating success or failureuser_data (
object
orNone
) – the data passed toSoup.Socket.connect_async
()
The callback function passed to
Soup.Socket.connect_async
().