Debian Codegraph @

Modules/_sqlite/clinic/blob.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
6
7 PyDoc_STRVAR(blob_close__doc__,
8 "close($self, /)\n"
9 "--\n"
10 "\n"
11 "Close the blob.");
12
13 #define BLOB_CLOSE_METHODDEF \
14 {"close", (PyCFunction)blob_close, METH_NOARGS, blob_close__doc__},
15
16 static PyObject *
17 blob_close_impl(pysqlite_Blob *self);
18
19 static PyObject *
20 blob_close(PyObject *self, PyObject *Py_UNUSED(ignored))
21 {
22 return blob_close_impl((pysqlite_Blob *)self);
23 }
24
25 PyDoc_STRVAR(blob_read__doc__,
26 "read($self, length=-1, /)\n"
27 "--\n"
28 "\n"
29 "Read data at the current offset position.\n"
30 "\n"
31 " length\n"
32 " Read length in bytes.\n"
33 "\n"
34 "If the end of the blob is reached, the data up to end of file will\n"
35 "be returned. When length is not specified, or is negative,\n"
36 "Blob.read() will read until the end of the blob.");
37
38 #define BLOB_READ_METHODDEF \
39 {"read", _PyCFunction_CAST(blob_read), METH_FASTCALL, blob_read__doc__},
40
41 static PyObject *
42 blob_read_impl(pysqlite_Blob *self, int length);
43
44 static PyObject *
45 blob_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
46 {
47 PyObject *return_value = NULL;
48 int length = -1;
49
50 if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
51 goto exit;
52 }
53 if (nargs < 1) {
54 goto skip_optional;
55 }
56 length = PyLong_AsInt(args[0]);
57 if (length == -1 && PyErr_Occurred()) {
58 goto exit;
59 }
60 skip_optional:
61 return_value = blob_read_impl((pysqlite_Blob *)self, length);
62
63 exit:
64 return return_value;
65 }
66
67 PyDoc_STRVAR(blob_write__doc__,
68 "write($self, data, /)\n"
69 "--\n"
70 "\n"
71 "Write data at the current offset.\n"
72 "\n"
73 "This function cannot change the blob length. Writing beyond the end\n"
74 "of the blob will result in an exception being raised.");
75
76 #define BLOB_WRITE_METHODDEF \
77 {"write", (PyCFunction)blob_write, METH_O, blob_write__doc__},
78
79 static PyObject *
80 blob_write_impl(pysqlite_Blob *self, Py_buffer *data);
81
82 static PyObject *
83 blob_write(PyObject *self, PyObject *arg)
84 {
85 PyObject *return_value = NULL;
86 Py_buffer data = {NULL, NULL};
87
88 if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
89 goto exit;
90 }
91 return_value = blob_write_impl((pysqlite_Blob *)self, &data);
92
93 exit:
94 /* Cleanup for data */
95 if (data.obj) {
96 PyBuffer_Release(&data);
97 }
98
99 return return_value;
100 }
101
102 PyDoc_STRVAR(blob_seek__doc__,
103 "seek($self, offset, origin=0, /)\n"
104 "--\n"
105 "\n"
106 "Set the current access position to offset.\n"
107 "\n"
108 "The origin argument defaults to os.SEEK_SET (absolute blob\n"
109 "positioning). Other values for origin are os.SEEK_CUR (seek\n"
110 "relative to the current position) and os.SEEK_END (seek relative to\n"
111 "the blob\'s end).");
112
113 #define BLOB_SEEK_METHODDEF \
114 {"seek", _PyCFunction_CAST(blob_seek), METH_FASTCALL, blob_seek__doc__},
115
116 static PyObject *
117 blob_seek_impl(pysqlite_Blob *self, int offset, int origin);
118
119 static PyObject *
120 blob_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
121 {
122 PyObject *return_value = NULL;
123 int offset;
124 int origin = 0;
125
126 if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
127 goto exit;
128 }
129 offset = PyLong_AsInt(args[0]);
130 if (offset == -1 && PyErr_Occurred()) {
131 goto exit;
132 }
133 if (nargs < 2) {
134 goto skip_optional;
135 }
136 origin = PyLong_AsInt(args[1]);
137 if (origin == -1 && PyErr_Occurred()) {
138 goto exit;
139 }
140 skip_optional:
141 return_value = blob_seek_impl((pysqlite_Blob *)self, offset, origin);
142
143 exit:
144 return return_value;
145 }
146
147 PyDoc_STRVAR(blob_tell__doc__,
148 "tell($self, /)\n"
149 "--\n"
150 "\n"
151 "Return the current access position for the blob.");
152
153 #define BLOB_TELL_METHODDEF \
154 {"tell", (PyCFunction)blob_tell, METH_NOARGS, blob_tell__doc__},
155
156 static PyObject *
157 blob_tell_impl(pysqlite_Blob *self);
158
159 static PyObject *
160 blob_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
161 {
162 return blob_tell_impl((pysqlite_Blob *)self);
163 }
164
165 PyDoc_STRVAR(blob_enter__doc__,
166 "__enter__($self, /)\n"
167 "--\n"
168 "\n"
169 "Blob context manager enter.");
170
171 #define BLOB_ENTER_METHODDEF \
172 {"__enter__", (PyCFunction)blob_enter, METH_NOARGS, blob_enter__doc__},
173
174 static PyObject *
175 blob_enter_impl(pysqlite_Blob *self);
176
177 static PyObject *
178 blob_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
179 {
180 return blob_enter_impl((pysqlite_Blob *)self);
181 }
182
183 PyDoc_STRVAR(blob_exit__doc__,
184 "__exit__($self, type, val, tb, /)\n"
185 "--\n"
186 "\n"
187 "Blob context manager exit.");
188
189 #define BLOB_EXIT_METHODDEF \
190 {"__exit__", _PyCFunction_CAST(blob_exit), METH_FASTCALL, blob_exit__doc__},
191
192 static PyObject *
193 blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
194 PyObject *tb);
195
196 static PyObject *
197 blob_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
198 {
199 PyObject *return_value = NULL;
200 PyObject *type;
201 PyObject *val;
202 PyObject *tb;
203
204 if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
205 goto exit;
206 }
207 type = args[0];
208 val = args[1];
209 tb = args[2];
210 return_value = blob_exit_impl((pysqlite_Blob *)self, type, val, tb);
211
212 exit:
213 return return_value;
214 }
215 /*[clinic end generated code: output=b0e3d38063739b17 input=a9049054013a1b77]*/