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 *
blob_close(pysqlite_Blob * self,PyObject * Py_UNUSED (ignored))20 blob_close(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
21 {
22 return blob_close_impl(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 be returned.\n"
35 "When length is not specified, or is negative, Blob.read() will read until the\n"
36 "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 *
blob_read(pysqlite_Blob * self,PyObject * const * args,Py_ssize_t nargs)45 blob_read(pysqlite_Blob *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(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 of the\n"
74 "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 *
blob_write(pysqlite_Blob * self,PyObject * arg)83 blob_write(pysqlite_Blob *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(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 positioning).\n"
109 "Other values for origin are os.SEEK_CUR (seek relative to the current position)\n"
110 "and os.SEEK_END (seek relative to the blob\'s end).");
111
112 #define BLOB_SEEK_METHODDEF \
113 {"seek", _PyCFunction_CAST(blob_seek), METH_FASTCALL, blob_seek__doc__},
114
115 static PyObject *
116 blob_seek_impl(pysqlite_Blob *self, int offset, int origin);
117
118 static PyObject *
blob_seek(pysqlite_Blob * self,PyObject * const * args,Py_ssize_t nargs)119 blob_seek(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
120 {
121 PyObject *return_value = NULL;
122 int offset;
123 int origin = 0;
124
125 if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
126 goto exit;
127 }
128 offset = PyLong_AsInt(args[0]);
129 if (offset == -1 && PyErr_Occurred()) {
130 goto exit;
131 }
132 if (nargs < 2) {
133 goto skip_optional;
134 }
135 origin = PyLong_AsInt(args[1]);
136 if (origin == -1 && PyErr_Occurred()) {
137 goto exit;
138 }
139 skip_optional:
140 return_value = blob_seek_impl(self, offset, origin);
141
142 exit:
143 return return_value;
144 }
145
146 PyDoc_STRVAR(blob_tell__doc__,
147 "tell($self, /)\n"
148 "--\n"
149 "\n"
150 "Return the current access position for the blob.");
151
152 #define BLOB_TELL_METHODDEF \
153 {"tell", (PyCFunction)blob_tell, METH_NOARGS, blob_tell__doc__},
154
155 static PyObject *
156 blob_tell_impl(pysqlite_Blob *self);
157
158 static PyObject *
blob_tell(pysqlite_Blob * self,PyObject * Py_UNUSED (ignored))159 blob_tell(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
160 {
161 return blob_tell_impl(self);
162 }
163
164 PyDoc_STRVAR(blob_enter__doc__,
165 "__enter__($self, /)\n"
166 "--\n"
167 "\n"
168 "Blob context manager enter.");
169
170 #define BLOB_ENTER_METHODDEF \
171 {"__enter__", (PyCFunction)blob_enter, METH_NOARGS, blob_enter__doc__},
172
173 static PyObject *
174 blob_enter_impl(pysqlite_Blob *self);
175
176 static PyObject *
blob_enter(pysqlite_Blob * self,PyObject * Py_UNUSED (ignored))177 blob_enter(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
178 {
179 return blob_enter_impl(self);
180 }
181
182 PyDoc_STRVAR(blob_exit__doc__,
183 "__exit__($self, type, val, tb, /)\n"
184 "--\n"
185 "\n"
186 "Blob context manager exit.");
187
188 #define BLOB_EXIT_METHODDEF \
189 {"__exit__", _PyCFunction_CAST(blob_exit), METH_FASTCALL, blob_exit__doc__},
190
191 static PyObject *
192 blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
193 PyObject *tb);
194
195 static PyObject *
blob_exit(pysqlite_Blob * self,PyObject * const * args,Py_ssize_t nargs)196 blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
197 {
198 PyObject *return_value = NULL;
199 PyObject *type;
200 PyObject *val;
201 PyObject *tb;
202
203 if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
204 goto exit;
205 }
206 type = args[0];
207 val = args[1];
208 tb = args[2];
209 return_value = blob_exit_impl(self, type, val, tb);
210
211 exit:
212 return return_value;
213 }
214 /*[clinic end generated code: output=31abd55660e0c5af input=a9049054013a1b77]*/
215