[pygobject] [API change] Remove static filename_from_utf8() binding
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [API change] Remove static filename_from_utf8() binding
- Date: Sat, 3 Nov 2012 13:19:42 +0000 (UTC)
commit 3267808318b284814e52f2803b17af56fca648ad
Author: Martin Pitt <martinpitt gnome org>
Date: Sat Nov 3 14:17:25 2012 +0100
[API change] Remove static filename_from_utf8() binding
Replace static GLib.filename_from_utf8() with GI. The old static binding always
tried to convert the result to an Unicode object, which will fail if the result
is not UTF-8 encoded (which is the whole point of this function really!), so
return bytes now.
Although the static binding was rather useless before, this is technically an
API break.
docs/reference/pyglib-functions.xml | 32 --------------------------------
gi/_glib/__init__.py | 1 -
gi/_glib/glibmodule.c | 26 --------------------------
gi/_gobject/__init__.py | 1 -
gi/overrides/GLib.py | 8 ++++++++
gi/overrides/GObject.py | 3 ++-
tests/test_glib.py | 8 ++++++++
7 files changed, 18 insertions(+), 61 deletions(-)
---
diff --git a/docs/reference/pyglib-functions.xml b/docs/reference/pyglib-functions.xml
index 45e570f..a2e3a08 100644
--- a/docs/reference/pyglib-functions.xml
+++ b/docs/reference/pyglib-functions.xml
@@ -27,10 +27,6 @@ linkend="function-glib--spawn-async">glib.spawn_async</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-from-utf8">glib.filename_from_utf8</link></methodname>
- <methodparam><parameter>utf8string</parameter></methodparam>
</methodsynopsis></programlisting>
</refsect1>
@@ -292,34 +288,6 @@ raised.</para>
</refsect2>
- <refsect2 id="function-glib--filename-from-utf8">
- <title>glib.filename_from_utf8</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.filename_from_utf8</methodname>
- <methodparam><parameter>utf8string</parameter></methodparam>
- </methodsynopsis></programlisting>
- <variablelist role="params">
- <varlistentry>
- <term><emphasis>utf8string</emphasis> :</term>
- <listitem><simpara>a UTF-8 encoded string.</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis> :</term>
- <listitem><simpara>a filename encoded in the GLib filename
- encoding.</simpara></listitem>
- </varlistentry>
- </variablelist>
- <note>
- <para>This function is available in PyGTK 2.10 and above.</para>
- </note>
-
- <para>The <function>filename_from_utf8</function>() function converts
- a string from UTF-8 to the encoding GLib uses for filenames. Note that
- on Windows GLib uses UTF-8 for filenames.</para>
-
- </refsect2>
-
</refsect1>
</refentry>
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index 9faefb6..3c26a0d 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -45,6 +45,5 @@ OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
OPTION_REMAINING = _glib.OPTION_REMAINING
# Functions
-filename_from_utf8 = _glib.filename_from_utf8
spawn_async = _glib.spawn_async
threads_init = _glib.threads_init
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index 765fd5b..91c1ffb 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -51,30 +51,6 @@ pyglib_threads_init(PyObject *unused, PyObject *args, PyObject *kwargs)
return Py_None;
}
-static PyObject *
-pyglib_filename_from_utf8(PyObject *self, PyObject *args)
-{
- char *filename, *utf8string;
- Py_ssize_t utf8string_len;
- gsize bytes_written;
- GError *error = NULL;
- PyObject *py_filename;
-
- if (!PyArg_ParseTuple(args, "s#:glib.filename_from_utf8",
- &utf8string, &utf8string_len))
- return NULL;
-
- filename = g_filename_from_utf8(utf8string, utf8string_len,
- NULL, &bytes_written, &error);
- if (pyglib_error_check(&error)) {
- g_free(filename);
- return NULL;
- }
- py_filename = PYGLIB_PyUnicode_FromStringAndSize(filename, bytes_written);
- g_free(filename);
- return py_filename;
-}
-
static PyMethodDef _glib_functions[] = {
{ "threads_init",
(PyCFunction) pyglib_threads_init, METH_NOARGS,
@@ -90,8 +66,6 @@ static PyMethodDef _glib_functions[] = {
" standard_error=None) -> (pid, stdin, stdout, stderr)\n"
"Execute a child program asynchronously within a glib.MainLoop()\n"
"See the reference manual for a complete reference." },
- { "filename_from_utf8",
- (PyCFunction)pyglib_filename_from_utf8, METH_VARARGS },
{ NULL, NULL, 0 }
};
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 2493cff..1bd5e8f 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -82,7 +82,6 @@ type_parent = _gobject.type_parent
type_register = _gobject.type_register
spawn_async = _glib.spawn_async
-filename_from_utf8 = _glib.filename_from_utf8
Pid = _glib.Pid
GError = _glib.GError
OptionGroup = _glib.OptionGroup
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index cb4a26b..5527641 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -802,6 +802,14 @@ get_current_time = deprecated(get_current_time, 'GLib.get_real_time()')
__all__.append('get_current_time')
+# backwards compatible API with default argument, and ignoring bytes_read
+# output argument
+def filename_from_utf8(utf8string, len=-1):
+ return GLib.filename_from_utf8(utf8string, len)[0]
+
+__all__.append('filename_from_utf8')
+
+
# obsolete constants for backwards compatibility
glib_version = (GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION)
__all__.append('glib_version')
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 704aa01..49052dd 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -28,7 +28,8 @@ __all__ = []
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',
+ 'filename_display_name', 'filename_from_utf8',
+ 'uri_list_extract_uris',
'MainLoop', 'MainContext', 'main_context_default',
'source_remove', 'Source', 'Idle', 'Timeout', 'PollFD',
'idle_add', 'timeout_add', 'timeout_add_seconds',
diff --git a/tests/test_glib.py b/tests/test_glib.py
index 336cc8e..1a45fd8 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -54,6 +54,14 @@ class TestGLib(unittest.TestCase):
self.assertEqual(GLib.filename_display_name('foo'), 'foo')
self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')
+ # this is locale dependent, so we cannot completely verify the result
+ res = GLib.filename_from_utf8(_unicode('aÃb'))
+ self.assertTrue(isinstance(res, bytes))
+ self.assertGreaterEqual(len(res), 3)
+
+ # with explicit length argument
+ self.assertEqual(GLib.filename_from_utf8(_unicode('aÃb'), 1), b'a')
+
def test_uri_extract(self):
res = GLib.uri_list_extract_uris('''# some comment
http://example.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]