summaryrefslogtreecommitdiffstats
path: root/gio
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2008-04-08 15:12:21 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-04-08 15:12:21 +0000
commitdb07def4e878b7237a61d4ac73a861d7422a5578 (patch)
tree8df21656100f9b11bb9ab4d9c2a681cf6da8fd18 /gio
parent24d6e7c51d6a43a31838065ea7bb7d664f53e4d4 (diff)
downloadpygobject-db07def4e878b7237a61d4ac73a861d7422a5578.tar.gz
pygobject-db07def4e878b7237a61d4ac73a861d7422a5578.tar.xz
pygobject-db07def4e878b7237a61d4ac73a861d7422a5578.zip
Add bindings for content_type_guess. Based on patch by Thomas Leonard
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) svn path=/trunk/; revision=768
Diffstat (limited to 'gio')
-rw-r--r--gio/gio.defs7
-rw-r--r--gio/gio.override30
2 files changed, 37 insertions, 0 deletions
diff --git a/gio/gio.defs b/gio/gio.defs
index 4f293ac..dfe70ec 100644
--- a/gio/gio.defs
+++ b/gio/gio.defs
@@ -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
diff --git a/gio/gio.override b/gio/gio.override
index 33b8611..e34e5f9 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -180,3 +180,33 @@ _wrap_g_themed_icon_get_names(PyGObject *self)
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);
+}