Functions#
- action_parse_detailed_name(detailed_name: str) tuple[bool, str, Variant | None]#
- Parameters:
detailed_name
- action_print_detailed_name(action_name: str, target_value: Variant | None = None) str#
- Parameters:
action_name
target_value
- app_info_create_from_commandline(commandline: str, application_name: str | None, flags: AppInfoCreateFlags) AppInfo#
- Parameters:
commandline
application_name
flags
- app_info_get_default_for_type(content_type: str, must_support_uris: bool) AppInfo | None#
- Parameters:
content_type
must_support_uris
- app_info_get_default_for_type_async(content_type: str, must_support_uris: bool, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
content_type
must_support_uris
cancellable
callback
user_data
- app_info_get_default_for_type_finish(result: AsyncResult) AppInfo#
- Parameters:
result
- app_info_get_default_for_uri_scheme_async(uri_scheme: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
uri_scheme
cancellable
callback
user_data
- app_info_get_default_for_uri_scheme_finish(result: AsyncResult) AppInfo#
- Parameters:
result
- app_info_launch_default_for_uri(uri: str, context: AppLaunchContext | None = None) bool#
- Parameters:
uri
context
- app_info_launch_default_for_uri_async(uri: str, context: AppLaunchContext | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
uri
context
cancellable
callback
user_data
- app_info_launch_default_for_uri_finish(result: AsyncResult) bool#
- Parameters:
result
- async_initable_newv_async(object_type: GType, n_parameters: int, parameters: Parameter, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
object_type
n_parameters
parameters
io_priority
cancellable
callback
user_data
- bus_get(bus_type: BusType, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously connects to the message bus specified by
bus_type.When the operation is finished,
callbackwill be invoked. You can then callbus_get_finish()to get the result of the operation.This is an asynchronous failable function. See
bus_get_sync()for the synchronous version.Added in version 2.26.
- Parameters:
bus_type – a
BusTypecancellable – a
CancellableorNonecallback – a
AsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to
callback
- bus_get_finish(res: AsyncResult) DBusConnection#
Finishes an operation started with
bus_get().The returned object is a singleton, that is, shared with other callers of
bus_get()andbus_get_sync()forbus_type. In the event that you need a private message bus connection, usedbus_address_get_for_bus_sync()andnew_for_address()with G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT and G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION flags.Note that the returned
DBusConnectionobject will (usually) have theDBusConnection:exit-on-close property set toTrue.Added in version 2.26.
- Parameters:
res – a
AsyncResultobtained from theAsyncReadyCallbackpassed tobus_get()- Returns:
a
DBusConnectionorNoneiferroris set. Free withunref().
- bus_get_sync(bus_type: BusType, cancellable: Cancellable | None = None) DBusConnection#
Synchronously connects to the message bus specified by
bus_type. Note that the returned object may shared with other callers, e.g. if two separate parts of a process calls this function with the samebus_type, they will share the same object.This is a synchronous failable function. See
bus_get()andbus_get_finish()for the asynchronous version.The returned object is a singleton, that is, shared with other callers of
bus_get()andbus_get_sync()forbus_type. In the event that you need a private message bus connection, usedbus_address_get_for_bus_sync()andnew_for_address()with G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT and G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION flags.Note that the returned
DBusConnectionobject will (usually) have theDBusConnection:exit-on-close property set toTrue.Added in version 2.26.
- Parameters:
bus_type – a
BusTypecancellable – a
CancellableorNone
- Returns:
a
DBusConnectionorNoneiferroris set. Free withunref().
- bus_own_name(bus_type: BusType, name: str, flags: BusNameOwnerFlags, bus_acquired_closure: Closure | None = None, name_acquired_closure: Closure | None = None, name_lost_closure: Closure | None = None) int#
Starts acquiring
nameon the bus specified bybus_typeand callsname_acquired_handlerandname_lost_handlerwhen the name is acquired respectively lost. Callbacks will be invoked in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this function from.You are guaranteed that one of the
name_acquired_handlerandname_lost_handlercallbacks will be invoked after calling this function - there are three possible cases:name_lost_handlerwith aNoneconnection (if a connection to the bus can’t be made).bus_acquired_handlerthenname_lost_handler(if the name can’t be obtained)bus_acquired_handlerthenname_acquired_handler(if the name was obtained).
When you are done owning the name, just call
bus_unown_name()with the owner id this function returns.If the name is acquired or lost (for example another application could acquire the name if you allow replacement or the application currently owning the name exits), the handlers are also invoked. If the
DBusConnectionthat is used for attempting to own the name closes, thenname_lost_handleris invoked since it is no longer possible for other processes to access the process.You cannot use
bus_own_name()several times for the same name (unless interleaved with calls tobus_unown_name()) - only the first call will work.Another guarantee is that invocations of
name_acquired_handlerandname_lost_handlerare guaranteed to alternate; that is, ifname_acquired_handleris invoked then you are guaranteed that the next time one of the handlers is invoked, it will bename_lost_handler. The reverse is also true.If you plan on exporting objects (using e.g.
register_object()), note that it is generally too late to export the objects inname_acquired_handler. Instead, you can do this inbus_acquired_handlersince you are guaranteed that this will run beforenameis requested from the bus.This behavior makes it very simple to write applications that wants to [own names][gdbus-owning-names] and export objects. Simply register objects to be exported in
bus_acquired_handlerand unregister the objects (if any) inname_lost_handler.Added in version 2.26.
- Parameters:
bus_type – the type of bus to own a name on
name – the well-known name to own
flags – a set of flags from the
BusNameOwnerFlagsenumerationbus_acquired_closure
name_acquired_closure
name_lost_closure
- Returns:
an identifier (never 0) that can be used with
bus_unown_name()to stop owning the name.
- bus_own_name_on_connection(connection: DBusConnection, name: str, flags: BusNameOwnerFlags, name_acquired_closure: Closure | None = None, name_lost_closure: Closure | None = None) int#
Like
bus_own_name()but takes aDBusConnectioninstead of aBusType.Added in version 2.26.
- Parameters:
connection – a
DBusConnectionname – the well-known name to own
flags – a set of flags from the
BusNameOwnerFlagsenumerationname_acquired_closure
name_lost_closure
- Returns:
an identifier (never 0) that can be used with
bus_unown_name()to stop owning the name
- bus_unown_name(owner_id: int) None#
Stops owning a name.
Note that there may still be D-Bus traffic to process (relating to owning and unowning the name) in the current thread-default
MainContextafter this function has returned. You should continue to iterate theMainContextuntil theDestroyNotifyfunction passed tobus_own_name()is called, in order to avoid memory leaks through callbacks queued on theMainContextafter it’s stopped being iterated.Added in version 2.26.
- Parameters:
owner_id – an identifier obtained from
bus_own_name()
- bus_unwatch_name(watcher_id: int) None#
Stops watching a name.
Note that there may still be D-Bus traffic to process (relating to watching and unwatching the name) in the current thread-default
MainContextafter this function has returned. You should continue to iterate theMainContextuntil theDestroyNotifyfunction passed tobus_watch_name()is called, in order to avoid memory leaks through callbacks queued on theMainContextafter it’s stopped being iterated.Added in version 2.26.
- Parameters:
watcher_id – An identifier obtained from
bus_watch_name()
- bus_watch_name(bus_type: BusType, name: str, flags: BusNameWatcherFlags, name_appeared_closure: Closure | None = None, name_vanished_closure: Closure | None = None) int#
Starts watching
nameon the bus specified bybus_typeand callsname_appeared_handlerandname_vanished_handlerwhen the name is known to have an owner respectively known to lose its owner. Callbacks will be invoked in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this function from.You are guaranteed that one of the handlers will be invoked after calling this function. When you are done watching the name, just call
bus_unwatch_name()with the watcher id this function returns.If the name vanishes or appears (for example the application owning the name could restart), the handlers are also invoked. If the
DBusConnectionthat is used for watching the name disconnects, thenname_vanished_handleris invoked since it is no longer possible to access the name.Another guarantee is that invocations of
name_appeared_handlerandname_vanished_handlerare guaranteed to alternate; that is, ifname_appeared_handleris invoked then you are guaranteed that the next time one of the handlers is invoked, it will bename_vanished_handler. The reverse is also true.This behavior makes it very simple to write applications that want to take action when a certain [name exists][gdbus-watching-names]. Basically, the application should create object proxies in
name_appeared_handlerand destroy them again (if any) inname_vanished_handler.Added in version 2.26.
- Parameters:
bus_type – The type of bus to watch a name on.
name – The name (well-known or unique) to watch.
flags – Flags from the
BusNameWatcherFlagsenumeration.name_appeared_closure
name_vanished_closure
- Returns:
An identifier (never 0) that can be used with
bus_unwatch_name()to stop watching the name.
- bus_watch_name_on_connection(connection: DBusConnection, name: str, flags: BusNameWatcherFlags, name_appeared_closure: Closure | None = None, name_vanished_closure: Closure | None = None) int#
Like
bus_watch_name()but takes aDBusConnectioninstead of aBusType.Added in version 2.26.
- Parameters:
connection – A
DBusConnection.name – The name (well-known or unique) to watch.
flags – Flags from the
BusNameWatcherFlagsenumeration.name_appeared_closure
name_vanished_closure
- Returns:
An identifier (never 0) that can be used with
bus_unwatch_name()to stop watching the name.
- content_type_can_be_executable(type: str) bool#
Checks if a content type can be executable. Note that for instance things like text files can be executables (i.e. scripts and batch files).
- Parameters:
type – a content type string
- Returns:
Trueif the file type corresponds to a type that can be executable,Falseotherwise.
- content_type_equals(type1: str, type2: str) bool#
Compares two content types for equality.
- Parameters:
type1 – a content type string
type2 – a content type string
- Returns:
Trueif the two strings are identical or equivalent,Falseotherwise.
- content_type_from_mime_type(mime_type: str) str | None#
Tries to find a content type based on the mime type name.
Added in version 2.18.
- Parameters:
mime_type – a mime type string
- Returns:
Newly allocated string with content type or
None. Free withfree()
- content_type_get_description(type: str) str#
Gets the human readable description of the content type.
- Parameters:
type – a content type string
- Returns:
a short description of the content type
type. Free the returned string withfree()
- content_type_get_generic_icon_name(type: str) str | None#
Gets the generic icon name for a content type.
See the shared-mime-info specification for more on the generic icon name.
Added in version 2.34.
- Parameters:
type – a content type string
- Returns:
the registered generic icon name for the given
type, orNoneif unknown. Free withfree()
- content_type_get_icon(type: str) Icon#
Gets the icon for a content type.
- Parameters:
type – a content type string
- Returns:
Iconcorresponding to the content type. Free the returned object withunref()
- content_type_get_mime_dirs() list[str]#
Get the list of directories which MIME data is loaded from. See
content_type_set_mime_dirs()for details.Added in version 2.60.
- Returns:
None-terminated list of directories to load MIME data from, including anymime/subdirectory, and with the first directory to try listed first
- content_type_get_mime_type(type: str) str | None#
Gets the mime type for the content type, if one is registered.
- Parameters:
type – a content type string
- Returns:
the registered mime type for the given
type, orNoneif unknown; free withfree().
- content_type_get_symbolic_icon(type: str) Icon#
Gets the symbolic icon for a content type.
Added in version 2.34.
- Parameters:
type – a content type string
- Returns:
symbolic
Iconcorresponding to the content type. Free the returned object withunref()
- content_type_guess(filename: str | None = None, data: list[int] | None = None) tuple[str, bool]#
Guesses the content type based on example data. If the function is uncertain,
result_uncertainwill be set toTrue. Eitherfilenameordatamay beNone, in which case the guess will be based solely on the other argument.- Parameters:
filename – a path, or
Nonedata – a stream of data, or
None
- Returns:
a string indicating a guessed content type for the given data. Free with
free()
- content_type_guess_for_tree(root: File) list[str]#
Tries to guess the type of the tree with root
root, by looking at the files it contains. The result is an array of content types, with the best guess coming first.The types returned all have the form x-content/foo, e.g. x-content/audio-cdda (for audio CDs) or x-content/image-dcf (for a camera memory card). See the shared-mime-info specification for more on x-content types.
This function is useful in the implementation of
guess_content_type().Added in version 2.18.
- Parameters:
root – the root of the tree to guess a type for
- Returns:
an
None-terminated array of zero or more content types. Free withstrfreev()
- content_type_is_a(type: str, supertype: str) bool#
Determines if
typeis a subset ofsupertype.- Parameters:
type – a content type string
supertype – a content type string
- Returns:
Trueiftypeis a kind ofsupertype,Falseotherwise.
- content_type_is_mime_type(type: str, mime_type: str) bool#
Determines if
typeis a subset ofmime_type. Convenience wrapper aroundcontent_type_is_a().Added in version 2.52.
- Parameters:
type – a content type string
mime_type – a mime type string
- Returns:
Trueiftypeis a kind ofmime_type,Falseotherwise.
- content_type_is_unknown(type: str) bool#
Checks if the content type is the generic “unknown” type. On UNIX this is the “application/octet-stream” mimetype, while on win32 it is “*” and on OSX it is a dynamic type or octet-stream.
- Parameters:
type – a content type string
- Returns:
Trueif the type is the unknown type.
- content_type_set_mime_dirs(dirs: list[str] | None = None) None#
Set the list of directories used by GIO to load the MIME database. If
dirsisNone, the directories used are the default:the
mimesubdirectory of the directory in$XDG_DATA_HOMEthe
mimesubdirectory of every directory in$XDG_DATA_DIRS
This function is intended to be used when writing tests that depend on information stored in the MIME database, in order to control the data.
Typically, in case your tests use %G_TEST_OPTION_ISOLATE_DIRS, but they depend on the system’s MIME database, you should call this function with
dirsset toNonebefore callingtest_init(), for instance:// Load MIME data from the system g_content_type_set_mime_dirs (NULL); // Isolate the environment g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); … return g_test_run ();
Added in version 2.60.
- Parameters:
dirs –
None-terminated list of directories to load MIME data from, including anymime/subdirectory, and with the first directory to try listed first
- content_types_get_registered() list[str]#
Gets a list of strings containing all the registered content types known to the system. The list and its data should be freed using
g_list_free_full (list, g_free).- Returns:
list of the registered content types
- dbus_address_escape_value(string: str) str#
Escape
stringso it can appear in a D-Bus address as the value part of a key-value pair.For instance, if
stringis/run/bus-for-:0, this function would return/run/bus-for-%3A0, which could be used in a D-Bus address likeunix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-%3A0.Added in version 2.36.
- Parameters:
string – an unescaped string to be included in a D-Bus address as the value in a key-value pair
- Returns:
a copy of
stringwith all non-optionally-escaped bytes escaped
- dbus_address_get_for_bus_sync(bus_type: BusType, cancellable: Cancellable | None = None) str#
Synchronously looks up the D-Bus address for the well-known message bus instance specified by
bus_type. This may involve using various platform specific mechanisms.The returned address will be in the D-Bus address format.
Added in version 2.26.
- Parameters:
bus_type – a
BusTypecancellable – a
CancellableorNone
- Returns:
a valid D-Bus address string for
bus_typeorNoneiferroris set
- dbus_address_get_stream(address: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously connects to an endpoint specified by
addressand sets up the connection so it is in a state to run the client-side of the D-Bus authentication conversation.addressmust be in the D-Bus address format.When the operation is finished,
callbackwill be invoked. You can then calldbus_address_get_stream_finish()to get the result of the operation.This is an asynchronous failable function. See
dbus_address_get_stream_sync()for the synchronous version.Added in version 2.26.
- Parameters:
address – A valid D-Bus address.
cancellable – A
CancellableorNone.callback – A
AsyncReadyCallbackto call when the request is satisfied.user_data – Data to pass to
callback.
- dbus_address_get_stream_finish(res: AsyncResult) tuple[IOStream, str | None]#
Finishes an operation started with
dbus_address_get_stream().A server is not required to set a GUID, so
out_guidmay be set toNoneeven on success.Added in version 2.26.
- Parameters:
res – A
AsyncResultobtained from the GAsyncReadyCallback passed todbus_address_get_stream().- Returns:
A
IOStreamorNoneiferroris set.
- dbus_address_get_stream_sync(address: str, cancellable: Cancellable | None = None) tuple[IOStream, str | None]#
Synchronously connects to an endpoint specified by
addressand sets up the connection so it is in a state to run the client-side of the D-Bus authentication conversation.addressmust be in the D-Bus address format.A server is not required to set a GUID, so
out_guidmay be set toNoneeven on success.This is a synchronous failable function. See
dbus_address_get_stream()for the asynchronous version.Added in version 2.26.
- Parameters:
address – A valid D-Bus address.
cancellable – A
CancellableorNone.
- Returns:
A
IOStreamorNoneiferroris set.
- dbus_annotation_info_lookup(annotations: list[DBusAnnotationInfo] | None, name: str) str | None#
- Parameters:
annotations
name
- dbus_error_new_for_dbus_error(dbus_error_name: str, dbus_error_message: str) GError#
- Parameters:
dbus_error_name
dbus_error_message
- dbus_error_register_error(error_domain: int, error_code: int, dbus_error_name: str) bool#
- Parameters:
error_domain
error_code
dbus_error_name
- dbus_error_register_error_domain(error_domain_quark_name: str, quark_volatile: int, entries: list[DBusErrorEntry]) None#
- Parameters:
error_domain_quark_name
quark_volatile
entries
- dbus_error_unregister_error(error_domain: int, error_code: int, dbus_error_name: str) bool#
- Parameters:
error_domain
error_code
dbus_error_name
- dbus_escape_object_path(s: str) str#
This is a language binding friendly version of
dbus_escape_object_path_bytestring().Added in version 2.68.
- Parameters:
s – the string to escape
- Returns:
an escaped version of
s. Free withfree().
- dbus_escape_object_path_bytestring(bytes: list[int]) str#
Escapes
bytesfor use in a D-Bus object path component.bytesis an array of zero or more nonzero bytes in an unspecified encoding, followed by a single zero byte.The escaping method consists of replacing all non-alphanumeric characters (see
ascii_isalnum()) with their hexadecimal value preceded by an underscore (_). For example:foo.bar.bazwill becomefoo_2ebar_2ebaz.This method is appropriate to use when the input is nearly a valid object path component but is not when your input is far from being a valid object path component. Other escaping algorithms are also valid to use with D-Bus object paths.
This can be reversed with
dbus_unescape_object_path().Added in version 2.68.
- Parameters:
bytes – the string of bytes to escape
- Returns:
an escaped version of
bytes. Free withfree().
- dbus_generate_guid() str#
Generate a D-Bus GUID that can be used with e.g.
new().See the D-Bus specification regarding what strings are valid D-Bus GUIDs. The specification refers to these as ‘UUIDs’ whereas GLib (for historical reasons) refers to them as ‘GUIDs’. The terms are interchangeable.
Note that D-Bus GUIDs do not follow RFC 4122.
Added in version 2.26.
- Returns:
A valid D-Bus GUID. Free with
free().
- dbus_gvalue_to_gvariant(gvalue: Value, type: VariantType) Variant#
Converts a
Valueto aVariantof the type indicated by thetypeparameter.The conversion is using the following rules:
G_TYPE_STRING: ‘s’, ‘o’, ‘g’ or ‘ay’G_TYPE_STRV: ‘as’, ‘ao’ or ‘aay’G_TYPE_BOOLEAN: ‘b’G_TYPE_UCHAR: ‘y’G_TYPE_INT: ‘i’, ‘n’G_TYPE_UINT: ‘u’, ‘q’G_TYPE_INT64: ‘x’G_TYPE_UINT64: ‘t’G_TYPE_DOUBLE: ‘d’G_TYPE_VARIANT: AnyVariantType
This can fail if e.g.
gvalueis of typestrandtypeis ‘i’, i.e. %G_VARIANT_TYPE_INT32. It will also fail for anyType(including e.g.objectandBoxedderived-types) not in the table above.Note that if
gvalueis of type %G_TYPE_VARIANT and its value isNone, the emptyVariantinstance (neverNone) fortypeis returned (e.g. 0 for scalar types, the empty string for string types, ‘/’ for object path types, the empty array for any array type and so on).See the
dbus_gvariant_to_gvalue()function for how to convert aVariantto aValue.Added in version 2.30.
- Parameters:
type – A
VariantType
- Returns:
A
Variant(never floating) ofVariantTypetypeholding the data fromgvalueor an emptyVariantin case of failure. Free withunref().
- dbus_gvariant_to_gvalue(value: Variant) Value#
Converts a
Variantto aValue. Ifvalueis floating, it is consumed.The rules specified in the
dbus_gvalue_to_gvariant()function are used - this function is essentially its reverse form. So, aVariantcontaining any basic or string array type will be converted to aValuecontaining a basic value or string array. Any otherVariant(handle, variant, tuple, dict entry) will be converted to aValuecontaining thatVariant.The conversion never fails - a valid
Valueis always returned inout_gvalue.Added in version 2.30.
- Parameters:
value – A
Variant.
- dbus_is_address(string: str) bool#
Checks if
stringis a D-Bus address.This doesn’t check if
stringis actually supported byDBusServerorDBusConnection- usedbus_is_supported_address()to do more checks.Added in version 2.26.
- Parameters:
string – A string.
- Returns:
Trueifstringis a valid D-Bus address,Falseotherwise.
- dbus_is_error_name(string: str) bool#
Check whether
stringis a valid D-Bus error name.This function returns the same result as
dbus_is_interface_name(), because D-Bus error names are defined to have exactly the same syntax as interface names.Added in version 2.70.
- Parameters:
string – The string to check.
- Returns:
Trueif valid,Falseotherwise.
- dbus_is_guid(string: str) bool#
Checks if
stringis a D-Bus GUID.See the documentation for
dbus_generate_guid()for more information about the format of a GUID.Added in version 2.26.
- Parameters:
string – The string to check.
- Returns:
Trueifstringis a GUID,Falseotherwise.
- dbus_is_interface_name(string: str) bool#
Checks if
stringis a valid D-Bus interface name.Added in version 2.26.
- Parameters:
string – The string to check.
- Returns:
Trueif valid,Falseotherwise.
- dbus_is_member_name(string: str) bool#
Checks if
stringis a valid D-Bus member (e.g. signal or method) name.Added in version 2.26.
- Parameters:
string – The string to check.
- Returns:
Trueif valid,Falseotherwise.
- dbus_is_name(string: str) bool#
Checks if
stringis a valid D-Bus bus name (either unique or well-known).Added in version 2.26.
- Parameters:
string – The string to check.
- Returns:
Trueif valid,Falseotherwise.
- dbus_is_supported_address(string: str) bool#
Like
dbus_is_address()but also checks if the library supports the transports instringand that key/value pairs for each transport are valid. See the specification of the D-Bus address format.Added in version 2.26.
- Parameters:
string – A string.
- Returns:
Trueifstringis a valid D-Bus address that is supported by this library,Falseiferroris set.
- dbus_is_unique_name(string: str) bool#
Checks if
stringis a valid D-Bus unique bus name.Added in version 2.26.
- Parameters:
string – The string to check.
- Returns:
Trueif valid,Falseotherwise.
- dbus_unescape_object_path(s: str) list[int] | None#
Unescapes an string that was previously escaped with
dbus_escape_object_path(). If the string is in a format that could not have been returned bydbus_escape_object_path(), this function returnsNone.Encoding alphanumeric characters which do not need to be encoded is not allowed (e.g
_63is not valid, the string should containcinstead).Added in version 2.68.
- Parameters:
s – the string to unescape
- Returns:
an unescaped version of
s, orNoneifsis not a string returned fromdbus_escape_object_path(). Free withfree().
- dtls_client_connection_new(base_socket: DatagramBased, server_identity: SocketConnectable | None = None) DtlsClientConnection#
- Parameters:
base_socket
server_identity
- dtls_server_connection_new(base_socket: DatagramBased, certificate: TlsCertificate | None = None) DtlsServerConnection#
- Parameters:
base_socket
certificate
- file_new_tmp_async(tmpl: str | None, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
tmpl
io_priority
cancellable
callback
user_data
- file_new_tmp_dir_async(tmpl: str | None, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
- Parameters:
tmpl
io_priority
cancellable
callback
user_data
- file_new_tmp_dir_finish(result: AsyncResult) File#
- Parameters:
result
- file_new_tmp_finish(result: AsyncResult) tuple[File, FileIOStream]#
- Parameters:
result
- initable_newv(object_type: GType, parameters: list[Parameter], cancellable: Cancellable | None = None) Object#
- Parameters:
object_type
parameters
cancellable
- io_error_from_errno(err_no: int) IOErrorEnum#
Converts
errno.herror codes into GIO error codes.The fallback value
FAILEDis returned for error codes not currently handled (but note that future GLib releases may return a more specific value instead).As
errnois global and may be modified by intermediate function calls, you should save its value immediately after the call returns, and use the saved value instead oferrno:int saved_errno; ret = read (blah); saved_errno = errno; g_io_error_from_errno (saved_errno);
- Parameters:
err_no – Error number as defined in errno.h.
- Returns:
IOErrorEnumvalue for the givenerrno.herror number
- io_error_from_file_error(file_error: FileError) IOErrorEnum#
Converts
FileErrorerror codes into GIO error codes.Added in version 2.74.
- Parameters:
file_error – a
FileError.- Returns:
IOErrorEnumvalue for the givenFileErrorerror value.
- io_extension_point_implement(extension_point_name: str, type: GType, extension_name: str, priority: int) IOExtension#
- Parameters:
extension_point_name
type
extension_name
priority
- io_extension_point_lookup(name: str) IOExtensionPoint#
- Parameters:
name
- io_extension_point_register(name: str) IOExtensionPoint#
- Parameters:
name
- io_modules_load_all_in_directory(dirname: str) list[IOModule]#
Loads all the modules in the specified directory.
If don’t require all modules to be initialized (and thus registering all gtypes) then you can use
io_modules_scan_all_in_directory()which allows delayed/lazy loading of modules.- Parameters:
dirname – pathname for a directory containing modules to load.
- Returns:
a list of
IOModuleloaded from the directory, All the modules are loaded into memory, if you want to unload them (enabling on-demand loading) you must callunuse()on all the modules. Free the list withfree().
- io_modules_load_all_in_directory_with_scope(dirname: str, scope: IOModuleScope) list[IOModule]#
Loads all the modules in the specified directory.
If don’t require all modules to be initialized (and thus registering all gtypes) then you can use
io_modules_scan_all_in_directory()which allows delayed/lazy loading of modules.Added in version 2.30.
- Parameters:
dirname – pathname for a directory containing modules to load.
scope – a scope to use when scanning the modules.
- Returns:
a list of
IOModuleloaded from the directory, All the modules are loaded into memory, if you want to unload them (enabling on-demand loading) you must callunuse()on all the modules. Free the list withfree().
- io_modules_scan_all_in_directory(dirname: str) None#
Scans all the modules in the specified directory, ensuring that any extension point implemented by a module is registered.
This may not actually load and initialize all the types in each module, some modules may be lazily loaded and initialized when an extension point it implements is used with e.g.
get_extensions()orget_extension_by_name().If you need to guarantee that all types are loaded in all the modules, use
io_modules_load_all_in_directory().Added in version 2.24.
- Parameters:
dirname – pathname for a directory containing modules to scan.
- io_modules_scan_all_in_directory_with_scope(dirname: str, scope: IOModuleScope) None#
Scans all the modules in the specified directory, ensuring that any extension point implemented by a module is registered.
This may not actually load and initialize all the types in each module, some modules may be lazily loaded and initialized when an extension point it implements is used with e.g.
get_extensions()orget_extension_by_name().If you need to guarantee that all types are loaded in all the modules, use
io_modules_load_all_in_directory().Added in version 2.30.
- Parameters:
dirname – pathname for a directory containing modules to scan.
scope – a scope to use when scanning the modules
- io_scheduler_cancel_all_jobs() None#
Cancels all cancellable I/O jobs.
A job is cancellable if a
Cancellablewas passed intoio_scheduler_push_job().Deprecated since version 2.36: You should never call this function, since you don’t know how other libraries in your program might be making use of gioscheduler.
- io_scheduler_push_job(job_func: Callable[[IOSchedulerJob, Cancellable | None, Any], bool], user_data: Any, io_priority: int, cancellable: Cancellable | None = None) None#
Schedules the I/O job to run in another thread.
notifywill be called onuser_dataafterjob_funchas returned, regardless whether the job was cancelled or has run to completion.If
cancellableis notNone, it can be used to cancel the I/O job by callingcancel()or by callingio_scheduler_cancel_all_jobs().Deprecated since version 2.36: use
ThreadPoolorrun_in_thread()- Parameters:
job_func – a
IOSchedulerJobFunc.user_data – data to pass to
job_funcio_priority – the I/O priority of the request.
cancellable – optional
Cancellableobject,Noneto ignore.
- keyfile_settings_backend_new(filename: str, root_path: str, root_group: str | None = None) SettingsBackend#
Creates a keyfile-backed
SettingsBackend.The filename of the keyfile to use is given by
filename.All settings read to or written from the backend must fall under the path given in
root_path(which must start and end with a slash and not contain two consecutive slashes).root_pathmay be “/”.If
root_groupis non-Nonethen it specifies the name of the keyfile group used for keys that are written directly belowroot_path. For example, ifroot_pathis “/apps/example/” androot_groupis “toplevel”, then settings the key “/apps/example/enabled” to a value ofTruewill cause the following to appear in the keyfile:[toplevel] enabled=true
If
root_groupisNonethen it is not permitted to store keys directly below theroot_path.For keys not stored directly below
root_path(ie: in a sub-path), the name of the subpath (with the final slash stripped) is used as the name of the keyfile group. To continue the example, if “/apps/example/profiles/default/font-size” were set to 12 then the following would appear in the keyfile:[profiles/default] font-size=12
The backend will refuse writes (and return writability as being
False) for keys outside ofroot_pathand, in the event thatroot_groupisNone, also for keys directly underroot_path. Writes will also be refused if the backend detects that it has the inability to rewrite the keyfile (ie: the containing directory is not writable).There is no checking done for your key namespace clashing with the syntax of the key file format. For example, if you have ‘[’ or ‘]’ characters in your path names or ‘=’ in your key names you may be in trouble.
The backend reads default values from a keyfile called
defaultsin the directory specified by theGKeyfileSettingsBackend:defaults-dir property, and a list of locked keys from a text file with the namelocksin the same location.- Parameters:
filename – the filename of the keyfile
root_path – the path under which all settings keys appear
root_group – the group name corresponding to
root_path, orNone
- Returns:
a keyfile-backed
SettingsBackend
- memory_monitor_dup_default() MemoryMonitor#
- memory_settings_backend_new() SettingsBackend#
Creates a memory-backed
SettingsBackend.This backend allows changes to settings, but does not write them to any backing storage, so the next time you run your application, the memory backend will start out with the default values again.
Added in version 2.28.
- Returns:
a newly created
SettingsBackend
- network_monitor_get_default() NetworkMonitor#
- networking_init() None#
Initializes the platform networking libraries (eg, on Windows, this calls WSAStartup()). GLib will call this itself if it is needed, so you only need to call it if you directly call system networking functions (without calling any GLib networking functions first).
Added in version 2.36.
- null_settings_backend_new() SettingsBackend#
Creates a readonly
SettingsBackend.This backend does not allow changes to settings, so all settings will always have their default values.
Added in version 2.28.
- Returns:
a newly created
SettingsBackend
- pollable_source_new(pollable_stream: Object) Source#
Utility method for
PollableInputStreamandPollableOutputStreamimplementations. Creates a newSourcethat expects a callback of typeGPollableSourceFunc. The new source does not actually do anything on its own; useadd_child_source()to add other sources to it to cause it to trigger.Added in version 2.28.
- Parameters:
pollable_stream – the stream associated with the new source
- Returns:
the new
Source.
- pollable_source_new_full(pollable_stream: Object, child_source: Source | None = None, cancellable: Cancellable | None = None) Source#
Utility method for
PollableInputStreamandPollableOutputStreamimplementations. Creates a newSource, as withpollable_source_new(), but also attachingchild_source(with a dummy callback), andcancellable, if they are non-None.Added in version 2.34.
- Parameters:
pollable_stream – the stream associated with the new source
child_source – optional child source to attach
cancellable – optional
Cancellableto attach
- Returns:
the new
Source.
- pollable_stream_read(stream: InputStream, buffer: list[int], blocking: bool, cancellable: Cancellable | None = None) int#
Tries to read from
stream, as withread()(ifblockingisTrue) orread_nonblocking()(ifblockingisFalse). This can be used to more easily share code between blocking and non-blocking implementations of a method.If
blockingisFalse, thenstreammust be aPollableInputStreamfor whichcan_poll()returnsTrue, or else the behavior is undefined. IfblockingisTrue, thenstreamdoes not need to be aPollableInputStream.Added in version 2.34.
- Parameters:
stream – a
InputStreambuffer – a buffer to read data into
blocking – whether to do blocking I/O
cancellable – optional
Cancellableobject,Noneto ignore.
- Returns:
the number of bytes read, or -1 on error.
- pollable_stream_write(stream: OutputStream, buffer: list[int], blocking: bool, cancellable: Cancellable | None = None) int#
Tries to write to
stream, as withwrite()(ifblockingisTrue) orwrite_nonblocking()(ifblockingisFalse). This can be used to more easily share code between blocking and non-blocking implementations of a method.If
blockingisFalse, thenstreammust be aPollableOutputStreamfor whichcan_poll()returnsTrueor else the behavior is undefined. IfblockingisTrue, thenstreamdoes not need to be aPollableOutputStream.Added in version 2.34.
- Parameters:
stream – a
OutputStream.buffer – the buffer containing the data to write.
blocking – whether to do blocking I/O
cancellable – optional
Cancellableobject,Noneto ignore.
- Returns:
the number of bytes written, or -1 on error.
- pollable_stream_write_all(stream: OutputStream, buffer: list[int], blocking: bool, cancellable: Cancellable | None = None) tuple[bool, int]#
Tries to write
countbytes tostream, as withwrite_all(), but usingpollable_stream_write()rather thanwrite().On a successful write of
countbytes,Trueis returned, andbytes_writtenis set tocount.If there is an error during the operation (including
WOULD_BLOCKin the non-blocking case),Falseis returned anderroris set to indicate the error status,bytes_writtenis updated to contain the number of bytes written into the stream before the error occurred.As with
pollable_stream_write(), ifblockingisFalse, thenstreammust be aPollableOutputStreamfor whichcan_poll()returnsTrueor else the behavior is undefined. IfblockingisTrue, thenstreamdoes not need to be aPollableOutputStream.Added in version 2.34.
- Parameters:
stream – a
OutputStream.buffer – the buffer containing the data to write.
blocking – whether to do blocking I/O
cancellable – optional
Cancellableobject,Noneto ignore.
- Returns:
Trueon success,Falseif there was an error
- power_profile_monitor_dup_default() PowerProfileMonitor#
- proxy_resolver_get_default() ProxyResolver#
- resources_enumerate_children(path: str, lookup_flags: ResourceLookupFlags) list[str]#
Returns all the names of children at the specified
pathin the set of globally registered resources. The return result is aNoneterminated list of strings which should be released withstrfreev().lookup_flagscontrols the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- Returns:
an array of constant strings
- resources_get_info(path: str, lookup_flags: ResourceLookupFlags) tuple[bool, int, int]#
Looks for a file at the specified
pathin the set of globally registered resources and if found returns information about it.lookup_flagscontrols the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- Returns:
Trueif the file was found.Falseif there were errors
- resources_lookup_data(path: str, lookup_flags: ResourceLookupFlags) Bytes#
Looks for a file at the specified
pathin the set of globally registered resources and returns aBytesthat lets you directly access the data in memory.The data is always followed by a zero byte, so you can safely use the data as a C string. However, that byte is not included in the size of the GBytes.
For uncompressed resource files this is a pointer directly into the resource bundle, which is typically in some readonly data section in the program binary. For compressed files we allocate memory on the heap and automatically uncompress the data.
lookup_flagscontrols the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- Returns:
BytesorNoneon error. Free the returned object withunref()
- resources_open_stream(path: str, lookup_flags: ResourceLookupFlags) InputStream#
Looks for a file at the specified
pathin the set of globally registered resources and returns aInputStreamthat lets you read the data.lookup_flagscontrols the behaviour of the lookup.Added in version 2.32.
- Parameters:
path – A pathname inside the resource
lookup_flags – A
ResourceLookupFlags
- Returns:
InputStreamorNoneon error. Free the returned object withunref()
- resources_register(resource: Resource) None#
Registers the resource with the process-global set of resources. Once a resource is registered the files in it can be accessed with the global resource lookup functions like
resources_lookup_data().Added in version 2.32.
- Parameters:
resource – A
Resource
- resources_unregister(resource: Resource) None#
Unregisters the resource from the process-global set of resources.
Added in version 2.32.
- Parameters:
resource – A
Resource
- settings_schema_source_get_default() SettingsSchemaSource | None#
- simple_async_report_gerror_in_idle(object: Object | None, callback: Callable[[Object | None, AsyncResult, Any], None] | None, user_data: Any, error: GError) None#
Reports an error in an idle function. Similar to
simple_async_report_error_in_idle(), but takes aErrorrather than building a new one.Deprecated since version 2.46: Use
report_error().
- tls_backend_get_default() TlsBackend#
- tls_client_connection_new(base_io_stream: IOStream, server_identity: SocketConnectable | None = None) TlsClientConnection#
- Parameters:
base_io_stream
server_identity
- tls_file_database_new(anchors: str) TlsFileDatabase#
- Parameters:
anchors
- tls_server_connection_new(base_io_stream: IOStream, certificate: TlsCertificate | None = None) TlsServerConnection#
- Parameters:
base_io_stream
certificate
- unix_is_mount_path_system_internal(mount_path: str) bool#
Determines if
mount_pathis considered an implementation of the OS. This is primarily used for hiding mountable and mounted volumes that only are used in the OS and has little to no relevance to the casual user.- Parameters:
mount_path – a mount path, e.g.
/media/diskor/usr- Returns:
Trueifmount_pathis considered an implementation detail of the OS.
- unix_is_system_device_path(device_path: str) bool#
Determines if
device_pathis considered a block device path which is only used in implementation of the OS. This is primarily used for hiding mounted volumes that are intended as APIs for programs to read, and system administrators at a shell; rather than something that should, for example, appear in a GUI. For example, the Linux/procfilesystem.The list of device paths considered ‘system’ ones may change over time.
Added in version 2.56.
- Parameters:
device_path – a device path, e.g.
/dev/loop0ornfsd- Returns:
Trueifdevice_pathis considered an implementation detail of the OS.
- unix_is_system_fs_type(fs_type: str) bool#
Determines if
fs_typeis considered a type of file system which is only used in implementation of the OS. This is primarily used for hiding mounted volumes that are intended as APIs for programs to read, and system administrators at a shell; rather than something that should, for example, appear in a GUI. For example, the Linux/procfilesystem.The list of file system types considered ‘system’ ones may change over time.
Added in version 2.56.
- Parameters:
fs_type – a file system type, e.g.
procfsortmpfs- Returns:
Trueiffs_typeis considered an implementation detail of the OS.
- unix_mount_at(mount_path: str) tuple[UnixMountEntry | None, int]#
Gets a
UnixMountEntryfor a given mount path. Iftime_readis set, it will be filled with a unix timestamp for checking if the mounts have changed since withunix_mounts_changed_since().If more mounts have the same mount path, the last matching mount is returned.
This will return
Noneif there is no mount point atmount_path.- Parameters:
mount_path – path for a possible unix mount.
- Returns:
- unix_mount_compare(mount1: UnixMountEntry, mount2: UnixMountEntry) int#
Compares two unix mounts.
- Parameters:
mount1 – first
UnixMountEntryto compare.mount2 – second
UnixMountEntryto compare.
- Returns:
1, 0 or -1 if
mount1is greater than, equal to, or less thanmount2, respectively.
- unix_mount_for(file_path: str) tuple[UnixMountEntry | None, int]#
Gets a
UnixMountEntryfor a given file path. Iftime_readis set, it will be filled with a unix timestamp for checking if the mounts have changed since withunix_mounts_changed_since().If more mounts have the same mount path, the last matching mount is returned.
This will return
Noneif looking up the mount entry fails, iffile_pathdoesn’t exist or there is an I/O error.Added in version 2.52.
- Parameters:
file_path – file path on some unix mount.
- Returns:
- unix_mount_free(mount_entry: UnixMountEntry) None#
Frees a unix mount.
- Parameters:
mount_entry – a
UnixMountEntry.
- unix_mount_get_device_path(mount_entry: UnixMountEntry) str#
Gets the device path for a unix mount.
- Parameters:
mount_entry – a
GUnixMount.- Returns:
a string containing the device path.
- unix_mount_get_fs_type(mount_entry: UnixMountEntry) str#
Gets the filesystem type for the unix mount.
- Parameters:
mount_entry – a
GUnixMount.- Returns:
a string containing the file system type.
- unix_mount_get_mount_path(mount_entry: UnixMountEntry) str#
Gets the mount path for a unix mount.
- Parameters:
mount_entry – input
UnixMountEntryto get the mount path for.- Returns:
the mount path for
mount_entry.
- unix_mount_get_options(mount_entry: UnixMountEntry) str | None#
Gets a comma-separated list of mount options for the unix mount. For example,
rw,relatime,seclabel,data=ordered.This is similar to
get_options(), but it takes aUnixMountEntryas an argument.Added in version 2.58.
- Parameters:
mount_entry – a
UnixMountEntry.- Returns:
a string containing the options, or
Noneif not available.
- unix_mount_get_root_path(mount_entry: UnixMountEntry) str | None#
Gets the root of the mount within the filesystem. This is useful e.g. for mounts created by bind operation, or btrfs subvolumes.
For example, the root path is equal to “/” for mount created by “mount /dev/sda1 /mnt/foo” and “/bar” for “mount –bind /mnt/foo/bar /mnt/bar”.
Added in version 2.60.
- Parameters:
mount_entry – a
UnixMountEntry.- Returns:
a string containing the root, or
Noneif not supported.
- unix_mount_guess_can_eject(mount_entry: UnixMountEntry) bool#
Guesses whether a Unix mount can be ejected.
- Parameters:
mount_entry – a
UnixMountEntry- Returns:
Trueifmount_entryis deemed to be ejectable.
- unix_mount_guess_icon(mount_entry: UnixMountEntry) Icon#
Guesses the icon of a Unix mount.
- Parameters:
mount_entry – a
UnixMountEntry- Returns:
a
Icon
- unix_mount_guess_name(mount_entry: UnixMountEntry) str#
Guesses the name of a Unix mount. The result is a translated string.
- Parameters:
mount_entry – a
UnixMountEntry- Returns:
A newly allocated string that must be freed with
free()
- unix_mount_guess_should_display(mount_entry: UnixMountEntry) bool#
Guesses whether a Unix mount should be displayed in the UI.
- Parameters:
mount_entry – a
UnixMountEntry- Returns:
Trueifmount_entryis deemed to be displayable.
- unix_mount_guess_symbolic_icon(mount_entry: UnixMountEntry) Icon#
Guesses the symbolic icon of a Unix mount.
Added in version 2.34.
- Parameters:
mount_entry – a
UnixMountEntry- Returns:
a
Icon
- unix_mount_is_readonly(mount_entry: UnixMountEntry) bool#
Checks if a unix mount is mounted read only.
- Parameters:
mount_entry – a
GUnixMount.- Returns:
Trueifmount_entryis read only.
- unix_mount_is_system_internal(mount_entry: UnixMountEntry) bool#
Checks if a Unix mount is a system mount. This is the Boolean OR of
unix_is_system_fs_type(),unix_is_system_device_path()andunix_is_mount_path_system_internal()onmount_entry’s properties.The definition of what a ‘system’ mount entry is may change over time as new file system types and device paths are ignored.
- Parameters:
mount_entry – a
GUnixMount.- Returns:
Trueif the unix mount is for a system path.
- unix_mount_points_changed_since(time: int) bool#
Checks if the unix mount points have changed since a given unix time.
- Parameters:
time – guint64 to contain a timestamp.
- Returns:
Trueif the mount points have changed sincetime.
- unix_mount_points_get() tuple[list[UnixMountPoint], int]#
Gets a
ListofUnixMountPointcontaining the unix mount points. Iftime_readis set, it will be filled with the mount timestamp, allowing for checking if the mounts have changed withunix_mount_points_changed_since().- Returns:
a
Listof the UNIX mountpoints.
- unix_mount_points_get_from_file(table_path: str) tuple[list[UnixMountPoint] | None, int]#
Gets an array of
UnixMountPoints containing the Unix mount points listed intable_path.This is a generalized version of
unix_mount_points_get(), mainly intended for internal testing use. Note thatunix_mount_points_get()may parse multiple hierarchical table files, so this function is not a direct superset of its functionality.If there is an error reading or parsing the file,
NULLwill be returned and both out parameters will be set to0.Added in version 2.82.
- Parameters:
table_path – path to the mount points table file (for example
/etc/fstab)- Returns:
mount points, or
NULLif there was an error loading them
- unix_mounts_changed_since(time: int) bool#
Checks if the unix mounts have changed since a given unix time.
- Parameters:
time – guint64 to contain a timestamp.
- Returns:
Trueif the mounts have changed sincetime.
- unix_mounts_get() tuple[list[UnixMountEntry], int]#
Gets a
ListofUnixMountEntrycontaining the unix mounts. Iftime_readis set, it will be filled with the mount timestamp, allowing for checking if the mounts have changed withunix_mounts_changed_since().- Returns:
a
Listof the UNIX mounts.
- unix_mounts_get_from_file(table_path: str) tuple[list[UnixMountEntry] | None, int]#
Gets an array of
UnixMountEntrys containing the Unix mounts listed intable_path.This is a generalized version of
unix_mounts_get(), mainly intended for internal testing use. Note thatunix_mounts_get()may parse multiple hierarchical table files, so this function is not a direct superset of its functionality.If there is an error reading or parsing the file,
NULLwill be returned and both out parameters will be set to0.Added in version 2.82.
- Parameters:
table_path – path to the mounts table file (for example
/proc/self/mountinfo)- Returns:
mount entries, or
NULLif there was an error loading them