• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
_io_StringIO_getvalue(stringio * self,PyObject * Py_UNUSED (ignored))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 *
_io_StringIO_tell(stringio * self,PyObject * Py_UNUSED (ignored))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 *
_io_StringIO_read(stringio * self,PyObject * const * args,Py_ssize_t nargs)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 *
_io_StringIO_readline(stringio * self,PyObject * const * args,Py_ssize_t nargs)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 *
_io_StringIO_truncate(stringio * self,PyObject * const * args,Py_ssize_t nargs)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 *
_io_StringIO_seek(stringio * self,PyObject * const * args,Py_ssize_t nargs)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     if (PyFloat_Check(args[0])) {
181         PyErr_SetString(PyExc_TypeError,
182                         "integer argument expected, got float" );
183         goto exit;
184     }
185     {
186         Py_ssize_t ival = -1;
187         PyObject *iobj = PyNumber_Index(args[0]);
188         if (iobj != NULL) {
189             ival = PyLong_AsSsize_t(iobj);
190             Py_DECREF(iobj);
191         }
192         if (ival == -1 && PyErr_Occurred()) {
193             goto exit;
194         }
195         pos = ival;
196     }
197     if (nargs < 2) {
198         goto skip_optional;
199     }
200     if (PyFloat_Check(args[1])) {
201         PyErr_SetString(PyExc_TypeError,
202                         "integer argument expected, got float" );
203         goto exit;
204     }
205     whence = _PyLong_AsInt(args[1]);
206     if (whence == -1 && PyErr_Occurred()) {
207         goto exit;
208     }
209 skip_optional:
210     return_value = _io_StringIO_seek_impl(self, pos, whence);
211 
212 exit:
213     return return_value;
214 }
215 
216 PyDoc_STRVAR(_io_StringIO_write__doc__,
217 "write($self, s, /)\n"
218 "--\n"
219 "\n"
220 "Write string to file.\n"
221 "\n"
222 "Returns the number of characters written, which is always equal to\n"
223 "the length of the string.");
224 
225 #define _IO_STRINGIO_WRITE_METHODDEF    \
226     {"write", (PyCFunction)_io_StringIO_write, METH_O, _io_StringIO_write__doc__},
227 
228 PyDoc_STRVAR(_io_StringIO_close__doc__,
229 "close($self, /)\n"
230 "--\n"
231 "\n"
232 "Close the IO object.\n"
233 "\n"
234 "Attempting any further operation after the object is closed\n"
235 "will raise a ValueError.\n"
236 "\n"
237 "This method has no effect if the file is already closed.");
238 
239 #define _IO_STRINGIO_CLOSE_METHODDEF    \
240     {"close", (PyCFunction)_io_StringIO_close, METH_NOARGS, _io_StringIO_close__doc__},
241 
242 static PyObject *
243 _io_StringIO_close_impl(stringio *self);
244 
245 static PyObject *
_io_StringIO_close(stringio * self,PyObject * Py_UNUSED (ignored))246 _io_StringIO_close(stringio *self, PyObject *Py_UNUSED(ignored))
247 {
248     return _io_StringIO_close_impl(self);
249 }
250 
251 PyDoc_STRVAR(_io_StringIO___init____doc__,
252 "StringIO(initial_value=\'\', newline=\'\\n\')\n"
253 "--\n"
254 "\n"
255 "Text I/O implementation using an in-memory buffer.\n"
256 "\n"
257 "The initial_value argument sets the value of object.  The newline\n"
258 "argument is like the one of TextIOWrapper\'s constructor.");
259 
260 static int
261 _io_StringIO___init___impl(stringio *self, PyObject *value,
262                            PyObject *newline_obj);
263 
264 static int
_io_StringIO___init__(PyObject * self,PyObject * args,PyObject * kwargs)265 _io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
266 {
267     int return_value = -1;
268     static const char * const _keywords[] = {"initial_value", "newline", NULL};
269     static _PyArg_Parser _parser = {NULL, _keywords, "StringIO", 0};
270     PyObject *argsbuf[2];
271     PyObject * const *fastargs;
272     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
273     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
274     PyObject *value = NULL;
275     PyObject *newline_obj = NULL;
276 
277     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
278     if (!fastargs) {
279         goto exit;
280     }
281     if (!noptargs) {
282         goto skip_optional_pos;
283     }
284     if (fastargs[0]) {
285         value = fastargs[0];
286         if (!--noptargs) {
287             goto skip_optional_pos;
288         }
289     }
290     newline_obj = fastargs[1];
291 skip_optional_pos:
292     return_value = _io_StringIO___init___impl((stringio *)self, value, newline_obj);
293 
294 exit:
295     return return_value;
296 }
297 
298 PyDoc_STRVAR(_io_StringIO_readable__doc__,
299 "readable($self, /)\n"
300 "--\n"
301 "\n"
302 "Returns True if the IO object can be read.");
303 
304 #define _IO_STRINGIO_READABLE_METHODDEF    \
305     {"readable", (PyCFunction)_io_StringIO_readable, METH_NOARGS, _io_StringIO_readable__doc__},
306 
307 static PyObject *
308 _io_StringIO_readable_impl(stringio *self);
309 
310 static PyObject *
_io_StringIO_readable(stringio * self,PyObject * Py_UNUSED (ignored))311 _io_StringIO_readable(stringio *self, PyObject *Py_UNUSED(ignored))
312 {
313     return _io_StringIO_readable_impl(self);
314 }
315 
316 PyDoc_STRVAR(_io_StringIO_writable__doc__,
317 "writable($self, /)\n"
318 "--\n"
319 "\n"
320 "Returns True if the IO object can be written.");
321 
322 #define _IO_STRINGIO_WRITABLE_METHODDEF    \
323     {"writable", (PyCFunction)_io_StringIO_writable, METH_NOARGS, _io_StringIO_writable__doc__},
324 
325 static PyObject *
326 _io_StringIO_writable_impl(stringio *self);
327 
328 static PyObject *
_io_StringIO_writable(stringio * self,PyObject * Py_UNUSED (ignored))329 _io_StringIO_writable(stringio *self, PyObject *Py_UNUSED(ignored))
330 {
331     return _io_StringIO_writable_impl(self);
332 }
333 
334 PyDoc_STRVAR(_io_StringIO_seekable__doc__,
335 "seekable($self, /)\n"
336 "--\n"
337 "\n"
338 "Returns True if the IO object can be seeked.");
339 
340 #define _IO_STRINGIO_SEEKABLE_METHODDEF    \
341     {"seekable", (PyCFunction)_io_StringIO_seekable, METH_NOARGS, _io_StringIO_seekable__doc__},
342 
343 static PyObject *
344 _io_StringIO_seekable_impl(stringio *self);
345 
346 static PyObject *
_io_StringIO_seekable(stringio * self,PyObject * Py_UNUSED (ignored))347 _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
348 {
349     return _io_StringIO_seekable_impl(self);
350 }
351 /*[clinic end generated code: output=7aad5ab2e64a25b8 input=a9049054013a1b77]*/
352