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