[pygobject] Drop unnecessary static _glib bindings
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Drop unnecessary static _glib bindings
- Date: Tue, 23 Oct 2012 06:19:11 +0000 (UTC)
commit fb473b31054744e5ab59e9d4ed3b74571e27d3ff
Author: Martin Pitt <martinpitt gnome org>
Date: Tue Oct 23 07:48:52 2012 +0200
Drop unnecessary static _glib bindings
Drop static pyglib bindings which have straightforward and working GLib GI
bindings. Add tests for all dropped functions to ensure they keep working.
docs/reference/pyglib-constants.xml | 59 -------
docs/reference/pyglib-functions.xml | 270 -----------------------------
gi/_glib/__init__.py | 24 ---
gi/_glib/glibmodule.c | 319 -----------------------------------
gi/_gobject/__init__.py | 9 -
gi/overrides/GLib.py | 16 ++
gi/overrides/GObject.py | 32 ++++
gi/overrides/Makefile.am | 1 +
tests/Makefile.am | 1 -
tests/test_glib.py | 46 +++++
tests/test_gobject.py | 4 +
tests/test_uris.py | 16 --
12 files changed, 99 insertions(+), 698 deletions(-)
---
diff --git a/docs/reference/pyglib-constants.xml b/docs/reference/pyglib-constants.xml
index 0f1bf8d..4f4f37b 100644
--- a/docs/reference/pyglib-constants.xml
+++ b/docs/reference/pyglib-constants.xml
@@ -193,65 +193,6 @@ of <parameter>argv</parameter> to the child.</simpara>
</refsect2>
- <refsect2 id="glib-user-directory-constants">
- <title id="glib-user-directory-constants-title">Glib User Directory Constants</title>
-
- <para>The User Directory constants are integer values that are currently used only as arguments to
- <link linkend="function-glib--get-user-special-dir"><function>glib.get_user_special_dir</function>()</link>
- function. See function documentation for details.</para>
-
- <variablelist>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_DESKTOP</literal></term>
- <listitem>
- <simpara>the user's Desktop directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_DOCUMENTS</literal></term>
- <listitem>
- <simpara>the user's Documents directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_DOWNLOAD</literal></term>
- <listitem>
- <simpara>the user's Downloads directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_MUSIC</literal></term>
- <listitem>
- <simpara>the user's Music directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_PICTURES</literal></term>
- <listitem>
- <simpara>the user's Pictures directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_PUBLIC_SHARE</literal></term>
- <listitem>
- <simpara>the user's shared directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_TEMPLATES</literal></term>
- <listitem>
- <simpara>the user's Templates directory</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.USER_DIRECTORY_VIDEOS</literal></term>
- <listitem>
- <simpara>the user's Movies directory</simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsect2>
-
<refsect2 id="glib-version-constants">
<title id="glib-version-constants-title">Glib Version Constants</title>
<para>The Version constants specify the version of
diff --git a/docs/reference/pyglib-functions.xml b/docs/reference/pyglib-functions.xml
index 3e11251..7c4204e 100644
--- a/docs/reference/pyglib-functions.xml
+++ b/docs/reference/pyglib-functions.xml
@@ -45,10 +45,6 @@ linkend="function-glib--source-remove">glib.source_remove</link></methodname>
linkend="function-glib--main-context-default">glib.main_context_default</link></methodname>
<methodparam></methodparam>
</methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-glib--markup-escape-text">glib.markup_escape_text</link></methodname>
- <methodparam><parameter role="keyword">text</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
<methodname><link linkend="function-glib--child-watch-add">glib.child_watch_add</link></methodname>
<methodparam><parameter role="keyword">pid</parameter></methodparam>
<methodparam><parameter role="keyword">function</parameter></methodparam>
@@ -71,33 +67,9 @@ linkend="function-glib--spawn-async">glib.spawn_async</link></methodname>
linkend="function-glib--get-current-time">glib.get_current_time</link></methodname>
</methodsynopsis><methodsynopsis language="python">
<methodname><link
- linkend="function-glib--get-user-cache-dir">glib.get_user_cache_dir</link></methodname>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
- linkend="function-glib--get-user-config-dir">glib.get_user_config_dir</link></methodname>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
- linkend="function-glib--get-user-data-dir">glib.get_user_data_dir</link></methodname>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
- linkend="function-glib--get-user-special-dir">glib.get_user_special_dir</link></methodname>
- <methodparam><parameter role="keyword">directory</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-glib--main-depth">glib.main_depth</link></methodname>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
linkend="function-glib--threads-init">glib.threads_init</link></methodname>
</methodsynopsis><methodsynopsis language="python">
<methodname><link
-linkend="function-glib--filename-display-name">glib.filename_display_name</link></methodname>
- <methodparam><parameter>filename</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-glib--filename-display-basename">glib.filename_display_basename</link></methodname>
- <methodparam><parameter>filename</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
linkend="function-glib--filename-from-utf8">glib.filename_from_utf8</link></methodname>
<methodparam><parameter>utf8string</parameter></methodparam>
</methodsynopsis></programlisting>
@@ -730,172 +702,6 @@ from the epoch.</para>
</refsect2>
- <refsect2 id="function-glib--get-user-cache-dir">
- <title>glib.get_user_cache_dir</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.get_user_cache_dir</methodname>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem>
- <simpara>
- a strings with a path to user's cache directory.
- </simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGObject 2.18 and above.</para>
- </note>
-
- <para>Returns a base directory in which to store non-essential,
- cached data specific to particular user.</para>
-
- <para>On UNIX platforms this is determined using the mechanisms
- described in the
- <ulink url="http://www.freedesktop.org/Standards/basedir-spec">XDG
- Base Directory Specification</ulink>.</para>
- </refsect2>
-
- <refsect2 id="function-glib--get-user-config-dir">
- <title>glib.get_user_config_dir</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.get_user_config_dir</methodname>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem>
- <simpara>
- a strings with a path to user's configuration directory.
- </simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGObject 2.18 and above.</para>
- </note>
-
- <para>Returns a base directory in which to store user-specific
- application configuration information such as user preferences
- and settings. </para>
-
- <para>On UNIX platforms this is determined using the mechanisms
- described in the
- <ulink url="http://www.freedesktop.org/Standards/basedir-spec">XDG
- Base Directory Specification</ulink>.</para>
- </refsect2>
-
- <refsect2 id="function-glib--get-user-data-dir">
- <title>glib.get_user_data_dir</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.get_user_data_dir</methodname>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem>
- <simpara>
- a strings with a path to user's data directory.
- </simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGObject 2.18 and above.</para>
- </note>
-
- <para>Returns a base directory in which to access application
- data such as icons that is customized for a particular
- user</para>
-
- <para>On UNIX platforms this is determined using the mechanisms
- described in the
- <ulink url="http://www.freedesktop.org/Standards/basedir-spec">XDG
- Base Directory Specification</ulink>.</para>
- </refsect2>
-
- <refsect2 id="function-glib--get-user-special-dir">
- <title>glib.get_user_special_dir</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.get_user_special_dir</methodname>
- <methodparam><parameter>directory</parameter></methodparam>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>directory</emphasis> :</term>
- <listitem>
- <simpara>
- the logical id of special directory,
- see <link linkend="glib-user-directory-constants">User
- Directory constants</link> for the list of supported
- values
- </simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem>
- <simpara>
- a strings with a path to the requested directory.
- </simpara>
- </listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGObject 2.18 and above.</para>
- </note>
-
- <para>Returns the full path of a special directory using its
- logical id.</para>
-
- <para>On Unix this is done using the XDG special user
- directories. For compatibility with existing practise,
- <link linkend="glib-user-directory-constants">glib.USER_DIRECTORY_DESKTOP</link>
- falls back to <literal>$HOME/Desktop</literal> when XDG
- special user directories have not been set up.</para>
-
- <para>Depending on the platform, the user might be able to
- change the path of the special directory without requiring the
- session to restart; GLib will not reflect any change once the
- special directories are loaded.</para>
- </refsect2>
-
- <refsect2 id="function-glib--main-depth">
- <title>glib.main_depth</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.main_depth</methodname>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem><simpara>the depth of the stack of calls to the main
-context.</simpara></listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGTK 2.8 and above.</para>
- </note>
-
- <para>The <function>main_depth</function>() function returns the depth
-of the stack of calls in the main context. That is, when called from the
-toplevel, it gives 0. When called from within a callback from the <link
-linkend="method-glibmaincontext--iteration"><methodname>glib.MainContext.iteration</methodname>()</link>
-method (or the <link
-linkend="method-glibmainloop--run"><methodname>glib.MainLoop.run</methodname>()</link>
-method, etc.) it returns 1. When called from within a callback to a
-recursive call to the <link
-linkend="method-glibmaincontext--iteration"><methodname>glib.MainContext.iteration</methodname>()</link>
-method), it returns 2. And so forth.</para>
-
- </refsect2>
-
<refsect2 id="function-glib--threads-init">
<title>glib.threads_init</title>
@@ -938,82 +744,6 @@ method), it returns 2. And so forth.</para>
</refsect2>
- <refsect2 id="function-glib--filename-display-name">
- <title>glib.filename_display_name</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.filename_display_name</methodname>
- <methodparam><parameter>filename</parameter></methodparam>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>filename</emphasis> :</term>
- <listitem><simpara>a pathname in the file name
- encoding</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem><simpara>an UTF8 rendition of
- <parameter>filename</parameter>.</simpara></listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGTK 2.10 and above.</para>
- </note>
-
- <para>The <function>filename_display_name</function>() function
- converts a filename into a valid UTF-8 string. The conversion is not
- necessarily reversible, so you should keep the original around and use
- the return value of this function only for display purposes. Unlike
- g_filename_to_utf8(), the result is guaranteed to be non-None even if
- the filename actually isn't in the file name encoding.</para>
-
- <para>If you know the whole pathname of the file you should use the
- <link
- linkend="function-glib--filename-display-basename"><function>glib.filename_display_basename</function>()</link>
- function, since that allows location-based translation of
- filenames.</para>
-
- </refsect2>
-
- <refsect2 id="function-glib--filename-display-basename">
- <title>glib.filename_display_basename</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.filename_display_basename</methodname>
- <methodparam><parameter>filename</parameter></methodparam>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>filename</emphasis> :</term>
- <listitem><simpara>an absolute pathname in the file name
- encoding</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem><simpara>an UTF8 rendition of
- <parameter>filename</parameter>.</simpara></listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGTK 2.10 and above.</para>
- </note>
-
- <para>The <function>filename_display_basename</function>() function
- returns the display basename for the particular filename, guaranteed
- to be valid UTF-8. The display name might not be identical to the
- filename, for instance there might be problems converting it to UTF-8,
- and some files can be translated in the display.</para>
-
- <para>You must pass the whole absolute pathname to this functions so
- that translation of well known locations can be done.</para>
-
- <para>This function is preferred over the <link
- linkend="function-glib--filename-display-name"><function>glib.filename_display_name</function>()</link>
- function if you know the whole path, as it allows translation.</para>
-
- </refsect2>
-
<refsect2 id="function-glib--filename-from-utf8">
<title>glib.filename_from_utf8</title>
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index b0d2212..378d981 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -80,42 +80,18 @@ SPAWN_LEAVE_DESCRIPTORS_OPEN = _glib.SPAWN_LEAVE_DESCRIPTORS_OPEN
SPAWN_SEARCH_PATH = _glib.SPAWN_SEARCH_PATH
SPAWN_STDERR_TO_DEV_NULL = _glib.SPAWN_STDERR_TO_DEV_NULL
SPAWN_STDOUT_TO_DEV_NULL = _glib.SPAWN_STDOUT_TO_DEV_NULL
-USER_DIRECTORY_DESKTOP = _glib.USER_DIRECTORY_DESKTOP
-USER_DIRECTORY_DOCUMENTS = _glib.USER_DIRECTORY_DOCUMENTS
-USER_DIRECTORY_DOWNLOAD = _glib.USER_DIRECTORY_DOWNLOAD
-USER_DIRECTORY_MUSIC = _glib.USER_DIRECTORY_MUSIC
-USER_DIRECTORY_PICTURES = _glib.USER_DIRECTORY_PICTURES
-USER_DIRECTORY_PUBLIC_SHARE = _glib.USER_DIRECTORY_PUBLIC_SHARE
-USER_DIRECTORY_TEMPLATES = _glib.USER_DIRECTORY_TEMPLATES
-USER_DIRECTORY_VIDEOS = _glib.USER_DIRECTORY_VIDEOS
# Functions
child_watch_add = _glib.child_watch_add
-filename_display_basename = _glib.filename_display_basename
-filename_display_name = _glib.filename_display_name
filename_from_utf8 = _glib.filename_from_utf8
-find_program_in_path = _glib.find_program_in_path
-get_application_name = _glib.get_application_name
get_current_time = _glib.get_current_time
-get_prgname = _glib.get_prgname
-get_system_config_dirs = _glib.get_system_config_dirs
-get_system_data_dirs = _glib.get_system_data_dirs
-get_user_cache_dir = _glib.get_user_cache_dir
-get_user_config_dir = _glib.get_user_config_dir
-get_user_data_dir = _glib.get_user_data_dir
-get_user_special_dir = _glib.get_user_special_dir
glib_version = _glib.glib_version
idle_add = _glib.idle_add
io_add_watch = _glib.io_add_watch
main_context_default = _glib.main_context_default
-main_depth = _glib.main_depth
-markup_escape_text = _glib.markup_escape_text
pyglib_version = _glib.pyglib_version
-set_application_name = _glib.set_application_name
-set_prgname = _glib.set_prgname
source_remove = _glib.source_remove
spawn_async = _glib.spawn_async
threads_init = _glib.threads_init
timeout_add = _glib.timeout_add
timeout_add_seconds = _glib.timeout_add_seconds
-uri_list_extract_uris = _glib.uri_list_extract_uris
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index 4dea68c..791bd93 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -389,25 +389,6 @@ pyglib_child_watch_add(PyObject *unused, PyObject *args, PyObject *kwargs)
}
static PyObject *
-pyglib_markup_escape_text(PyObject *unused, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "text", NULL };
- char *text_in, *text_out;
- Py_ssize_t text_size;
- PyObject *retval;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "s#:glib.markup_escape_text", kwlist,
- &text_in, &text_size))
- return NULL;
-
- text_out = g_markup_escape_text(text_in, text_size);
- retval = PYGLIB_PyUnicode_FromString(text_out);
- g_free(text_out);
- return retval;
-}
-
-static PyObject *
pyglib_get_current_time(PyObject *unused)
{
GTimeVal timeval;
@@ -416,96 +397,6 @@ pyglib_get_current_time(PyObject *unused)
return pyglib_float_from_timeval(timeval);
}
-static PyObject*
-get_user_dir(const char *path)
-{
- if (path)
- return PYGLIB_PyUnicode_FromString(path);
- else {
- Py_INCREF(Py_None);
- return Py_None;
- }
-}
-
-static PyObject*
-pyglib_get_user_config_dir(PyObject *self)
-{
- return get_user_dir(g_get_user_config_dir());
-}
-
-static PyObject*
-pyglib_get_user_cache_dir(PyObject *self)
-{
- return get_user_dir(g_get_user_cache_dir());
-}
-
-static PyObject*
-pyglib_get_user_data_dir(PyObject *self)
-{
- return get_user_dir(g_get_user_data_dir());
-}
-
-static PyObject *
-pyglib_get_user_special_dir(PyObject *unused, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "directory", NULL };
- guint directory;
- const char *path;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "i:glib.get_user_special_dir", kwlist,
- &directory))
- return NULL;
-
- path = g_get_user_special_dir(directory);
- if (path)
- return PYGLIB_PyUnicode_FromString(path);
- else {
- Py_INCREF(Py_None);
- return Py_None;
- }
-}
-
-static PyObject *
-pyglib_main_depth(PyObject *unused)
-{
- return PYGLIB_PyLong_FromLong(g_main_depth());
-}
-
-static PyObject *
-pyglib_filename_display_name(PyObject *self, PyObject *args)
-{
- PyObject *py_display_name;
- char *filename, *display_name;
-
- if (!PyArg_ParseTuple(args, "s:glib.filename_display_name",
- &filename))
- return NULL;
-
- display_name = g_filename_display_name(filename);
- py_display_name = PyUnicode_DecodeUTF8(display_name,
- strlen(display_name), NULL);
- g_free(display_name);
- return py_display_name;
-}
-
-static PyObject *
-pyglib_filename_display_basename(PyObject *self, PyObject *args)
-{
- PyObject *py_display_basename;
- char *filename, *display_basename;
-
- if (!PyArg_ParseTuple(args, "s:glib.filename_display_basename",
- &filename))
- return NULL;
-
- display_basename = g_filename_display_basename(filename);
- py_display_basename = PyUnicode_DecodeUTF8(display_basename,
- strlen(display_basename), NULL);
- g_free(display_basename);
- return py_display_basename;
-}
-
static PyObject *
pyglib_filename_from_utf8(PyObject *self, PyObject *args)
{
@@ -530,161 +421,6 @@ pyglib_filename_from_utf8(PyObject *self, PyObject *args)
return py_filename;
}
-
-static PyObject*
-pyglib_get_application_name(PyObject *self)
-{
- const char *name;
-
- name = g_get_application_name();
- if (!name) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PYGLIB_PyUnicode_FromString(name);
-}
-
-static PyObject*
-pyglib_set_application_name(PyObject *self, PyObject *arg)
-{
- PyObject *repr = NULL;
- if (!PYGLIB_PyUnicode_Check(arg)) {
- repr = PyObject_Repr(arg);
- PyErr_Format(PyExc_TypeError,
- "first argument must be a string, not '%s'",
- PYGLIB_PyUnicode_AsString(repr));
- Py_DECREF(repr);
- return NULL;
- }
- g_set_application_name(PYGLIB_PyUnicode_AsString(arg));
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject*
-pyglib_get_prgname(PyObject *self)
-{
- char *name;
-
- name = g_get_prgname();
- if (!name) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PYGLIB_PyUnicode_FromString(name);
-}
-
-static PyObject*
-pyglib_set_prgname(PyObject *self, PyObject *arg)
-{
- PyObject *repr = NULL;
- if (!PYGLIB_PyUnicode_Check(arg)) {
- repr = PyObject_Repr(arg);
- PyErr_Format(PyExc_TypeError,
- "first argument must be a string, not '%s'",
- PYGLIB_PyUnicode_AsString(repr));
- Py_DECREF(repr);
- return NULL;
- }
- g_set_prgname(PYGLIB_PyUnicode_AsString(arg));
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-pyglib_find_program_in_path(PyObject *unused, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "program", NULL };
- char *program, *ret;
- PyObject *retval;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "s:glib.find_program_in_path", kwlist,
- &program))
- return NULL;
-
- ret = g_find_program_in_path(program);
-
- if (ret != NULL) {
- retval = PYGLIB_PyUnicode_FromString(ret);
- g_free(ret);
- } else {
- Py_INCREF(Py_None);
- retval = Py_None;
- }
- return retval;
-}
-
-static PyObject *
-pyglib_uri_list_extract_uris(PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "uri_list", NULL };
- char *uri_list;
- char **uris, **tmp;
- int i = 0, j;
- PyObject *ret;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,"s:uri_list_extract_uris", kwlist, &uri_list))
- return NULL;
-
- uris = (char **)g_uri_list_extract_uris(uri_list);
- if (!uris) {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- tmp = uris;
- while (*tmp)
- tmp++, i++;
-
- ret = PyTuple_New(i);
- for (j = 0; j < i; j++)
- PyTuple_SetItem(ret, j, PYGLIB_PyUnicode_FromString(uris[j]));
-
- g_strfreev(uris);
-
- return ret;
-}
-
-/* FIXME: we should use strv_to_pylist (in pygio-utils.h) here, but that
- * function should be moved into pyglib first. See
- * https://bugzilla.gnome.org/show_bug.cgi?id=630508
- */
-static PyObject *
-tuple_of_strings_from_dirs(const gchar* const *dirs)
-{
- char **tmp;
- int i = 0, j;
- PyObject *ret;
-
- if (!dirs) {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- tmp = (char **)dirs;
- while (*tmp)
- tmp++, i++;
-
- ret = PyTuple_New(i);
- for (j = 0; j < i; j++)
- PyTuple_SetItem(ret, j, PYGLIB_PyUnicode_FromString(dirs[j]));
-
- return ret;
-}
-
-static PyObject*
-pyglib_get_system_config_dirs(PyObject *self)
-{
- return tuple_of_strings_from_dirs(g_get_system_config_dirs());
-}
-
-static PyObject*
-pyglib_get_system_data_dirs(PyObject *self)
-{
- return tuple_of_strings_from_dirs(g_get_system_data_dirs());
-}
-
static PyMethodDef _glib_functions[] = {
{ "threads_init",
(PyCFunction) pyglib_threads_init, METH_NOARGS,
@@ -748,48 +484,10 @@ static PyMethodDef _glib_functions[] = {
"main_context_default() -> a main context\n"
"Returns the default main context. This is the main context used\n"
"for main loop functions when a main loop is not explicitly specified." },
- { "main_depth",
- (PyCFunction)pyglib_main_depth, METH_NOARGS,
- "main_depth() -> stack depth\n"
- "Returns the depth of the stack of calls in the main context." },
- { "filename_display_name",
- (PyCFunction)pyglib_filename_display_name, METH_VARARGS },
- { "filename_display_basename",
- (PyCFunction)pyglib_filename_display_basename, METH_VARARGS },
{ "filename_from_utf8",
(PyCFunction)pyglib_filename_from_utf8, METH_VARARGS },
- { "get_application_name",
- (PyCFunction)pyglib_get_application_name, METH_NOARGS },
- { "set_application_name",
- (PyCFunction)pyglib_set_application_name, METH_O },
- { "get_prgname",
- (PyCFunction)pyglib_get_prgname, METH_NOARGS },
- { "set_prgname",
- (PyCFunction)pyglib_set_prgname, METH_O },
{ "get_current_time",
(PyCFunction)pyglib_get_current_time, METH_NOARGS },
- { "get_user_cache_dir",
- (PyCFunction)pyglib_get_user_cache_dir, METH_NOARGS },
- { "get_user_config_dir",
- (PyCFunction)pyglib_get_user_config_dir, METH_NOARGS },
- { "get_user_data_dir",
- (PyCFunction)pyglib_get_user_data_dir, METH_NOARGS },
- { "get_user_special_dir",
- (PyCFunction)pyglib_get_user_special_dir, METH_VARARGS|METH_KEYWORDS },
- { "markup_escape_text",
- (PyCFunction)pyglib_markup_escape_text, METH_VARARGS|METH_KEYWORDS },
- { "find_program_in_path",
- (PyCFunction)pyglib_find_program_in_path, METH_VARARGS|METH_KEYWORDS },
- { "uri_list_extract_uris",
- (PyCFunction)pyglib_uri_list_extract_uris, METH_VARARGS|METH_KEYWORDS,
- "uri_list_extract_uris(uri_list) -> tuple of strings holding URIs\n"
- "Splits an string containing an URI list conforming to the \n"
- "text/uri-list mime type defined in RFC 2483 into individual URIs, \n"
- "discarding any comments. The URIs are not validated." },
- { "get_system_config_dirs",
- (PyCFunction)pyglib_get_system_config_dirs, METH_NOARGS },
- { "get_system_data_dirs",
- (PyCFunction)pyglib_get_system_data_dirs, METH_NOARGS },
{ NULL, NULL, 0 }
};
@@ -939,23 +637,6 @@ pyglib_register_constants(PyObject *m)
PyModule_AddIntConstant(m, "OPTION_ERROR_FAILED",
G_OPTION_ERROR_FAILED);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_DESKTOP",
- G_USER_DIRECTORY_DESKTOP);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_DOCUMENTS",
- G_USER_DIRECTORY_DOCUMENTS);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_DOWNLOAD",
- G_USER_DIRECTORY_DOWNLOAD);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_MUSIC",
- G_USER_DIRECTORY_MUSIC);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_PICTURES",
- G_USER_DIRECTORY_PICTURES);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_PUBLIC_SHARE",
- G_USER_DIRECTORY_PUBLIC_SHARE);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_TEMPLATES",
- G_USER_DIRECTORY_TEMPLATES);
- PyModule_AddIntConstant(m, "USER_DIRECTORY_VIDEOS",
- G_USER_DIRECTORY_VIDEOS);
-
PyModule_AddStringConstant(m, "OPTION_REMAINING",
G_OPTION_REMAINING);
PyModule_AddStringConstant(m, "OPTION_ERROR",
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index f12d3fe..ba6f7de 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -88,16 +88,8 @@ timeout_add_seconds = _glib.timeout_add_seconds
io_add_watch = _glib.io_add_watch
source_remove = _glib.source_remove
child_watch_add = _glib.child_watch_add
-markup_escape_text = _glib.markup_escape_text
get_current_time = _glib.get_current_time
-filename_display_name = _glib.filename_display_name
-filename_display_basename = _glib.filename_display_basename
filename_from_utf8 = _glib.filename_from_utf8
-get_application_name = _glib.get_application_name
-set_application_name = _glib.set_application_name
-get_prgname = _glib.get_prgname
-set_prgname = _glib.set_prgname
-main_depth = _glib.main_depth
Pid = _glib.Pid
GError = _glib.GError
glib_version = _glib.glib_version
@@ -111,7 +103,6 @@ Timeout = _glib.Timeout
PollFD = _glib.PollFD
OptionGroup = _glib.OptionGroup
OptionContext = _glib.OptionContext
-uri_list_extract_uris = _glib.uri_list_extract_uris
SPAWN_LEAVE_DESCRIPTORS_OPEN = _glib.SPAWN_LEAVE_DESCRIPTORS_OPEN
SPAWN_DO_NOT_REAP_CHILD = _glib.SPAWN_DO_NOT_REAP_CHILD
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index b6f2ce2e..3dcc618 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -2,6 +2,7 @@
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2010 Tomeu Vizoso <tomeu vizoso collabora co uk>
+# Copyright (C) 2011, 2012 Canonical Ltd.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -406,3 +407,18 @@ setattr(Variant, 'new_tuple', new_tuple)
setattr(Variant, 'get_string', get_string)
__all__.append('Variant')
+
+
+def markup_escape_text(text, length=-1):
+ if isinstance(text, bytes):
+ return GLib.markup_escape_text(text.decode('UTF-8'), length)
+ else:
+ return GLib.markup_escape_text(text, length)
+__all__.append('markup_escape_text')
+
+
+# backwards compatible names from old static bindings
+for n in ['DESKTOP', 'DOCUMENTS', 'DOWNLOAD', 'MUSIC', 'PICTURES',
+ 'PUBLIC_SHARE', 'TEMPLATES', 'VIDEOS']:
+ exec('USER_DIRECTORY_%s = GLib.UserDirectory.DIRECTORY_%s' % (n, n))
+ __all__.append('USER_DIRECTORY_' + n)
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
new file mode 100644
index 0000000..3af4d44
--- /dev/null
+++ b/gi/overrides/GObject.py
@@ -0,0 +1,32 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2012 Canonical Ltd.
+# Author: Martin Pitt <martin pitt ubuntu com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+# USA
+
+from gi.repository import GLib
+
+__all__ = []
+
+# API aliases for backwards compatibility
+for name in ['markup_escape_text', 'get_application_name',
+ 'set_application_name', 'get_prgname', 'set_prgname',
+ 'main_depth', 'filename_display_basename',
+ 'filename_display_name', 'uri_list_extract_uris']:
+ globals()[name] = getattr(GLib, name)
+ __all__.append(name)
diff --git a/gi/overrides/Makefile.am b/gi/overrides/Makefile.am
index 8d95eee..e69c91c 100644
--- a/gi/overrides/Makefile.am
+++ b/gi/overrides/Makefile.am
@@ -4,6 +4,7 @@ pygioverrides_PYTHON = \
GLib.py \
Gtk.py \
Gdk.py \
+ GObject.py \
Gio.py \
GIMarshallingTests.py \
Pango.py \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7a619bf..ff264f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -94,7 +94,6 @@ EXTRA_DIST = \
test_source.py \
test_subprocess.py \
test_thread.py \
- test_uris.py \
test_everything.py \
test_gi.py \
test_gdbus.py \
diff --git a/tests/test_glib.py b/tests/test_glib.py
index a36eca6..97d7648 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -1,10 +1,13 @@
# -*- Mode: Python -*-
+# encoding: UTF-8
import unittest
import os.path
from gi.repository import GLib
+from compathelper import _unicode, _bytes
+
class TestGLib(unittest.TestCase):
def test_find_program_in_path(self):
@@ -13,3 +16,46 @@ class TestGLib(unittest.TestCase):
self.assertTrue(os.path.exists(bash_path))
self.assertEqual(GLib.find_program_in_path('non existing'), None)
+
+ def test_markup_escape_text(self):
+ self.assertEqual(GLib.markup_escape_text(_unicode('a&bÃ')), 'a&bÃ')
+ self.assertEqual(GLib.markup_escape_text(_bytes('a&b\x05')), 'a&b')
+
+ # with explicit length argument
+ self.assertEqual(GLib.markup_escape_text(_bytes('a\x05\x01\x02'), 2), 'a')
+
+ def test_progname(self):
+ GLib.set_prgname('moo')
+ self.assertEqual(GLib.get_prgname(), 'moo')
+
+ def test_appname(self):
+ GLib.set_application_name('moo')
+ self.assertEqual(GLib.get_application_name(), 'moo')
+
+ def test_xdg_dirs(self):
+ self.assertTrue(os.path.isdir(GLib.get_user_data_dir()))
+ self.assertTrue(os.path.isdir(GLib.get_user_special_dir(GLib.USER_DIRECTORY_DESKTOP)))
+ # also works with backwards compatible enum names
+ self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC),
+ GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))
+
+ for d in GLib.get_system_config_dirs():
+ self.assertTrue('/' in d, d)
+ for d in GLib.get_system_data_dirs():
+ self.assertTrue('/' in d, d)
+
+ def test_main_depth(self):
+ self.assertEqual(GLib.main_depth(), 0)
+
+ def test_filenames(self):
+ self.assertEqual(GLib.filename_display_name('foo'), 'foo')
+ self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')
+
+ def test_uri_extract(self):
+ res = GLib.uri_list_extract_uris('''# some comment
+http://example.com
+https://my.org/q?x=1&y=2
+ http://gnome.org/new''')
+ self.assertEqual(res, ['http://example.com',
+ 'https://my.org/q?x=1&y=2',
+ 'http://gnome.org/new'])
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index a28a145..d67365f 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -15,6 +15,10 @@ class TestGObjectAPI(unittest.TestCase):
self.assertEqual(obj.__module__,
'gi._gobject._gobject')
+ def testCompatAPI(self):
+ # GObject formerly exposed a lot of GLib's functions
+ self.assertEqual(GObject.markup_escape_text('foo'), 'foo')
+
class TestReferenceCounting(unittest.TestCase):
def testRegularObject(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]