summaryrefslogtreecommitdiffstats
path: root/gio/gfile.override
blob: e0280f40394af46e38b360edaf8b4b0e369b6087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygobject - Python bindings for GObject
 * Copyright (C) 2008  Johan Dahlin
 *
 *   gfile.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_file_meta
static PyObject *
_wrap__install_file_meta(PyObject *self, PyObject *args)
{
    PyObject *metaclass;

    if (!PyArg_ParseTuple(args, "O", &metaclass))
	return NULL;

    Py_INCREF(metaclass);
    PyGFile_Type.ob_type = (PyTypeObject*)metaclass;

    Py_INCREF(Py_None);
    return Py_None;
}
%%
define _file_init kwargs
static PyObject*
_wrap__file_init(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    GFile *file;
    Py_ssize_t n_args, n_kwargs;
    char *arg;

    n_args = PyTuple_Size(args);
    n_kwargs = kwargs != NULL ? PyDict_Size(kwargs) : 0;

    if (n_args == 1 && n_kwargs == 0) {
	if (!PyArg_ParseTuple(args, "s:GFile", &arg))
	    return NULL;
	file = g_file_new_for_commandline_arg(arg);
    } else if (n_args == 0 && n_kwargs == 1) {
	if (PyDict_GetItemString(kwargs, "path")) {
	    char *kwlist[] = { "path", NULL };
	    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
					     "s:gio.File", kwlist, &arg))
		return NULL;
	    file = g_file_new_for_path(arg);
	} else if (PyDict_GetItemString(kwargs, "uri")) {
	    char *kwlist[] = { "uri", NULL };
	    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
					     "s:gio.File", kwlist, &arg))
		return NULL;
	    file = g_file_new_for_uri(arg);
	} else {	
	    PyErr_Format(PyExc_TypeError,
			 "gio.File() got an unexpected keyword argument '%s'",
			 "unknown");
	    return NULL;
	}
    } else {
	PyErr_Format(PyExc_TypeError,
		     "gio.File() takes exactly 1 argument (%d given)",
		     n_args + n_kwargs);
	return NULL;
    }

    if (!file) {
        PyErr_SetString(PyExc_RuntimeError,
			"could not create GFile object");
        return NULL;
    }
    return pygobject_new((GObject *)file);
}
%%
override g_file_read_async kwargs
static PyObject *
_wrap_g_file_read_async(PyGObject *self, PyObject *args, PyObject *kwargs)
{
  static char *kwlist[] = { "io_priority", "cancellable", "callback",
                            "user_data", NULL };
  int io_priority = G_PRIORITY_DEFAULT;
  PyGObject *pycancellable;
  GCancellable *cancellable;
  PyGAsyncRequestNotify *notify;
  
  notify = g_slice_new0(PyGAsyncRequestNotify);

  if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                   "iOO|O:InputStream.read_async",
                                   kwlist,
                                   &io_priority,
                                   &pycancellable,
                                   &notify->callback,
                                   &notify->data))
    {
      g_slice_free(PyGAsyncRequestNotify, notify);
      return NULL;
    }

  if ((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;
    }

  if (!PyCallable_Check(notify->callback))
    {
      PyErr_SetString(PyExc_TypeError, "callback argument not callable");
      g_slice_free(PyGAsyncRequestNotify, notify);
      return NULL;
    }
  Py_INCREF(notify->callback);
  Py_XINCREF(notify->data);
  
  g_file_read_async(G_FILE(self->obj),
                    io_priority,
                    cancellable,
                    (GAsyncReadyCallback)async_result_callback_marshal,
                    notify);
  
  Py_INCREF(Py_None);
  return Py_None;
}
/* GFile.append_to_async */
/* GFile.create_async */
/* GFile.enumerate_children_async */
/* GFile.eject_mountable */
/* GFile.find_enclosing_mount_async */
/* GFile.load_contents_async */
/* GFile.mount_enclosing_volume */
/* GFile.mount_mountable */
/* GFile.query_info_async */
/* GFile.replace_async */
/* GFile.replace_contents_async */
/* GFile.set_attributes_async */
/* GFile.set_display_name_async */
/* GFile.unmount_mountable */
/* GFile.load_partial_contents_async: No ArgType for GFileReadMoreCallback */
/* GFile.copy: No ArgType for GFileProgressCallback */
/* GFile.move: No ArgType for GFileProgressCallback */
/* GFile.query_settable_attributes: No ArgType for GFileAttributeInfoList* */
/* 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** */
/* GFile.replace_contents_finish: No ArgType for char** */