Commit 32678083 authored by Martin Pitt's avatar Martin Pitt
Browse files

[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.
parent 8d52bceb
......@@ -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>&nbsp;:</term>
<listitem><simpara>a UTF-8 encoded string.</simpara></listitem>
</varlistentry>
<varlistentry>
<term><emphasis>Returns</emphasis>&nbsp;:</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>
......@@ -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
......@@ -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 }
};
......
......@@ -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
......
......@@ -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')
......
......@@ -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',
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment