pygobject r793 - in trunk: . gio tests
- From: gianmt svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r793 - in trunk: . gio tests
- Date: Fri, 11 Jul 2008 19:18:29 +0000 (UTC)
Author: gianmt
Date: Fri Jul 11 19:18:28 2008
New Revision: 793
URL: http://svn.gnome.org/viewvc/pygobject?rev=793&view=rev
Log:
wrap File.load_contents with docstrings
Modified:
trunk/ChangeLog
trunk/gio/gfile.override
trunk/gio/gio.defs
trunk/tests/test_gio.py
Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override (original)
+++ trunk/gio/gfile.override Fri Jul 11 19:18:28 2008
@@ -101,7 +101,7 @@
notify = g_slice_new0(PyGAsyncRequestNotify);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O|iOO:InputStream.read_async",
+ "O|iOO:File.read_async",
kwlist,
¬ify->callback,
&io_priority,
@@ -142,6 +142,50 @@
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_file_load_contents kwargs
+static PyObject *
+_wrap_g_file_load_contents(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "cancellable", NULL };
+ GCancellable *cancellable;
+ PyGObject *pycancellable = NULL;
+ gchar *contents, *etag_out;
+ gsize lenght;
+ GError *error = NULL;
+ gboolean ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|O:File.load_contents",
+ kwlist,
+ &pycancellable))
+ return NULL;
+
+ if (pycancellable == NULL || (PyObject*)pycancellable == Py_None)
+ cancellable = NULL;
+ else if (pygobject_check(pycancellable, &PyGCancellable_Type))
+ cancellable = G_CANCELLABLE(pycancellable->obj);
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "cancellable should be a gio.Cancellable");
+ return NULL;
+ }
+
+ ret = g_file_load_contents(G_FILE(self->obj), cancellable,
+ &contents, &lenght, &etag_out, &error);
+
+ if (pyg_error_check(&error))
+ return NULL;
+
+ if (ret)
+ return Py_BuildValue("(sks)", contents, lenght, etag_out);
+ else {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+}
/* GFile.append_to_async */
/* GFile.create_async */
/* GFile.enumerate_children_async */
@@ -163,7 +207,6 @@
/* GFile.query_writable_namespaces: No ArgType for GFileAttributeInfoList* */
/* GFile.set_attribute: No ArgType for gpointer */
/* GFile.set_attributes_finish: No ArgType for GFileInfo** */
-/* GFile.load_contents: No ArgType for char** */
/* GFile.load_contents_finish: No ArgType for char** */
/* GFile.load_partial_contents_finish: No ArgType for char** */
/* GFile.replace_contents: No ArgType for char** */
Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs (original)
+++ trunk/gio/gio.defs Fri Jul 11 19:18:28 2008
@@ -1253,17 +1253,18 @@
(define-method read
(of-object "GFile")
(docstring
-"F.read([cancellable]) -> input stream\n"
-"Opens a file for reading. The result is a GFileInputStream that can be \n"
-"used to read the contents of the file.\n"
-"\n"
-"If cancellable is specified, then the operation can be cancelled by \n"
-"triggering the cancellable object from another thread. If the operation \n"
-"was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n"
-"If the file does not exist, the gio.IO_ERROR_NOT_FOUND error will \n"
-"be returned. If the file is a directory, the gio.IO_ERROR_IS_DIRECTORY \n"
-"error will be returned. Other errors are possible too, and depend on what \n"
-"kind of filesystem the file is on.")
+ "F.read([cancellable]) -> input stream\n"
+ "Opens a file for reading. The result is a GFileInputStream that\n"
+ "can be used to read the contents of the file.\n"
+ "\n"
+ "If cancellable is specified, then the operation can be cancelled\n"
+ "by triggering the cancellable object from another thread. If the\n"
+ "operation was cancelled, the error gio.IO_ERROR_CANCELLED will\n"
+ "be returned. If the file does not exist, the gio.IO_ERROR_NOT_FOUND\n"
+ "error will be returned. If the file is a directory, the\n"
+ "gio.IO_ERROR_IS_DIRECTORY error will be returned. Other errors\n"
+ "are possible too, and depend on what kind of filesystem the file is on."
+ )
(c-name "g_file_read")
(return-type "GFileInputStream*")
(parameters
@@ -1275,12 +1276,14 @@
(define-method read_async
(of-object "GFile")
(docstring
-"F.read_async(callback [,io_priority [,cancellable [,user_data]]]) -> start read\n"
-"\n"
-"For more details, see gio.File.read() which is the synchronous version of this call.\n"
-"Asynchronously opens file for reading."
-"When the operation is finished, callback will be called.\n"
-"You can then call g_file_read_finish() to get the result of the operation.\n")
+ "F.read_async(callback [,io_priority [,cancellable [,user_data]]]) -> start read\n"
+ "\n"
+ "For more details, see gio.File.read() which is the synchronous\n"
+ "version of this call. Asynchronously opens file for reading.\n"
+ "When the operation is finished, callback will be called.\n"
+ "You can then call g_file_read_finish() to get the result of the\n"
+ "operation.\n"
+ )
(c-name "g_file_read_async")
(return-type "none")
(parameters
@@ -1906,6 +1909,15 @@
)
(define-method load_contents
+ (docstring
+ "F.load_contents([cancellable]) -> contents, length, etag_out\n\n"
+ "Loads the content of the file into memory, returning the size of the\n"
+ "data. The data is always zero terminated, but this is not included\n"
+ "in the resultant length.\n"
+ "If cancellable is not None, then the operation can be cancelled by\n"
+ "triggering the cancellable object from another thread. If the operation\n"
+ "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n"
+ )
(of-object "GFile")
(c-name "g_file_load_contents")
(return-type "gboolean")
Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py (original)
+++ trunk/tests/test_gio.py Fri Jul 11 19:18:28 2008
@@ -61,6 +61,15 @@
self.assertRaises(TypeError, gio.File, foo="bar")
self.assertRaises(TypeError, gio.File, uri=1)
self.assertRaises(TypeError, gio.File, path=1)
+
+ def testLoadContents(self):
+ self._f.write("testing load_contents")
+ self._f.seek(0)
+ c = gio.Cancellable()
+ cont, leng, etag = self.file.load_contents(cancellable=c)
+ self.assertEqual(cont, "testing load_contents")
+ self.assertEqual(leng, 21)
+ self.assertNotEqual(etag, '')
class TestGFileEnumerator(unittest.TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]