1 | /*[clinic input] |
2 | preserve |
3 | [clinic start generated code]*/ |
4 | |
5 | PyDoc_STRVAR(_io_StringIO_getvalue__doc__, |
6 | "getvalue($self, /)\n" |
7 | "--\n" |
8 | "\n" |
9 | "Retrieve the entire contents of the object." ); |
10 | |
11 | #define _IO_STRINGIO_GETVALUE_METHODDEF \ |
12 | {"getvalue", (PyCFunction)_io_StringIO_getvalue, METH_NOARGS, _io_StringIO_getvalue__doc__}, |
13 | |
14 | static PyObject * |
15 | _io_StringIO_getvalue_impl(stringio *self); |
16 | |
17 | static PyObject * |
18 | _io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored)) |
19 | { |
20 | return _io_StringIO_getvalue_impl(self); |
21 | } |
22 | |
23 | PyDoc_STRVAR(_io_StringIO_tell__doc__, |
24 | "tell($self, /)\n" |
25 | "--\n" |
26 | "\n" |
27 | "Tell the current file position." ); |
28 | |
29 | #define _IO_STRINGIO_TELL_METHODDEF \ |
30 | {"tell", (PyCFunction)_io_StringIO_tell, METH_NOARGS, _io_StringIO_tell__doc__}, |
31 | |
32 | static PyObject * |
33 | _io_StringIO_tell_impl(stringio *self); |
34 | |
35 | static PyObject * |
36 | _io_StringIO_tell(stringio *self, PyObject *Py_UNUSED(ignored)) |
37 | { |
38 | return _io_StringIO_tell_impl(self); |
39 | } |
40 | |
41 | PyDoc_STRVAR(_io_StringIO_read__doc__, |
42 | "read($self, size=-1, /)\n" |
43 | "--\n" |
44 | "\n" |
45 | "Read at most size characters, returned as a string.\n" |
46 | "\n" |
47 | "If the argument is negative or omitted, read until EOF\n" |
48 | "is reached. Return an empty string at EOF." ); |
49 | |
50 | #define _IO_STRINGIO_READ_METHODDEF \ |
51 | {"read", (PyCFunction)(void(*)(void))_io_StringIO_read, METH_FASTCALL, _io_StringIO_read__doc__}, |
52 | |
53 | static PyObject * |
54 | _io_StringIO_read_impl(stringio *self, Py_ssize_t size); |
55 | |
56 | static PyObject * |
57 | _io_StringIO_read(stringio *self, PyObject *const *args, Py_ssize_t nargs) |
58 | { |
59 | PyObject *return_value = NULL; |
60 | Py_ssize_t size = -1; |
61 | |
62 | if (!_PyArg_CheckPositional("read" , nargs, 0, 1)) { |
63 | goto exit; |
64 | } |
65 | if (nargs < 1) { |
66 | goto skip_optional; |
67 | } |
68 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
69 | goto exit; |
70 | } |
71 | skip_optional: |
72 | return_value = _io_StringIO_read_impl(self, size); |
73 | |
74 | exit: |
75 | return return_value; |
76 | } |
77 | |
78 | PyDoc_STRVAR(_io_StringIO_readline__doc__, |
79 | "readline($self, size=-1, /)\n" |
80 | "--\n" |
81 | "\n" |
82 | "Read until newline or EOF.\n" |
83 | "\n" |
84 | "Returns an empty string if EOF is hit immediately." ); |
85 | |
86 | #define _IO_STRINGIO_READLINE_METHODDEF \ |
87 | {"readline", (PyCFunction)(void(*)(void))_io_StringIO_readline, METH_FASTCALL, _io_StringIO_readline__doc__}, |
88 | |
89 | static PyObject * |
90 | _io_StringIO_readline_impl(stringio *self, Py_ssize_t size); |
91 | |
92 | static PyObject * |
93 | _io_StringIO_readline(stringio *self, PyObject *const *args, Py_ssize_t nargs) |
94 | { |
95 | PyObject *return_value = NULL; |
96 | Py_ssize_t size = -1; |
97 | |
98 | if (!_PyArg_CheckPositional("readline" , nargs, 0, 1)) { |
99 | goto exit; |
100 | } |
101 | if (nargs < 1) { |
102 | goto skip_optional; |
103 | } |
104 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
105 | goto exit; |
106 | } |
107 | skip_optional: |
108 | return_value = _io_StringIO_readline_impl(self, size); |
109 | |
110 | exit: |
111 | return return_value; |
112 | } |
113 | |
114 | PyDoc_STRVAR(_io_StringIO_truncate__doc__, |
115 | "truncate($self, pos=None, /)\n" |
116 | "--\n" |
117 | "\n" |
118 | "Truncate size to pos.\n" |
119 | "\n" |
120 | "The pos argument defaults to the current file position, as\n" |
121 | "returned by tell(). The current file position is unchanged.\n" |
122 | "Returns the new absolute position." ); |
123 | |
124 | #define _IO_STRINGIO_TRUNCATE_METHODDEF \ |
125 | {"truncate", (PyCFunction)(void(*)(void))_io_StringIO_truncate, METH_FASTCALL, _io_StringIO_truncate__doc__}, |
126 | |
127 | static PyObject * |
128 | _io_StringIO_truncate_impl(stringio *self, Py_ssize_t size); |
129 | |
130 | static PyObject * |
131 | _io_StringIO_truncate(stringio *self, PyObject *const *args, Py_ssize_t nargs) |
132 | { |
133 | PyObject *return_value = NULL; |
134 | Py_ssize_t size = self->pos; |
135 | |
136 | if (!_PyArg_CheckPositional("truncate" , nargs, 0, 1)) { |
137 | goto exit; |
138 | } |
139 | if (nargs < 1) { |
140 | goto skip_optional; |
141 | } |
142 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
143 | goto exit; |
144 | } |
145 | skip_optional: |
146 | return_value = _io_StringIO_truncate_impl(self, size); |
147 | |
148 | exit: |
149 | return return_value; |
150 | } |
151 | |
152 | PyDoc_STRVAR(_io_StringIO_seek__doc__, |
153 | "seek($self, pos, whence=0, /)\n" |
154 | "--\n" |
155 | "\n" |
156 | "Change stream position.\n" |
157 | "\n" |
158 | "Seek to character offset pos relative to position indicated by whence:\n" |
159 | " 0 Start of stream (the default). pos should be >= 0;\n" |
160 | " 1 Current position - pos must be 0;\n" |
161 | " 2 End of stream - pos must be 0.\n" |
162 | "Returns the new absolute position." ); |
163 | |
164 | #define _IO_STRINGIO_SEEK_METHODDEF \ |
165 | {"seek", (PyCFunction)(void(*)(void))_io_StringIO_seek, METH_FASTCALL, _io_StringIO_seek__doc__}, |
166 | |
167 | static PyObject * |
168 | _io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence); |
169 | |
170 | static PyObject * |
171 | _io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs) |
172 | { |
173 | PyObject *return_value = NULL; |
174 | Py_ssize_t pos; |
175 | int whence = 0; |
176 | |
177 | if (!_PyArg_CheckPositional("seek" , nargs, 1, 2)) { |
178 | goto exit; |
179 | } |
180 | { |
181 | Py_ssize_t ival = -1; |
182 | PyObject *iobj = _PyNumber_Index(args[0]); |
183 | if (iobj != NULL) { |
184 | ival = PyLong_AsSsize_t(iobj); |
185 | Py_DECREF(iobj); |
186 | } |
187 | if (ival == -1 && PyErr_Occurred()) { |
188 | goto exit; |
189 | } |
190 | pos = ival; |
191 | } |
192 | if (nargs < 2) { |
193 | goto skip_optional; |
194 | } |
195 | whence = _PyLong_AsInt(args[1]); |
196 | if (whence == -1 && PyErr_Occurred()) { |
197 | goto exit; |
198 | } |
199 | skip_optional: |
200 | return_value = _io_StringIO_seek_impl(self, pos, whence); |
201 | |
202 | exit: |
203 | return return_value; |
204 | } |
205 | |
206 | PyDoc_STRVAR(_io_StringIO_write__doc__, |
207 | "write($self, s, /)\n" |
208 | "--\n" |
209 | "\n" |
210 | "Write string to file.\n" |
211 | "\n" |
212 | "Returns the number of characters written, which is always equal to\n" |
213 | "the length of the string." ); |
214 | |
215 | #define _IO_STRINGIO_WRITE_METHODDEF \ |
216 | {"write", (PyCFunction)_io_StringIO_write, METH_O, _io_StringIO_write__doc__}, |
217 | |
218 | PyDoc_STRVAR(_io_StringIO_close__doc__, |
219 | "close($self, /)\n" |
220 | "--\n" |
221 | "\n" |
222 | "Close the IO object.\n" |
223 | "\n" |
224 | "Attempting any further operation after the object is closed\n" |
225 | "will raise a ValueError.\n" |
226 | "\n" |
227 | "This method has no effect if the file is already closed." ); |
228 | |
229 | #define _IO_STRINGIO_CLOSE_METHODDEF \ |
230 | {"close", (PyCFunction)_io_StringIO_close, METH_NOARGS, _io_StringIO_close__doc__}, |
231 | |
232 | static PyObject * |
233 | _io_StringIO_close_impl(stringio *self); |
234 | |
235 | static PyObject * |
236 | _io_StringIO_close(stringio *self, PyObject *Py_UNUSED(ignored)) |
237 | { |
238 | return _io_StringIO_close_impl(self); |
239 | } |
240 | |
241 | PyDoc_STRVAR(_io_StringIO___init____doc__, |
242 | "StringIO(initial_value=\'\', newline=\'\\n\')\n" |
243 | "--\n" |
244 | "\n" |
245 | "Text I/O implementation using an in-memory buffer.\n" |
246 | "\n" |
247 | "The initial_value argument sets the value of object. The newline\n" |
248 | "argument is like the one of TextIOWrapper\'s constructor." ); |
249 | |
250 | static int |
251 | _io_StringIO___init___impl(stringio *self, PyObject *value, |
252 | PyObject *newline_obj); |
253 | |
254 | static int |
255 | _io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
256 | { |
257 | int return_value = -1; |
258 | static const char * const _keywords[] = {"initial_value" , "newline" , NULL}; |
259 | static _PyArg_Parser _parser = {NULL, _keywords, "StringIO" , 0}; |
260 | PyObject *argsbuf[2]; |
261 | PyObject * const *fastargs; |
262 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
263 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
264 | PyObject *value = NULL; |
265 | PyObject *newline_obj = NULL; |
266 | |
267 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); |
268 | if (!fastargs) { |
269 | goto exit; |
270 | } |
271 | if (!noptargs) { |
272 | goto skip_optional_pos; |
273 | } |
274 | if (fastargs[0]) { |
275 | value = fastargs[0]; |
276 | if (!--noptargs) { |
277 | goto skip_optional_pos; |
278 | } |
279 | } |
280 | newline_obj = fastargs[1]; |
281 | skip_optional_pos: |
282 | return_value = _io_StringIO___init___impl((stringio *)self, value, newline_obj); |
283 | |
284 | exit: |
285 | return return_value; |
286 | } |
287 | |
288 | PyDoc_STRVAR(_io_StringIO_readable__doc__, |
289 | "readable($self, /)\n" |
290 | "--\n" |
291 | "\n" |
292 | "Returns True if the IO object can be read." ); |
293 | |
294 | #define _IO_STRINGIO_READABLE_METHODDEF \ |
295 | {"readable", (PyCFunction)_io_StringIO_readable, METH_NOARGS, _io_StringIO_readable__doc__}, |
296 | |
297 | static PyObject * |
298 | _io_StringIO_readable_impl(stringio *self); |
299 | |
300 | static PyObject * |
301 | _io_StringIO_readable(stringio *self, PyObject *Py_UNUSED(ignored)) |
302 | { |
303 | return _io_StringIO_readable_impl(self); |
304 | } |
305 | |
306 | PyDoc_STRVAR(_io_StringIO_writable__doc__, |
307 | "writable($self, /)\n" |
308 | "--\n" |
309 | "\n" |
310 | "Returns True if the IO object can be written." ); |
311 | |
312 | #define _IO_STRINGIO_WRITABLE_METHODDEF \ |
313 | {"writable", (PyCFunction)_io_StringIO_writable, METH_NOARGS, _io_StringIO_writable__doc__}, |
314 | |
315 | static PyObject * |
316 | _io_StringIO_writable_impl(stringio *self); |
317 | |
318 | static PyObject * |
319 | _io_StringIO_writable(stringio *self, PyObject *Py_UNUSED(ignored)) |
320 | { |
321 | return _io_StringIO_writable_impl(self); |
322 | } |
323 | |
324 | PyDoc_STRVAR(_io_StringIO_seekable__doc__, |
325 | "seekable($self, /)\n" |
326 | "--\n" |
327 | "\n" |
328 | "Returns True if the IO object can be seeked." ); |
329 | |
330 | #define _IO_STRINGIO_SEEKABLE_METHODDEF \ |
331 | {"seekable", (PyCFunction)_io_StringIO_seekable, METH_NOARGS, _io_StringIO_seekable__doc__}, |
332 | |
333 | static PyObject * |
334 | _io_StringIO_seekable_impl(stringio *self); |
335 | |
336 | static PyObject * |
337 | _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored)) |
338 | { |
339 | return _io_StringIO_seekable_impl(self); |
340 | } |
341 | /*[clinic end generated code: output=eea93dcab10d0a97 input=a9049054013a1b77]*/ |
342 | |