GLib.KeyFile¶
Fields¶
None
Methods¶
class | error_quark () |
class | new () |
get_boolean (group_name, key) |
|
get_boolean_list (group_name, key) |
|
get_comment (group_name, key) |
|
get_double (group_name, key) |
|
get_double_list (group_name, key) |
|
get_groups () |
|
get_int64 (group_name, key) |
|
get_integer (group_name, key) |
|
get_integer_list (group_name, key) |
|
get_keys (group_name) |
|
get_locale_for_key (group_name, key, locale) |
|
get_locale_string (group_name, key, locale) |
|
get_locale_string_list (group_name, key, locale) |
|
get_start_group () |
|
get_string (group_name, key) |
|
get_string_list (group_name, key) |
|
get_uint64 (group_name, key) |
|
get_value (group_name, key) |
|
has_group (group_name) |
|
load_from_bytes (bytes, flags) |
|
load_from_data (data, length, flags) |
|
load_from_data_dirs (file, flags) |
|
load_from_dirs (file, search_dirs, flags) |
|
load_from_file (file, flags) |
|
remove_comment (group_name, key) |
|
remove_group (group_name) |
|
remove_key (group_name, key) |
|
save_to_file (filename) |
|
set_boolean (group_name, key, value) |
|
set_boolean_list (group_name, key, list) |
|
set_comment (group_name, key, comment) |
|
set_double (group_name, key, value) |
|
set_double_list (group_name, key, list) |
|
set_int64 (group_name, key, value) |
|
set_integer (group_name, key, value) |
|
set_integer_list (group_name, key, list) |
|
set_list_separator (separator) |
|
set_locale_string (group_name, key, locale, string) |
|
set_locale_string_list (group_name, key, locale, list) |
|
set_string (group_name, key, string) |
|
set_string_list (group_name, key, list) |
|
set_uint64 (group_name, key, value) |
|
set_value (group_name, key, value) |
|
to_data () |
|
unref () |
Details¶
-
class
GLib.
KeyFile
¶ The
GLib.KeyFile
struct contains only private data and should not be accessed directly.-
classmethod
new
()[source]¶ Returns: an empty GLib.KeyFile
.Return type: GLib.KeyFile
Creates a new empty
GLib.KeyFile
object. UseGLib.KeyFile.load_from_file
(),GLib.KeyFile.load_from_data
(),GLib.KeyFile.load_from_dirs
() orGLib.KeyFile.load_from_data_dirs
() to read an existing key file.New in version 2.6.
-
get_boolean
(group_name, key)[source]¶ Parameters: Raises: Returns: the value associated with the key as a boolean, or
False
if the key was not found or could not be parsed.Return type: Returns the value associated with key under group_name as a boolean.
If key cannot be found then
False
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the value associated with key cannot be interpreted as a boolean thenFalse
is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.6.
-
get_boolean_list
(group_name, key)[source]¶ Parameters: Raises: Returns: the values associated with the key as a list of booleans, or
None
if the key was not found or could not be parsed. The returned list of booleans should be freed withGLib.free
() when no longer needed.Return type: [
bool
]Returns the values associated with key under group_name as booleans.
If key cannot be found then
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the values associated with key cannot be interpreted as booleans thenNone
is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.6.
-
get_comment
(group_name, key)[source]¶ Parameters: Raises: Returns: a comment that should be freed with
GLib.free
()Return type: Retrieves a comment above key from group_name. If key is
None
then comment will be read from above group_name. If both key and group_name areNone
, then comment will be read from above the first group in the file.Note that the returned string does not include the ‘#’ comment markers, but does include any whitespace after them (on each line). It includes the line breaks between lines, but does not include the final line break.
New in version 2.6.
-
get_double
(group_name, key)[source]¶ Parameters: Raises: Returns: the value associated with the key as a double, or 0.0 if the key was not found or could not be parsed.
Return type: Returns the value associated with key under group_name as a double. If group_name is
None
, the start_group is used.If key cannot be found then 0.0 is returned and error is set to
GLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the value associated with key cannot be interpreted as a double then 0.0 is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.12.
-
get_double_list
(group_name, key)[source]¶ Parameters: Raises: Returns: the values associated with the key as a list of doubles, or
None
if the key was not found or could not be parsed. The returned list of doubles should be freed withGLib.free
() when no longer needed.Return type: [
float
]Returns the values associated with key under group_name as doubles.
If key cannot be found then
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the values associated with key cannot be interpreted as doubles thenNone
is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.12.
-
get_groups
()[source]¶ Returns: a newly-allocated None
-terminated array of strings. UseGLib.strfreev
() to free it.length: return location for the number of returned groups, or None
Return type: ([ str
], length:int
)Returns all groups in the key file loaded with self. The array of returned groups will be
None
-terminated, so length may optionally beNone
.New in version 2.6.
-
get_int64
(group_name, key)[source]¶ Parameters: Raises: Returns: the value associated with the key as a signed 64-bit integer, or 0 if the key was not found or could not be parsed.
Return type: Returns the value associated with key under group_name as a signed 64-bit integer. This is similar to
GLib.KeyFile.get_integer
() but can return 64-bit results without truncation.New in version 2.26.
-
get_integer
(group_name, key)[source]¶ Parameters: Raises: Returns: the value associated with the key as an integer, or 0 if the key was not found or could not be parsed.
Return type: Returns the value associated with key under group_name as an integer.
If key cannot be found then 0 is returned and error is set to
GLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the value associated with key cannot be interpreted as an integer, or is out of range for aint
, then 0 is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.6.
-
get_integer_list
(group_name, key)[source]¶ Parameters: Raises: Returns: the values associated with the key as a list of integers, or
None
if the key was not found or could not be parsed. The returned list of integers should be freed withGLib.free
() when no longer needed.Return type: [
int
]Returns the values associated with key under group_name as integers.
If key cannot be found then
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. Likewise, if the values associated with key cannot be interpreted as integers, or are out of range forint
, thenNone
is returned and error is set toGLib.KeyFileError.INVALID_VALUE
.New in version 2.6.
-
get_keys
(group_name)[source]¶ Parameters: group_name ( str
) – a group nameRaises: GLib.Error
Returns: a newly-allocated None
-terminated array of strings. UseGLib.strfreev
() to free it.length: return location for the number of keys returned, or None
Return type: ([ str
], length:int
)Returns all keys for the group name group_name. The array of returned keys will be
None
-terminated, so length may optionally beNone
. In the event that the group_name cannot be found,None
is returned and error is set toGLib.KeyFileError.GROUP_NOT_FOUND
.New in version 2.6.
-
get_locale_for_key
(group_name, key, locale)[source]¶ Parameters: Returns: the locale from the file, or
None
if the key was not found or the entry in the file was was untranslatedReturn type: Returns the actual locale which the result of
GLib.KeyFile.get_locale_string
() orGLib.KeyFile.get_locale_string_list
() came from.If calling
GLib.KeyFile.get_locale_string
() orGLib.KeyFile.get_locale_string_list
() with exactly the same self, group_name, key and locale, the result of those functions will have originally been tagged with the locale that is the result of this function.New in version 2.56.
-
get_locale_string
(group_name, key, locale)[source]¶ Parameters: Raises: Returns: a newly allocated string or
None
if the specified key cannot be found.Return type: Returns the value associated with key under group_name translated in the given locale if available. If locale is
None
then the current locale is assumed.If locale is to be non-
None
, or if the current locale will change over the lifetime of theGLib.KeyFile
, it must be loaded withGLib.KeyFileFlags.KEEP_TRANSLATIONS
in order to load strings for all locales.If key cannot be found then
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. If the value associated with key cannot be interpreted or no suitable translation can be found then the untranslated value is returned.New in version 2.6.
-
get_locale_string_list
(group_name, key, locale)[source]¶ Parameters: Raises: Returns: a newly allocated
None
-terminated string array orNone
if the key isn’t found. The string array should be freed withGLib.strfreev
().Return type: [
str
]Returns the values associated with key under group_name translated in the given locale if available. If locale is
None
then the current locale is assumed.If locale is to be non-
None
, or if the current locale will change over the lifetime of theGLib.KeyFile
, it must be loaded withGLib.KeyFileFlags.KEEP_TRANSLATIONS
in order to load strings for all locales.If key cannot be found then
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. If the values associated with key cannot be interpreted or no suitable translations can be found then the untranslated values are returned. The returned array isNone
-terminated, so length may optionally beNone
.New in version 2.6.
-
get_start_group
()[source]¶ Returns: The start group of the key file. Return type: str
Returns the name of the start group of the file.
New in version 2.6.
-
get_string
(group_name, key)[source]¶ Parameters: Raises: Returns: a newly allocated string or
None
if the specified key cannot be found.Return type: Returns the string value associated with key under group_name. Unlike
GLib.KeyFile.get_value
(), this function handles escape sequences like \s.In the event the key cannot be found,
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. In the event that the group_name cannot be found,None
is returned and error is set toGLib.KeyFileError.GROUP_NOT_FOUND
.New in version 2.6.
-
get_string_list
(group_name, key)[source]¶ Parameters: Raises: Returns: a
None
-terminated string array orNone
if the specified key cannot be found. The array should be freed withGLib.strfreev
().Return type: [
str
]Returns the values associated with key under group_name.
In the event the key cannot be found,
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. In the event that the group_name cannot be found,None
is returned and error is set toGLib.KeyFileError.GROUP_NOT_FOUND
.New in version 2.6.
-
get_uint64
(group_name, key)[source]¶ Parameters: Raises: Returns: the value associated with the key as an unsigned 64-bit integer, or 0 if the key was not found or could not be parsed.
Return type: Returns the value associated with key under group_name as an unsigned 64-bit integer. This is similar to
GLib.KeyFile.get_integer
() but can return large positive results without truncation.New in version 2.26.
-
get_value
(group_name, key)[source]¶ Parameters: Raises: Returns: a newly allocated string or
None
if the specified key cannot be found.Return type: Returns the raw value associated with key under group_name. Use
GLib.KeyFile.get_string
() to retrieve an unescaped UTF-8 string.In the event the key cannot be found,
None
is returned and error is set toGLib.KeyFileError.KEY_NOT_FOUND
. In the event that the group_name cannot be found,None
is returned and error is set toGLib.KeyFileError.GROUP_NOT_FOUND
.New in version 2.6.
-
has_group
(group_name)[source]¶ Parameters: group_name ( str
) – a group nameReturns: True
if group_name is a part of self,False
otherwise.Return type: bool
Looks whether the key file has the group group_name.
New in version 2.6.
-
load_from_bytes
(bytes, flags)[source]¶ Parameters: - bytes (
GLib.Bytes
) – aGLib.Bytes
- flags (
GLib.KeyFileFlags
) – flags fromGLib.KeyFileFlags
Raises: Returns: Return type: Loads a key file from the data in bytes into an empty
GLib.KeyFile
structure. If the object cannot be created then %error is set to aGLib.KeyFileError
.New in version 2.50.
- bytes (
-
load_from_data
(data, length, flags)[source]¶ Parameters: - data (
str
) – key file loaded in memory - length (
int
) – the length of data in bytes (or (gsize)-1 if data is nul-terminated) - flags (
GLib.KeyFileFlags
) – flags fromGLib.KeyFileFlags
Raises: Returns: Return type: Loads a key file from memory into an empty
GLib.KeyFile
structure. If the object cannot be created then %error is set to aGLib.KeyFileError
.New in version 2.6.
- data (
-
load_from_data_dirs
(file, flags)[source]¶ Parameters: - file (
str
) – a relative path to a filename to open and parse - flags (
GLib.KeyFileFlags
) – flags fromGLib.KeyFileFlags
Raises: Returns: True
if a key file could be loaded,False
otherwisefull_path: return location for a string containing the full path of the file, or None
Return type: This function looks for a key file named file in the paths returned from
GLib.get_user_data_dir
() andGLib.get_system_data_dirs
(), loads the file into self and returns the file’s full path in full_path. If the file could not be loaded then an %error is set to either aGLib.FileError
orGLib.KeyFileError
.New in version 2.6.
- file (
-
load_from_dirs
(file, search_dirs, flags)[source]¶ Parameters: - file (
str
) – a relative path to a filename to open and parse - search_dirs ([
str
]) –None
-terminated array of directories to search - flags (
GLib.KeyFileFlags
) – flags fromGLib.KeyFileFlags
Raises: Returns: True
if a key file could be loaded,False
otherwisefull_path: return location for a string containing the full path of the file, or None
Return type: This function looks for a key file named file in the paths specified in search_dirs, loads the file into self and returns the file’s full path in full_path.
If the file could not be found in any of the search_dirs,
GLib.KeyFileError.NOT_FOUND
is returned. If the file is found but the OS returns an error when opening or reading the file, a %G_FILE_ERROR is returned. If there is a problem parsing the file, a %G_KEY_FILE_ERROR is returned.New in version 2.14.
- file (
-
load_from_file
(file, flags)[source]¶ Parameters: - file (
str
) – the path of a filename to load, in the GLib filename encoding - flags (
GLib.KeyFileFlags
) – flags fromGLib.KeyFileFlags
Raises: Returns: Return type: Loads a key file into an empty
GLib.KeyFile
structure.If the OS returns an error when opening or reading the file, a %G_FILE_ERROR is returned. If there is a problem parsing the file, a %G_KEY_FILE_ERROR is returned.
This function will never return a
GLib.KeyFileError.NOT_FOUND
error. If the file is not found,GLib.FileError.NOENT
is returned.New in version 2.6.
- file (
-
remove_comment
(group_name, key)[source]¶ Parameters: Raises: Returns: Return type: Removes a comment above key from group_name. If key is
None
then comment will be removed above group_name. If both key and group_name areNone
, then comment will be removed above the first group in the file.New in version 2.6.
-
remove_group
(group_name)[source]¶ Parameters: group_name ( str
) – a group nameRaises: GLib.Error
Returns: True
if the group was removed,False
otherwiseReturn type: bool
Removes the specified group, group_name, from the key file.
New in version 2.6.
-
remove_key
(group_name, key)[source]¶ Parameters: Raises: Returns: Return type: Removes key in group_name from the key file.
New in version 2.6.
-
save_to_file
(filename)[source]¶ Parameters: filename ( str
) – the name of the file to write toRaises: GLib.Error
Returns: True
if successful, elseFalse
with error setReturn type: bool
Writes the contents of self to filename using
GLib.file_set_contents
(). If you need stricter guarantees about durability of the written file than are provided byGLib.file_set_contents
(), useGLib.file_set_contents_full
() with the return value ofGLib.KeyFile.to_data
().This function can fail for any of the reasons that
GLib.file_set_contents
() may fail.New in version 2.40.
-
set_boolean
(group_name, key, value)[source]¶ Parameters: Associates a new boolean value with key under group_name. If key cannot be found then it is created.
New in version 2.6.
-
set_boolean_list
(group_name, key, list)[source]¶ Parameters: Associates a list of boolean values with key under group_name. If key cannot be found then it is created. If group_name is
None
, the start_group is used.New in version 2.6.
-
set_comment
(group_name, key, comment)[source]¶ Parameters: Raises: Returns: Return type: Places a comment above key from group_name.
If key is
None
then comment will be written above group_name. If both key and group_name areNone
, then comment will be written above the first group in the file.Note that this function prepends a ‘#’ comment marker to each line of comment.
New in version 2.6.
-
set_double
(group_name, key, value)[source]¶ Parameters: Associates a new double value with key under group_name. If key cannot be found then it is created.
New in version 2.12.
-
set_double_list
(group_name, key, list)[source]¶ Parameters: Associates a list of double values with key under group_name. If key cannot be found then it is created.
New in version 2.12.
-
set_int64
(group_name, key, value)[source]¶ Parameters: Associates a new integer value with key under group_name. If key cannot be found then it is created.
New in version 2.26.
-
set_integer
(group_name, key, value)[source]¶ Parameters: Associates a new integer value with key under group_name. If key cannot be found then it is created.
New in version 2.6.
-
set_integer_list
(group_name, key, list)[source]¶ Parameters: Associates a list of integer values with key under group_name. If key cannot be found then it is created.
New in version 2.6.
-
set_list_separator
(separator)[source]¶ Parameters: separator ( int
) – the separatorSets the character which is used to separate values in lists. Typically ‘;’ or ‘,’ are used as separators. The default list separator is ‘;’.
New in version 2.6.
-
set_locale_string
(group_name, key, locale, string)[source]¶ Parameters: Associates a string value for key and locale under group_name. If the translation for key cannot be found then it is created.
New in version 2.6.
-
set_locale_string_list
(group_name, key, locale, list)[source]¶ Parameters: Associates a list of string values for key and locale under group_name. If the translation for key cannot be found then it is created.
New in version 2.6.
-
set_string
(group_name, key, string)[source]¶ Parameters: Associates a new string value with key under group_name. If key cannot be found then it is created. If group_name cannot be found then it is created. Unlike
GLib.KeyFile.set_value
(), this function handles characters that need escaping, such as newlines.New in version 2.6.
-
set_string_list
(group_name, key, list)[source]¶ Parameters: Associates a list of string values for key under group_name. If key cannot be found then it is created. If group_name cannot be found then it is created.
New in version 2.6.
-
set_uint64
(group_name, key, value)[source]¶ Parameters: Associates a new integer value with key under group_name. If key cannot be found then it is created.
New in version 2.26.
-
set_value
(group_name, key, value)[source]¶ Parameters: Associates a new value with key under group_name.
If key cannot be found then it is created. If group_name cannot be found then it is created. To set an UTF-8 string which may contain characters that need escaping (such as newlines or spaces), use
GLib.KeyFile.set_string
().New in version 2.6.
-
to_data
()[source]¶ Raises: GLib.Error
Returns: a newly allocated string holding the contents of the GLib.KeyFile
length: return location for the length of the returned string, or None
Return type: ( str
, length:int
)This function outputs self as a string.
Note that this function never reports an error, so it is safe to pass
None
as error.New in version 2.6.
-
classmethod