pygobject r768 - in trunk: . gio tests
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r768 - in trunk: . gio tests
- Date: Tue, 8 Apr 2008 16:12:22 +0100 (BST)
Author: johan
Date: Tue Apr 8 16:12:21 2008
New Revision: 768
URL: http://svn.gnome.org/viewvc/pygobject?rev=768&view=rev
Log:
2008-04-08 Johan Dahlin <jdahlin async com br>
* gio/gio.defs:
* gio/gio.override:
* tests/test_gio.py:
Add bindings for content_type_guess.
Based on patch by Thomas Leonard (#525113)
Modified:
trunk/ChangeLog
trunk/gio/gio.defs
trunk/gio/gio.override
trunk/tests/test_gio.py
Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs (original)
+++ trunk/gio/gio.defs Tue Apr 8 16:12:21 2008
@@ -544,6 +544,13 @@
)
(define-function content_type_guess
+ (docstring
+"content_type_guess(filename=None, data=None, want_uncertain=False) -> mime-type\n"
+"\n"
+"Guesses the content-type based on the parameters passed.\n"
+"Returns a string containing the mime type.\n"
+"If want_uncertain is set to True, return a tuple with the mime type and \n"
+"True/False if the type guess was uncertain or not.")
(c-name "g_content_type_guess")
(return-type "char*")
(parameters
Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override (original)
+++ trunk/gio/gio.override Tue Apr 8 16:12:21 2008
@@ -180,3 +180,33 @@
return ret;
}
+%%
+override g_content_type_guess kwargs
+static PyObject *
+_wrap_g_content_type_guess(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ char *kwlist[] = {"filename", "data", "want_uncertain", NULL};
+ char *filename = NULL, *data = NULL, *type;
+ int data_size = 0;
+ gboolean result_uncertain, want_uncertain = FALSE;
+
+ if (!PyArg_ParseTupleAndKeywords (args, kwargs,
+ "|zz#i:g_content_type_guess",
+ kwlist,
+ &filename, &data, &data_size,
+ &want_uncertain))
+ return NULL;
+
+ if (!filename && !data) {
+ PyErr_SetString(PyExc_TypeError, "need at least one argument");
+ return NULL;
+ }
+
+ type = g_content_type_guess(filename, (guchar *) data,
+ data_size, &result_uncertain);
+
+ if (want_uncertain)
+ return Py_BuildValue("zN", type,
+ PyBool_FromLong(result_uncertain));
+ return PyString_FromString(type);
+}
Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py (original)
+++ trunk/tests/test_gio.py Tue Apr 8 16:12:21 2008
@@ -212,3 +212,18 @@
self.assertEquals(self.icon.get_names(), ['open'])
self.icon.append_name('close')
self.assertEquals(self.icon.get_names(), ['open', 'close'])
+
+class TestType(unittest.TestCase):
+ def testGuessFromName(self):
+ mime_type = gio.content_type_guess('diagram.svg')
+ self.assertEquals('image/svg+xml', mime_type)
+
+ def testGuessFromContents(self):
+ mime_type = gio.content_type_guess(data='<html></html>')
+ self.assertEquals('text/html', mime_type)
+
+ def testGuessFromContentsUncertain(self):
+ mime_type, result_uncertain = gio.content_type_guess(
+ data='<html></html>', want_uncertain=True)
+ self.assertEquals('text/html', mime_type)
+ self.assertEquals(bool, type(result_uncertain))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]