diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | gio/Makefile.am | 1 | ||||
-rw-r--r-- | gio/__init__.py | 11 | ||||
-rw-r--r-- | gio/gappinfo.override | 70 | ||||
-rw-r--r-- | gio/gio.defs | 8 | ||||
-rw-r--r-- | gio/gio.override | 1 | ||||
-rw-r--r-- | tests/test_gio.py | 26 |
7 files changed, 114 insertions, 13 deletions
@@ -1,6 +1,16 @@ 2008-04-08 Johan Dahlin <jdahlin@async.com.br> * gio/Makefile.am: + * gio/__init__.py: + * gio/gappinfo.override: + * gio/gio.defs: + * gio/gio.override: + * tests/test_gio.py: + Implement GAppInfo constructor, add tests. + +2008-04-08 Johan Dahlin <jdahlin@async.com.br> + + * gio/Makefile.am: * gio/gfileinfo.override: * gio/gio.defs: * gio/gio.override: diff --git a/gio/Makefile.am b/gio/Makefile.am index d67269b8..348d9c08 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -34,6 +34,7 @@ EXTRA_DIST = # gio module GIO_OVERRIDES = \ + gappinfo.override \ gio.override \ gfile.override \ gfileenumerator.override \ diff --git a/gio/__init__.py b/gio/__init__.py index 57351615..38873f23 100644 --- a/gio/__init__.py +++ b/gio/__init__.py @@ -1,4 +1,4 @@ -# -*- Mode: Python; py-indent-offset: 4 -*- +# -*- Mode: Python -*- # pygobject - Python bindings for the GObject library # Copyright (C) 2008 Johan Dahlin # @@ -29,7 +29,9 @@ except ImportError: from gobject import GObjectMeta from _gio import * -from _gio import _file_init, _install_file_meta +from _gio import \ + _app_info_init, _install_app_info_meta, \ + _file_init, _install_file_meta try: import unix unix # pyflakes @@ -39,5 +41,8 @@ del _gio class GFileMeta(GObjectMeta): __call__ = _file_init - _install_file_meta(GFileMeta) + +class GAppInfoMeta(GObjectMeta): + __call__ = _app_info_init +_install_app_info_meta(GAppInfoMeta) diff --git a/gio/gappinfo.override b/gio/gappinfo.override new file mode 100644 index 00000000..d41b9779 --- /dev/null +++ b/gio/gappinfo.override @@ -0,0 +1,70 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2008 Johan Dahlin + * + * gappinfo.override: module overrides for GInputStream + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +define _install_app_info_meta +static PyObject * +_wrap__install_app_info_meta(PyObject *self, PyObject *args) +{ + PyObject *metaclass; + + if (!PyArg_ParseTuple(args, "O", &metaclass)) + return NULL; + + Py_INCREF(metaclass); + PyGAppInfo_Type.ob_type = (PyTypeObject*)metaclass; + + Py_INCREF(Py_None); + return Py_None; +} +%% +define _app_info_init kwargs +static PyObject * +_wrap__app_info_init(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "commandline", "application_name", + "flags", NULL }; + char *commandline, *application_name = NULL; + PyObject *py_flags = NULL; + GAppInfo *ret; + GError *error = NULL; + GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "s|zO:gio.AppInfo", + kwlist, + &commandline, &application_name, + &py_flags)) + return NULL; + if (py_flags && pyg_flags_get_value(G_TYPE_APP_INFO_CREATE_FLAGS, + py_flags, (gpointer)&flags)) + return NULL; + + ret = g_app_info_create_from_commandline(commandline, + application_name, flags, &error); + + if (pyg_error_check(&error)) + return NULL; + + /* pygobject_new handles NULL checking */ + return pygobject_new((GObject *)ret); +} + diff --git a/gio/gio.defs b/gio/gio.defs index 32746a03..0dcc024f 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -15,11 +15,12 @@ (define-function app_info_create_from_commandline (c-name "g_app_info_create_from_commandline") + (is-constructor-of "GAppInfo") (return-type "GAppInfo*") (parameters '("const-char*" "commandline") - '("const-char*" "application_name") - '("GAppInfoCreateFlags" "flags") + '("const-char*" "application_name" (null-ok) (default "NULL")) + '("GAppInfoCreateFlags" "flags" (default "G_APP_INFO_CREATE_NONE")) '("GError**" "error") ) ) @@ -1095,6 +1096,7 @@ (define-function file_new_for_path (c-name "g_file_new_for_path") + (is-constructor-of "GFile") (return-type "GFile*") (parameters '("const-char*" "path") @@ -1103,6 +1105,7 @@ (define-function file_new_for_uri (c-name "g_file_new_for_uri") + (is-constructor-of "GFile") (return-type "GFile*") (parameters '("const-char*" "uri") @@ -1110,6 +1113,7 @@ ) (define-function file_new_for_commandline_arg + (is-constructor-of "GFile") (c-name "g_file_new_for_commandline_arg") (return-type "GFile*") (parameters diff --git a/gio/gio.override b/gio/gio.override index 41f60138..6624ad02 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -78,6 +78,7 @@ async_result_callback_marshal(GObject *source_object, } %% include + gappinfo.override gfile.override gfileenumerator.override gfileinfo.override diff --git a/tests/test_gio.py b/tests/test_gio.py index a01e2701..e06cbb02 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -9,7 +9,7 @@ from common import gio, gobject class TestFile(unittest.TestCase): def setUp(self): self._f = open("file.txt", "w+") - self.file = gio.file_new_for_path("file.txt") + self.file = gio.File("file.txt") def tearDown(self): self._f.close() @@ -54,7 +54,7 @@ class TestFile(unittest.TestCase): class TestGFileEnumerator(unittest.TestCase): def setUp(self): - self.file = gio.file_new_for_path(".") + self.file = gio.File(".") def testEnumerateChildren(self): enumerator = self.file.enumerate_children( @@ -186,6 +186,7 @@ class TestOutputStream(unittest.TestCase): loop = gobject.MainLoop() loop.run() + class TestVolumeMonitor(unittest.TestCase): def setUp(self): self.monitor = gio.volume_monitor_get() @@ -215,16 +216,17 @@ class TestThemedIcon(unittest.TestCase): self.icon.append_name('close') self.assertEquals(self.icon.get_names(), ['open', 'close']) -class TestType(unittest.TestCase): - def testGuessFromName(self): + +class TestContentTypeGuess(unittest.TestCase): + def testFromName(self): mime_type = gio.content_type_guess('diagram.svg') self.assertEquals('image/svg+xml', mime_type) - def testGuessFromContents(self): + def testFromContents(self): mime_type = gio.content_type_guess(data='<html></html>') self.assertEquals('text/html', mime_type) - def testGuessFromContentsUncertain(self): + def testFromContentsUncertain(self): mime_type, result_uncertain = gio.content_type_guess( data='<html></html>', want_uncertain=True) self.assertEquals('text/html', mime_type) @@ -233,8 +235,16 @@ class TestType(unittest.TestCase): class TestFileInfo(unittest.TestCase): def testListAttributes(self): - gfile = gio.File("test_gio.py") - fileinfo = gfile.query_info("*") + fileinfo = gio.File("test_gio.py").query_info("*") attributes = fileinfo.list_attributes("standard") self.failUnless(attributes) self.failUnless('standard::name' in attributes) + + +class TestAppInfo(unittest.TestCase): + def setUp(self): + self.appinfo = gio.AppInfo("does-not-exist") + + def testSimple(self): + self.assertEquals(self.appinfo.get_description(), + "Custom definition for (null)") |