/src/cpython/Modules/_io/clinic/textio.c.h
Line | Count | Source |
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 | | #endif |
8 | | #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() |
9 | | #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() |
10 | | #include "pycore_modsupport.h" // _PyArg_CheckPositional() |
11 | | #include "pycore_runtime.h" // _Py_SINGLETON() |
12 | | #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() |
13 | | |
14 | | PyDoc_STRVAR(_io__TextIOBase_detach__doc__, |
15 | | "detach($self, /)\n" |
16 | | "--\n" |
17 | | "\n" |
18 | | "Separate the underlying buffer from the TextIOBase and return it.\n" |
19 | | "\n" |
20 | | "After the underlying buffer has been detached, the TextIO is in\n" |
21 | | "an unusable state."); |
22 | | |
23 | | #define _IO__TEXTIOBASE_DETACH_METHODDEF \ |
24 | | {"detach", _PyCFunction_CAST(_io__TextIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_detach__doc__}, |
25 | | |
26 | | static PyObject * |
27 | | _io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls); |
28 | | |
29 | | static PyObject * |
30 | | _io__TextIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
31 | 0 | { |
32 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
33 | 0 | PyErr_SetString(PyExc_TypeError, "detach() takes no arguments"); |
34 | 0 | return NULL; |
35 | 0 | } |
36 | 0 | return _io__TextIOBase_detach_impl(self, cls); |
37 | 0 | } |
38 | | |
39 | | PyDoc_STRVAR(_io__TextIOBase_read__doc__, |
40 | | "read($self, size=-1, /)\n" |
41 | | "--\n" |
42 | | "\n" |
43 | | "Read at most size characters from stream.\n" |
44 | | "\n" |
45 | | "Read from underlying buffer until we have size characters or we hit\n" |
46 | | "EOF. If size is negative or omitted, read until EOF."); |
47 | | |
48 | | #define _IO__TEXTIOBASE_READ_METHODDEF \ |
49 | | {"read", _PyCFunction_CAST(_io__TextIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_read__doc__}, |
50 | | |
51 | | static PyObject * |
52 | | _io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls, |
53 | | int Py_UNUSED(size)); |
54 | | |
55 | | static PyObject * |
56 | | _io__TextIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
57 | 0 | { |
58 | 0 | PyObject *return_value = NULL; |
59 | 0 | int size = -1; |
60 | |
|
61 | 0 | if (!_PyArg_NoKwnames("read", kwnames)) { |
62 | 0 | goto exit; |
63 | 0 | } |
64 | 0 | if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
65 | 0 | goto exit; |
66 | 0 | } |
67 | 0 | if (nargs < 1) { |
68 | 0 | goto skip_optional; |
69 | 0 | } |
70 | 0 | size = PyLong_AsInt(args[0]); |
71 | 0 | if (size == -1 && PyErr_Occurred()) { |
72 | 0 | goto exit; |
73 | 0 | } |
74 | 0 | skip_optional: |
75 | 0 | return_value = _io__TextIOBase_read_impl(self, cls, size); |
76 | |
|
77 | 0 | exit: |
78 | 0 | return return_value; |
79 | 0 | } |
80 | | |
81 | | PyDoc_STRVAR(_io__TextIOBase_readline__doc__, |
82 | | "readline($self, size=-1, /)\n" |
83 | | "--\n" |
84 | | "\n" |
85 | | "Read until newline or EOF.\n" |
86 | | "\n" |
87 | | "Return an empty string if EOF is hit immediately.\n" |
88 | | "If size is specified, at most size characters will be read."); |
89 | | |
90 | | #define _IO__TEXTIOBASE_READLINE_METHODDEF \ |
91 | | {"readline", _PyCFunction_CAST(_io__TextIOBase_readline), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_readline__doc__}, |
92 | | |
93 | | static PyObject * |
94 | | _io__TextIOBase_readline_impl(PyObject *self, PyTypeObject *cls, |
95 | | int Py_UNUSED(size)); |
96 | | |
97 | | static PyObject * |
98 | | _io__TextIOBase_readline(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
99 | 0 | { |
100 | 0 | PyObject *return_value = NULL; |
101 | 0 | int size = -1; |
102 | |
|
103 | 0 | if (!_PyArg_NoKwnames("readline", kwnames)) { |
104 | 0 | goto exit; |
105 | 0 | } |
106 | 0 | if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { |
107 | 0 | goto exit; |
108 | 0 | } |
109 | 0 | if (nargs < 1) { |
110 | 0 | goto skip_optional; |
111 | 0 | } |
112 | 0 | size = PyLong_AsInt(args[0]); |
113 | 0 | if (size == -1 && PyErr_Occurred()) { |
114 | 0 | goto exit; |
115 | 0 | } |
116 | 0 | skip_optional: |
117 | 0 | return_value = _io__TextIOBase_readline_impl(self, cls, size); |
118 | |
|
119 | 0 | exit: |
120 | 0 | return return_value; |
121 | 0 | } |
122 | | |
123 | | PyDoc_STRVAR(_io__TextIOBase_write__doc__, |
124 | | "write($self, s, /)\n" |
125 | | "--\n" |
126 | | "\n" |
127 | | "Write string s to stream.\n" |
128 | | "\n" |
129 | | "Return the number of characters written\n" |
130 | | "(which is always equal to the length of the string)."); |
131 | | |
132 | | #define _IO__TEXTIOBASE_WRITE_METHODDEF \ |
133 | | {"write", _PyCFunction_CAST(_io__TextIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_write__doc__}, |
134 | | |
135 | | static PyObject * |
136 | | _io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls, |
137 | | const char *Py_UNUSED(s)); |
138 | | |
139 | | static PyObject * |
140 | | _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
141 | 0 | { |
142 | 0 | PyObject *return_value = NULL; |
143 | 0 | const char *s; |
144 | |
|
145 | 0 | if (!_PyArg_NoKwnames("write", kwnames)) { |
146 | 0 | goto exit; |
147 | 0 | } |
148 | 0 | if (!_PyArg_CheckPositional("write", nargs, 1, 1)) { |
149 | 0 | goto exit; |
150 | 0 | } |
151 | 0 | if (!PyUnicode_Check(args[0])) { |
152 | 0 | _PyArg_BadArgument("write", "argument 1", "str", args[0]); |
153 | 0 | goto exit; |
154 | 0 | } |
155 | 0 | s = _PyUnicode_AsUTF8NoNUL(args[0]); |
156 | 0 | if (s == NULL) { |
157 | 0 | goto exit; |
158 | 0 | } |
159 | 0 | return_value = _io__TextIOBase_write_impl(self, cls, s); |
160 | |
|
161 | 0 | exit: |
162 | 0 | return return_value; |
163 | 0 | } |
164 | | |
165 | | PyDoc_STRVAR(_io__TextIOBase_encoding__doc__, |
166 | | "Encoding of the text stream.\n" |
167 | | "\n" |
168 | | "Subclasses should override."); |
169 | | |
170 | | static PyObject * |
171 | | _io__TextIOBase_encoding_get_impl(PyObject *self); |
172 | | |
173 | | static PyObject * |
174 | | _io__TextIOBase_encoding_get(PyObject *self, void *Py_UNUSED(context)) |
175 | 0 | { |
176 | 0 | return _io__TextIOBase_encoding_get_impl(self); |
177 | 0 | } |
178 | | |
179 | | PyDoc_STRVAR(_io__TextIOBase_newlines__doc__, |
180 | | "Line endings translated so far.\n" |
181 | | "\n" |
182 | | "Only line endings translated during reading are considered.\n" |
183 | | "\n" |
184 | | "Subclasses should override."); |
185 | | |
186 | | static PyObject * |
187 | | _io__TextIOBase_newlines_get_impl(PyObject *self); |
188 | | |
189 | | static PyObject * |
190 | | _io__TextIOBase_newlines_get(PyObject *self, void *Py_UNUSED(context)) |
191 | 0 | { |
192 | 0 | return _io__TextIOBase_newlines_get_impl(self); |
193 | 0 | } |
194 | | |
195 | | PyDoc_STRVAR(_io__TextIOBase_errors__doc__, |
196 | | "The error setting of the decoder or encoder.\n" |
197 | | "\n" |
198 | | "Subclasses should override."); |
199 | | |
200 | | static PyObject * |
201 | | _io__TextIOBase_errors_get_impl(PyObject *self); |
202 | | |
203 | | static PyObject * |
204 | | _io__TextIOBase_errors_get(PyObject *self, void *Py_UNUSED(context)) |
205 | 0 | { |
206 | 0 | return _io__TextIOBase_errors_get_impl(self); |
207 | 0 | } |
208 | | |
209 | | PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__, |
210 | | "IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n" |
211 | | "--\n" |
212 | | "\n" |
213 | | "Codec used when reading a file in universal newlines mode.\n" |
214 | | "\n" |
215 | | "It wraps another incremental decoder, translating \\r\\n and \\r into \\n.\n" |
216 | | "It also records the types of newlines encountered. When used with\n" |
217 | | "translate=False, it ensures that the newline sequence is returned in\n" |
218 | | "one piece. When used with decoder=None, it expects unicode strings as\n" |
219 | | "decode input and translates newlines without first invoking an external\n" |
220 | | "decoder."); |
221 | | |
222 | | static int |
223 | | _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self, |
224 | | PyObject *decoder, int translate, |
225 | | PyObject *errors); |
226 | | |
227 | | static int |
228 | | _io_IncrementalNewlineDecoder___init___helper(PyObject *self, PyObject *const *args, |
229 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
230 | 0 | { |
231 | 0 | int return_value = -1; |
232 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
233 | |
|
234 | 0 | #define NUM_KEYWORDS 3 |
235 | 0 | static struct { |
236 | 0 | PyGC_Head _this_is_not_used; |
237 | 0 | PyObject_VAR_HEAD |
238 | 0 | Py_hash_t ob_hash; |
239 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
240 | 0 | } _kwtuple = { |
241 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
242 | 0 | .ob_hash = -1, |
243 | 0 | .ob_item = { &_Py_ID(decoder), &_Py_ID(translate), &_Py_ID(errors), }, |
244 | 0 | }; |
245 | 0 | #undef NUM_KEYWORDS |
246 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
247 | |
|
248 | | #else // !Py_BUILD_CORE |
249 | | # define KWTUPLE NULL |
250 | | #endif // !Py_BUILD_CORE |
251 | |
|
252 | 0 | static const char * const _keywords[] = {"decoder", "translate", "errors", NULL}; |
253 | 0 | static _PyArg_Parser _parser = { |
254 | 0 | .keywords = _keywords, |
255 | 0 | .fname = "IncrementalNewlineDecoder", |
256 | 0 | .kwtuple = KWTUPLE, |
257 | 0 | }; |
258 | 0 | #undef KWTUPLE |
259 | 0 | PyObject *argsbuf[3]; |
260 | 0 | PyObject * const *fastargs; |
261 | 0 | Py_ssize_t noptargs = nargs + nkw - 2; |
262 | 0 | PyObject *decoder; |
263 | 0 | int translate; |
264 | 0 | PyObject *errors = NULL; |
265 | |
|
266 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
267 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
268 | 0 | if (!fastargs) { |
269 | 0 | goto exit; |
270 | 0 | } |
271 | 0 | decoder = fastargs[0]; |
272 | 0 | translate = PyObject_IsTrue(fastargs[1]); |
273 | 0 | if (translate < 0) { |
274 | 0 | goto exit; |
275 | 0 | } |
276 | 0 | if (!noptargs) { |
277 | 0 | goto skip_optional_pos; |
278 | 0 | } |
279 | 0 | errors = fastargs[2]; |
280 | 0 | skip_optional_pos: |
281 | 0 | return_value = _io_IncrementalNewlineDecoder___init___impl((nldecoder_object *)self, decoder, translate, errors); |
282 | |
|
283 | 0 | exit: |
284 | 0 | return return_value; |
285 | 0 | } |
286 | | |
287 | | static int |
288 | | _io_IncrementalNewlineDecoder___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
289 | 0 | { |
290 | 0 | return _io_IncrementalNewlineDecoder___init___helper(self, _PyTuple_CAST(args)->ob_item, |
291 | 0 | PyTuple_GET_SIZE(args), |
292 | 0 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
293 | 0 | kwargs, NULL); |
294 | 0 | } |
295 | | |
296 | | static PyObject * |
297 | | _io_IncrementalNewlineDecoder_vectorcall(PyObject *type, PyObject *const *args, |
298 | | size_t nargsf, PyObject *kwnames) |
299 | 16.7k | { |
300 | 16.7k | PyObject *return_value = NULL; |
301 | 16.7k | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
302 | 16.7k | PyObject *self; |
303 | 16.7k | int _result; |
304 | 16.7k | PyObject *decoder; |
305 | 16.7k | int translate; |
306 | 16.7k | PyObject *errors = NULL; |
307 | | |
308 | 16.7k | assert(_PyType_CAST(type)->tp_init == _io_IncrementalNewlineDecoder___init__); |
309 | | /* Make sure the type object is immutable: the generated |
310 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
311 | 16.7k | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
312 | 16.7k | if (kwnames != NULL || nargs < 2 || nargs > 3) { |
313 | 0 | self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), |
314 | 0 | (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); |
315 | 0 | if (self == NULL) { |
316 | 0 | return NULL; |
317 | 0 | } |
318 | 0 | _result = _io_IncrementalNewlineDecoder___init___helper(self, args, nargs, |
319 | 0 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
320 | 0 | NULL, kwnames); |
321 | 0 | if (_result != 0) { |
322 | 0 | Py_DECREF(self); |
323 | 0 | return NULL; |
324 | 0 | } |
325 | 0 | return self; |
326 | 0 | } |
327 | 16.7k | decoder = args[0]; |
328 | 16.7k | translate = PyObject_IsTrue(args[1]); |
329 | 16.7k | if (translate < 0) { |
330 | 0 | goto exit; |
331 | 0 | } |
332 | 16.7k | if (nargs < 3) { |
333 | 16.7k | goto skip_optional; |
334 | 16.7k | } |
335 | 0 | errors = args[2]; |
336 | 16.7k | skip_optional: |
337 | 16.7k | self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), |
338 | 16.7k | (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); |
339 | 16.7k | if (self == NULL) { |
340 | 0 | goto exit; |
341 | 0 | } |
342 | 16.7k | _result = _io_IncrementalNewlineDecoder___init___impl((nldecoder_object *)self, decoder, translate, errors); |
343 | 16.7k | if (_result != 0) { |
344 | 0 | Py_DECREF(self); |
345 | 0 | goto exit; |
346 | 0 | } |
347 | 16.7k | return_value = self; |
348 | | |
349 | 16.7k | exit: |
350 | 16.7k | return return_value; |
351 | 16.7k | } |
352 | | |
353 | | PyDoc_STRVAR(_io_IncrementalNewlineDecoder_decode__doc__, |
354 | | "decode($self, /, input, final=False)\n" |
355 | | "--\n" |
356 | | "\n"); |
357 | | |
358 | | #define _IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF \ |
359 | | {"decode", _PyCFunction_CAST(_io_IncrementalNewlineDecoder_decode), METH_FASTCALL|METH_KEYWORDS, _io_IncrementalNewlineDecoder_decode__doc__}, |
360 | | |
361 | | static PyObject * |
362 | | _io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self, |
363 | | PyObject *input, int final); |
364 | | |
365 | | static PyObject * |
366 | | _io_IncrementalNewlineDecoder_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
367 | 0 | { |
368 | 0 | PyObject *return_value = NULL; |
369 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
370 | |
|
371 | 0 | #define NUM_KEYWORDS 2 |
372 | 0 | static struct { |
373 | 0 | PyGC_Head _this_is_not_used; |
374 | 0 | PyObject_VAR_HEAD |
375 | 0 | Py_hash_t ob_hash; |
376 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
377 | 0 | } _kwtuple = { |
378 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
379 | 0 | .ob_hash = -1, |
380 | 0 | .ob_item = { &_Py_ID(input), &_Py_ID(final), }, |
381 | 0 | }; |
382 | 0 | #undef NUM_KEYWORDS |
383 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
384 | |
|
385 | | #else // !Py_BUILD_CORE |
386 | | # define KWTUPLE NULL |
387 | | #endif // !Py_BUILD_CORE |
388 | |
|
389 | 0 | static const char * const _keywords[] = {"input", "final", NULL}; |
390 | 0 | static _PyArg_Parser _parser = { |
391 | 0 | .keywords = _keywords, |
392 | 0 | .fname = "decode", |
393 | 0 | .kwtuple = KWTUPLE, |
394 | 0 | }; |
395 | 0 | #undef KWTUPLE |
396 | 0 | PyObject *argsbuf[2]; |
397 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
398 | 0 | PyObject *input; |
399 | 0 | int final = 0; |
400 | |
|
401 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
402 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
403 | 0 | if (!args) { |
404 | 0 | goto exit; |
405 | 0 | } |
406 | 0 | input = args[0]; |
407 | 0 | if (!noptargs) { |
408 | 0 | goto skip_optional_pos; |
409 | 0 | } |
410 | 0 | final = PyObject_IsTrue(args[1]); |
411 | 0 | if (final < 0) { |
412 | 0 | goto exit; |
413 | 0 | } |
414 | 0 | skip_optional_pos: |
415 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
416 | 0 | return_value = _io_IncrementalNewlineDecoder_decode_impl((nldecoder_object *)self, input, final); |
417 | 0 | Py_END_CRITICAL_SECTION(); |
418 | |
|
419 | 0 | exit: |
420 | 0 | return return_value; |
421 | 0 | } |
422 | | |
423 | | PyDoc_STRVAR(_io_IncrementalNewlineDecoder_getstate__doc__, |
424 | | "getstate($self, /)\n" |
425 | | "--\n" |
426 | | "\n"); |
427 | | |
428 | | #define _IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF \ |
429 | | {"getstate", (PyCFunction)_io_IncrementalNewlineDecoder_getstate, METH_NOARGS, _io_IncrementalNewlineDecoder_getstate__doc__}, |
430 | | |
431 | | static PyObject * |
432 | | _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self); |
433 | | |
434 | | static PyObject * |
435 | | _io_IncrementalNewlineDecoder_getstate(PyObject *self, PyObject *Py_UNUSED(ignored)) |
436 | 0 | { |
437 | 0 | PyObject *return_value = NULL; |
438 | |
|
439 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
440 | 0 | return_value = _io_IncrementalNewlineDecoder_getstate_impl((nldecoder_object *)self); |
441 | 0 | Py_END_CRITICAL_SECTION(); |
442 | |
|
443 | 0 | return return_value; |
444 | 0 | } |
445 | | |
446 | | PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__, |
447 | | "setstate($self, state, /)\n" |
448 | | "--\n" |
449 | | "\n"); |
450 | | |
451 | | #define _IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF \ |
452 | | {"setstate", (PyCFunction)_io_IncrementalNewlineDecoder_setstate, METH_O, _io_IncrementalNewlineDecoder_setstate__doc__}, |
453 | | |
454 | | static PyObject * |
455 | | _io_IncrementalNewlineDecoder_setstate_impl(nldecoder_object *self, |
456 | | PyObject *state); |
457 | | |
458 | | static PyObject * |
459 | | _io_IncrementalNewlineDecoder_setstate(PyObject *self, PyObject *state) |
460 | 0 | { |
461 | 0 | PyObject *return_value = NULL; |
462 | |
|
463 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
464 | 0 | return_value = _io_IncrementalNewlineDecoder_setstate_impl((nldecoder_object *)self, state); |
465 | 0 | Py_END_CRITICAL_SECTION(); |
466 | |
|
467 | 0 | return return_value; |
468 | 0 | } |
469 | | |
470 | | PyDoc_STRVAR(_io_IncrementalNewlineDecoder_reset__doc__, |
471 | | "reset($self, /)\n" |
472 | | "--\n" |
473 | | "\n"); |
474 | | |
475 | | #define _IO_INCREMENTALNEWLINEDECODER_RESET_METHODDEF \ |
476 | | {"reset", (PyCFunction)_io_IncrementalNewlineDecoder_reset, METH_NOARGS, _io_IncrementalNewlineDecoder_reset__doc__}, |
477 | | |
478 | | static PyObject * |
479 | | _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self); |
480 | | |
481 | | static PyObject * |
482 | | _io_IncrementalNewlineDecoder_reset(PyObject *self, PyObject *Py_UNUSED(ignored)) |
483 | 0 | { |
484 | 0 | PyObject *return_value = NULL; |
485 | |
|
486 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
487 | 0 | return_value = _io_IncrementalNewlineDecoder_reset_impl((nldecoder_object *)self); |
488 | 0 | Py_END_CRITICAL_SECTION(); |
489 | |
|
490 | 0 | return return_value; |
491 | 0 | } |
492 | | |
493 | | static PyObject * |
494 | | _io_IncrementalNewlineDecoder_newlines_get_impl(nldecoder_object *self); |
495 | | |
496 | | static PyObject * |
497 | | _io_IncrementalNewlineDecoder_newlines_get(PyObject *self, void *Py_UNUSED(context)) |
498 | 0 | { |
499 | 0 | return _io_IncrementalNewlineDecoder_newlines_get_impl((nldecoder_object *)self); |
500 | 0 | } |
501 | | |
502 | | PyDoc_STRVAR(_io_TextIOWrapper___init____doc__, |
503 | | "TextIOWrapper(buffer, encoding=None, errors=None, newline=None,\n" |
504 | | " line_buffering=False, write_through=False)\n" |
505 | | "--\n" |
506 | | "\n" |
507 | | "Character and line based layer over a BufferedIOBase object, buffer.\n" |
508 | | "\n" |
509 | | "encoding gives the name of the encoding that the stream will be\n" |
510 | | "decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is\n" |
511 | | "disabled, the encoding returned by locale.getencoding() is used\n" |
512 | | "instead. See the codecs module for the list of supported\n" |
513 | | "encodings.\n" |
514 | | "\n" |
515 | | "errors determines the strictness of encoding and decoding (see\n" |
516 | | "help(codecs.Codec) or the documentation for codecs.register) and\n" |
517 | | "defaults to \"strict\".\n" |
518 | | "\n" |
519 | | "newline controls how line endings are handled. It can be None, \'\',\n" |
520 | | "\'\\n\', \'\\r\', and \'\\r\\n\'. It works as follows:\n" |
521 | | "\n" |
522 | | "* On input, if newline is None, universal newlines mode is\n" |
523 | | " enabled. Lines in the input can end in \'\\n\', \'\\r\', or \'\\r\\n\', and\n" |
524 | | " these are translated into \'\\n\' before being returned to the\n" |
525 | | " caller. If it is \'\', universal newline mode is enabled, but line\n" |
526 | | " endings are returned to the caller untranslated. If it has any of\n" |
527 | | " the other legal values, input lines are only terminated by the given\n" |
528 | | " string, and the line ending is returned to the caller untranslated.\n" |
529 | | "\n" |
530 | | "* On output, if newline is None, any \'\\n\' characters written are\n" |
531 | | " translated to the system default line separator, os.linesep. If\n" |
532 | | " newline is \'\' or \'\\n\', no translation takes place. If newline is any\n" |
533 | | " of the other legal values, any \'\\n\' characters written are translated\n" |
534 | | " to the given string.\n" |
535 | | "\n" |
536 | | "If line_buffering is True, a call to flush is implied when a call to\n" |
537 | | "write contains a newline character."); |
538 | | |
539 | | static int |
540 | | _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, |
541 | | const char *encoding, PyObject *errors, |
542 | | const char *newline, int line_buffering, |
543 | | int write_through); |
544 | | |
545 | | static int |
546 | | _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
547 | 130 | { |
548 | 130 | int return_value = -1; |
549 | 130 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
550 | | |
551 | 130 | #define NUM_KEYWORDS 6 |
552 | 130 | static struct { |
553 | 130 | PyGC_Head _this_is_not_used; |
554 | 130 | PyObject_VAR_HEAD |
555 | 130 | Py_hash_t ob_hash; |
556 | 130 | PyObject *ob_item[NUM_KEYWORDS]; |
557 | 130 | } _kwtuple = { |
558 | 130 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
559 | 130 | .ob_hash = -1, |
560 | 130 | .ob_item = { &_Py_ID(buffer), &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), }, |
561 | 130 | }; |
562 | 130 | #undef NUM_KEYWORDS |
563 | 130 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
564 | | |
565 | | #else // !Py_BUILD_CORE |
566 | | # define KWTUPLE NULL |
567 | | #endif // !Py_BUILD_CORE |
568 | | |
569 | 130 | static const char * const _keywords[] = {"buffer", "encoding", "errors", "newline", "line_buffering", "write_through", NULL}; |
570 | 130 | static _PyArg_Parser _parser = { |
571 | 130 | .keywords = _keywords, |
572 | 130 | .fname = "TextIOWrapper", |
573 | 130 | .kwtuple = KWTUPLE, |
574 | 130 | }; |
575 | 130 | #undef KWTUPLE |
576 | 130 | PyObject *argsbuf[6]; |
577 | 130 | PyObject * const *fastargs; |
578 | 130 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
579 | 130 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
580 | 130 | PyObject *buffer; |
581 | 130 | const char *encoding = NULL; |
582 | 130 | PyObject *errors = Py_None; |
583 | 130 | const char *newline = NULL; |
584 | 130 | int line_buffering = 0; |
585 | 130 | int write_through = 0; |
586 | | |
587 | 130 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
588 | 130 | /*minpos*/ 1, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
589 | 130 | if (!fastargs) { |
590 | 0 | goto exit; |
591 | 0 | } |
592 | 130 | buffer = fastargs[0]; |
593 | 130 | if (!noptargs) { |
594 | 0 | goto skip_optional_pos; |
595 | 0 | } |
596 | 130 | if (fastargs[1]) { |
597 | 130 | if (fastargs[1] == Py_None) { |
598 | 0 | encoding = NULL; |
599 | 0 | } |
600 | 130 | else if (PyUnicode_Check(fastargs[1])) { |
601 | 130 | encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); |
602 | 130 | if (encoding == NULL) { |
603 | 0 | goto exit; |
604 | 0 | } |
605 | 130 | } |
606 | 0 | else { |
607 | 0 | _PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]); |
608 | 0 | goto exit; |
609 | 0 | } |
610 | 130 | if (!--noptargs) { |
611 | 0 | goto skip_optional_pos; |
612 | 0 | } |
613 | 130 | } |
614 | 130 | if (fastargs[2]) { |
615 | 120 | errors = fastargs[2]; |
616 | 120 | if (!--noptargs) { |
617 | 0 | goto skip_optional_pos; |
618 | 0 | } |
619 | 120 | } |
620 | 130 | if (fastargs[3]) { |
621 | 120 | if (fastargs[3] == Py_None) { |
622 | 9 | newline = NULL; |
623 | 9 | } |
624 | 111 | else if (PyUnicode_Check(fastargs[3])) { |
625 | 111 | newline = _PyUnicode_AsUTF8NoNUL(fastargs[3]); |
626 | 111 | if (newline == NULL) { |
627 | 0 | goto exit; |
628 | 0 | } |
629 | 111 | } |
630 | 0 | else { |
631 | 0 | _PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]); |
632 | 0 | goto exit; |
633 | 0 | } |
634 | 120 | if (!--noptargs) { |
635 | 0 | goto skip_optional_pos; |
636 | 0 | } |
637 | 120 | } |
638 | 130 | if (fastargs[4]) { |
639 | 130 | line_buffering = PyObject_IsTrue(fastargs[4]); |
640 | 130 | if (line_buffering < 0) { |
641 | 0 | goto exit; |
642 | 0 | } |
643 | 130 | if (!--noptargs) { |
644 | 19 | goto skip_optional_pos; |
645 | 19 | } |
646 | 130 | } |
647 | 111 | write_through = PyObject_IsTrue(fastargs[5]); |
648 | 111 | if (write_through < 0) { |
649 | 0 | goto exit; |
650 | 0 | } |
651 | 130 | skip_optional_pos: |
652 | 130 | Py_BEGIN_CRITICAL_SECTION(self); |
653 | 130 | return_value = _io_TextIOWrapper___init___impl((textio *)self, buffer, encoding, errors, newline, line_buffering, write_through); |
654 | 130 | Py_END_CRITICAL_SECTION(); |
655 | | |
656 | 130 | exit: |
657 | 130 | return return_value; |
658 | 130 | } |
659 | | |
660 | | PyDoc_STRVAR(_io_TextIOWrapper_reconfigure__doc__, |
661 | | "reconfigure($self, /, *, encoding=None, errors=None, newline=None,\n" |
662 | | " line_buffering=None, write_through=None)\n" |
663 | | "--\n" |
664 | | "\n" |
665 | | "Reconfigure the text stream with new parameters.\n" |
666 | | "\n" |
667 | | "This also does an implicit stream flush."); |
668 | | |
669 | | #define _IO_TEXTIOWRAPPER_RECONFIGURE_METHODDEF \ |
670 | | {"reconfigure", _PyCFunction_CAST(_io_TextIOWrapper_reconfigure), METH_FASTCALL|METH_KEYWORDS, _io_TextIOWrapper_reconfigure__doc__}, |
671 | | |
672 | | static PyObject * |
673 | | _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding, |
674 | | PyObject *errors, PyObject *newline_obj, |
675 | | PyObject *line_buffering_obj, |
676 | | PyObject *write_through_obj); |
677 | | |
678 | | static PyObject * |
679 | | _io_TextIOWrapper_reconfigure(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
680 | 0 | { |
681 | 0 | PyObject *return_value = NULL; |
682 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
683 | |
|
684 | 0 | #define NUM_KEYWORDS 5 |
685 | 0 | static struct { |
686 | 0 | PyGC_Head _this_is_not_used; |
687 | 0 | PyObject_VAR_HEAD |
688 | 0 | Py_hash_t ob_hash; |
689 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
690 | 0 | } _kwtuple = { |
691 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
692 | 0 | .ob_hash = -1, |
693 | 0 | .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), }, |
694 | 0 | }; |
695 | 0 | #undef NUM_KEYWORDS |
696 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
697 | |
|
698 | | #else // !Py_BUILD_CORE |
699 | | # define KWTUPLE NULL |
700 | | #endif // !Py_BUILD_CORE |
701 | |
|
702 | 0 | static const char * const _keywords[] = {"encoding", "errors", "newline", "line_buffering", "write_through", NULL}; |
703 | 0 | static _PyArg_Parser _parser = { |
704 | 0 | .keywords = _keywords, |
705 | 0 | .fname = "reconfigure", |
706 | 0 | .kwtuple = KWTUPLE, |
707 | 0 | }; |
708 | 0 | #undef KWTUPLE |
709 | 0 | PyObject *argsbuf[5]; |
710 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
711 | 0 | PyObject *encoding = Py_None; |
712 | 0 | PyObject *errors = Py_None; |
713 | 0 | PyObject *newline_obj = NULL; |
714 | 0 | PyObject *line_buffering_obj = Py_None; |
715 | 0 | PyObject *write_through_obj = Py_None; |
716 | |
|
717 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
718 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
719 | 0 | if (!args) { |
720 | 0 | goto exit; |
721 | 0 | } |
722 | 0 | if (!noptargs) { |
723 | 0 | goto skip_optional_kwonly; |
724 | 0 | } |
725 | 0 | if (args[0]) { |
726 | 0 | encoding = args[0]; |
727 | 0 | if (!--noptargs) { |
728 | 0 | goto skip_optional_kwonly; |
729 | 0 | } |
730 | 0 | } |
731 | 0 | if (args[1]) { |
732 | 0 | errors = args[1]; |
733 | 0 | if (!--noptargs) { |
734 | 0 | goto skip_optional_kwonly; |
735 | 0 | } |
736 | 0 | } |
737 | 0 | if (args[2]) { |
738 | 0 | newline_obj = args[2]; |
739 | 0 | if (!--noptargs) { |
740 | 0 | goto skip_optional_kwonly; |
741 | 0 | } |
742 | 0 | } |
743 | 0 | if (args[3]) { |
744 | 0 | line_buffering_obj = args[3]; |
745 | 0 | if (!--noptargs) { |
746 | 0 | goto skip_optional_kwonly; |
747 | 0 | } |
748 | 0 | } |
749 | 0 | write_through_obj = args[4]; |
750 | 0 | skip_optional_kwonly: |
751 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
752 | 0 | return_value = _io_TextIOWrapper_reconfigure_impl((textio *)self, encoding, errors, newline_obj, line_buffering_obj, write_through_obj); |
753 | 0 | Py_END_CRITICAL_SECTION(); |
754 | |
|
755 | 0 | exit: |
756 | 0 | return return_value; |
757 | 0 | } |
758 | | |
759 | | PyDoc_STRVAR(_io_TextIOWrapper_detach__doc__, |
760 | | "detach($self, /)\n" |
761 | | "--\n" |
762 | | "\n"); |
763 | | |
764 | | #define _IO_TEXTIOWRAPPER_DETACH_METHODDEF \ |
765 | | {"detach", (PyCFunction)_io_TextIOWrapper_detach, METH_NOARGS, _io_TextIOWrapper_detach__doc__}, |
766 | | |
767 | | static PyObject * |
768 | | _io_TextIOWrapper_detach_impl(textio *self); |
769 | | |
770 | | static PyObject * |
771 | | _io_TextIOWrapper_detach(PyObject *self, PyObject *Py_UNUSED(ignored)) |
772 | 0 | { |
773 | 0 | PyObject *return_value = NULL; |
774 | |
|
775 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
776 | 0 | return_value = _io_TextIOWrapper_detach_impl((textio *)self); |
777 | 0 | Py_END_CRITICAL_SECTION(); |
778 | |
|
779 | 0 | return return_value; |
780 | 0 | } |
781 | | |
782 | | PyDoc_STRVAR(_io_TextIOWrapper_write__doc__, |
783 | | "write($self, text, /)\n" |
784 | | "--\n" |
785 | | "\n"); |
786 | | |
787 | | #define _IO_TEXTIOWRAPPER_WRITE_METHODDEF \ |
788 | | {"write", (PyCFunction)_io_TextIOWrapper_write, METH_O, _io_TextIOWrapper_write__doc__}, |
789 | | |
790 | | static PyObject * |
791 | | _io_TextIOWrapper_write_impl(textio *self, PyObject *text); |
792 | | |
793 | | static PyObject * |
794 | | _io_TextIOWrapper_write(PyObject *self, PyObject *arg) |
795 | 175k | { |
796 | 175k | PyObject *return_value = NULL; |
797 | 175k | PyObject *text; |
798 | | |
799 | 175k | if (!PyUnicode_Check(arg)) { |
800 | 0 | _PyArg_BadArgument("write", "argument", "str", arg); |
801 | 0 | goto exit; |
802 | 0 | } |
803 | 175k | text = arg; |
804 | 175k | Py_BEGIN_CRITICAL_SECTION(self); |
805 | 175k | return_value = _io_TextIOWrapper_write_impl((textio *)self, text); |
806 | 175k | Py_END_CRITICAL_SECTION(); |
807 | | |
808 | 175k | exit: |
809 | 175k | return return_value; |
810 | 175k | } |
811 | | |
812 | | PyDoc_STRVAR(_io_TextIOWrapper_read__doc__, |
813 | | "read($self, size=-1, /)\n" |
814 | | "--\n" |
815 | | "\n"); |
816 | | |
817 | | #define _IO_TEXTIOWRAPPER_READ_METHODDEF \ |
818 | | {"read", _PyCFunction_CAST(_io_TextIOWrapper_read), METH_FASTCALL, _io_TextIOWrapper_read__doc__}, |
819 | | |
820 | | static PyObject * |
821 | | _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n); |
822 | | |
823 | | static PyObject * |
824 | | _io_TextIOWrapper_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
825 | 8 | { |
826 | 8 | PyObject *return_value = NULL; |
827 | 8 | Py_ssize_t n = -1; |
828 | | |
829 | 8 | if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
830 | 0 | goto exit; |
831 | 0 | } |
832 | 8 | if (nargs < 1) { |
833 | 8 | goto skip_optional; |
834 | 8 | } |
835 | 0 | if (!_Py_convert_optional_to_ssize_t(args[0], &n)) { |
836 | 0 | goto exit; |
837 | 0 | } |
838 | 8 | skip_optional: |
839 | 8 | Py_BEGIN_CRITICAL_SECTION(self); |
840 | 8 | return_value = _io_TextIOWrapper_read_impl((textio *)self, n); |
841 | 8 | Py_END_CRITICAL_SECTION(); |
842 | | |
843 | 8 | exit: |
844 | 8 | return return_value; |
845 | 8 | } |
846 | | |
847 | | PyDoc_STRVAR(_io_TextIOWrapper_readline__doc__, |
848 | | "readline($self, size=-1, /)\n" |
849 | | "--\n" |
850 | | "\n"); |
851 | | |
852 | | #define _IO_TEXTIOWRAPPER_READLINE_METHODDEF \ |
853 | | {"readline", _PyCFunction_CAST(_io_TextIOWrapper_readline), METH_FASTCALL, _io_TextIOWrapper_readline__doc__}, |
854 | | |
855 | | static PyObject * |
856 | | _io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size); |
857 | | |
858 | | static PyObject * |
859 | | _io_TextIOWrapper_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
860 | 0 | { |
861 | 0 | PyObject *return_value = NULL; |
862 | 0 | Py_ssize_t size = -1; |
863 | |
|
864 | 0 | if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { |
865 | 0 | goto exit; |
866 | 0 | } |
867 | 0 | if (nargs < 1) { |
868 | 0 | goto skip_optional; |
869 | 0 | } |
870 | 0 | { |
871 | 0 | Py_ssize_t ival = -1; |
872 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
873 | 0 | if (iobj != NULL) { |
874 | 0 | ival = PyLong_AsSsize_t(iobj); |
875 | 0 | Py_DECREF(iobj); |
876 | 0 | } |
877 | 0 | if (ival == -1 && PyErr_Occurred()) { |
878 | 0 | goto exit; |
879 | 0 | } |
880 | 0 | size = ival; |
881 | 0 | } |
882 | 0 | skip_optional: |
883 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
884 | 0 | return_value = _io_TextIOWrapper_readline_impl((textio *)self, size); |
885 | 0 | Py_END_CRITICAL_SECTION(); |
886 | |
|
887 | 0 | exit: |
888 | 0 | return return_value; |
889 | 0 | } |
890 | | |
891 | | PyDoc_STRVAR(_io_TextIOWrapper_seek__doc__, |
892 | | "seek($self, cookie, whence=os.SEEK_SET, /)\n" |
893 | | "--\n" |
894 | | "\n" |
895 | | "Set the stream position, and return the new stream position.\n" |
896 | | "\n" |
897 | | " cookie\n" |
898 | | " Zero or an opaque number returned by tell().\n" |
899 | | " whence\n" |
900 | | " The relative position to seek from.\n" |
901 | | "\n" |
902 | | "Four operations are supported, given by the following argument\n" |
903 | | "combinations:\n" |
904 | | "\n" |
905 | | "- seek(0, SEEK_SET): Rewind to the start of the stream.\n" |
906 | | "- seek(cookie, SEEK_SET): Restore a previous position;\n" |
907 | | " \'cookie\' must be a number returned by tell().\n" |
908 | | "- seek(0, SEEK_END): Fast-forward to the end of the stream.\n" |
909 | | "- seek(0, SEEK_CUR): Leave the current stream position unchanged.\n" |
910 | | "\n" |
911 | | "Any other argument combinations are invalid,\n" |
912 | | "and may raise exceptions."); |
913 | | |
914 | | #define _IO_TEXTIOWRAPPER_SEEK_METHODDEF \ |
915 | | {"seek", _PyCFunction_CAST(_io_TextIOWrapper_seek), METH_FASTCALL, _io_TextIOWrapper_seek__doc__}, |
916 | | |
917 | | static PyObject * |
918 | | _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence); |
919 | | |
920 | | static PyObject * |
921 | | _io_TextIOWrapper_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
922 | 0 | { |
923 | 0 | PyObject *return_value = NULL; |
924 | 0 | PyObject *cookieObj; |
925 | 0 | int whence = 0; |
926 | |
|
927 | 0 | if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { |
928 | 0 | goto exit; |
929 | 0 | } |
930 | 0 | cookieObj = args[0]; |
931 | 0 | if (nargs < 2) { |
932 | 0 | goto skip_optional; |
933 | 0 | } |
934 | 0 | whence = PyLong_AsInt(args[1]); |
935 | 0 | if (whence == -1 && PyErr_Occurred()) { |
936 | 0 | goto exit; |
937 | 0 | } |
938 | 0 | skip_optional: |
939 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
940 | 0 | return_value = _io_TextIOWrapper_seek_impl((textio *)self, cookieObj, whence); |
941 | 0 | Py_END_CRITICAL_SECTION(); |
942 | |
|
943 | 0 | exit: |
944 | 0 | return return_value; |
945 | 0 | } |
946 | | |
947 | | PyDoc_STRVAR(_io_TextIOWrapper_tell__doc__, |
948 | | "tell($self, /)\n" |
949 | | "--\n" |
950 | | "\n" |
951 | | "Return the stream position as an opaque number.\n" |
952 | | "\n" |
953 | | "The return value of tell() can be given as input to seek(), to\n" |
954 | | "restore a previous stream position."); |
955 | | |
956 | | #define _IO_TEXTIOWRAPPER_TELL_METHODDEF \ |
957 | | {"tell", (PyCFunction)_io_TextIOWrapper_tell, METH_NOARGS, _io_TextIOWrapper_tell__doc__}, |
958 | | |
959 | | static PyObject * |
960 | | _io_TextIOWrapper_tell_impl(textio *self); |
961 | | |
962 | | static PyObject * |
963 | | _io_TextIOWrapper_tell(PyObject *self, PyObject *Py_UNUSED(ignored)) |
964 | 0 | { |
965 | 0 | PyObject *return_value = NULL; |
966 | |
|
967 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
968 | 0 | return_value = _io_TextIOWrapper_tell_impl((textio *)self); |
969 | 0 | Py_END_CRITICAL_SECTION(); |
970 | |
|
971 | 0 | return return_value; |
972 | 0 | } |
973 | | |
974 | | PyDoc_STRVAR(_io_TextIOWrapper_truncate__doc__, |
975 | | "truncate($self, pos=None, /)\n" |
976 | | "--\n" |
977 | | "\n"); |
978 | | |
979 | | #define _IO_TEXTIOWRAPPER_TRUNCATE_METHODDEF \ |
980 | | {"truncate", _PyCFunction_CAST(_io_TextIOWrapper_truncate), METH_FASTCALL, _io_TextIOWrapper_truncate__doc__}, |
981 | | |
982 | | static PyObject * |
983 | | _io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos); |
984 | | |
985 | | static PyObject * |
986 | | _io_TextIOWrapper_truncate(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
987 | 0 | { |
988 | 0 | PyObject *return_value = NULL; |
989 | 0 | PyObject *pos = Py_None; |
990 | |
|
991 | 0 | if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) { |
992 | 0 | goto exit; |
993 | 0 | } |
994 | 0 | if (nargs < 1) { |
995 | 0 | goto skip_optional; |
996 | 0 | } |
997 | 0 | pos = args[0]; |
998 | 0 | skip_optional: |
999 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1000 | 0 | return_value = _io_TextIOWrapper_truncate_impl((textio *)self, pos); |
1001 | 0 | Py_END_CRITICAL_SECTION(); |
1002 | |
|
1003 | 0 | exit: |
1004 | 0 | return return_value; |
1005 | 0 | } |
1006 | | |
1007 | | PyDoc_STRVAR(_io_TextIOWrapper_fileno__doc__, |
1008 | | "fileno($self, /)\n" |
1009 | | "--\n" |
1010 | | "\n"); |
1011 | | |
1012 | | #define _IO_TEXTIOWRAPPER_FILENO_METHODDEF \ |
1013 | | {"fileno", (PyCFunction)_io_TextIOWrapper_fileno, METH_NOARGS, _io_TextIOWrapper_fileno__doc__}, |
1014 | | |
1015 | | static PyObject * |
1016 | | _io_TextIOWrapper_fileno_impl(textio *self); |
1017 | | |
1018 | | static PyObject * |
1019 | | _io_TextIOWrapper_fileno(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1020 | 0 | { |
1021 | 0 | PyObject *return_value = NULL; |
1022 | |
|
1023 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1024 | 0 | return_value = _io_TextIOWrapper_fileno_impl((textio *)self); |
1025 | 0 | Py_END_CRITICAL_SECTION(); |
1026 | |
|
1027 | 0 | return return_value; |
1028 | 0 | } |
1029 | | |
1030 | | PyDoc_STRVAR(_io_TextIOWrapper_seekable__doc__, |
1031 | | "seekable($self, /)\n" |
1032 | | "--\n" |
1033 | | "\n"); |
1034 | | |
1035 | | #define _IO_TEXTIOWRAPPER_SEEKABLE_METHODDEF \ |
1036 | | {"seekable", (PyCFunction)_io_TextIOWrapper_seekable, METH_NOARGS, _io_TextIOWrapper_seekable__doc__}, |
1037 | | |
1038 | | static PyObject * |
1039 | | _io_TextIOWrapper_seekable_impl(textio *self); |
1040 | | |
1041 | | static PyObject * |
1042 | | _io_TextIOWrapper_seekable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1043 | 0 | { |
1044 | 0 | PyObject *return_value = NULL; |
1045 | |
|
1046 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1047 | 0 | return_value = _io_TextIOWrapper_seekable_impl((textio *)self); |
1048 | 0 | Py_END_CRITICAL_SECTION(); |
1049 | |
|
1050 | 0 | return return_value; |
1051 | 0 | } |
1052 | | |
1053 | | PyDoc_STRVAR(_io_TextIOWrapper_readable__doc__, |
1054 | | "readable($self, /)\n" |
1055 | | "--\n" |
1056 | | "\n"); |
1057 | | |
1058 | | #define _IO_TEXTIOWRAPPER_READABLE_METHODDEF \ |
1059 | | {"readable", (PyCFunction)_io_TextIOWrapper_readable, METH_NOARGS, _io_TextIOWrapper_readable__doc__}, |
1060 | | |
1061 | | static PyObject * |
1062 | | _io_TextIOWrapper_readable_impl(textio *self); |
1063 | | |
1064 | | static PyObject * |
1065 | | _io_TextIOWrapper_readable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1066 | 0 | { |
1067 | 0 | PyObject *return_value = NULL; |
1068 | |
|
1069 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1070 | 0 | return_value = _io_TextIOWrapper_readable_impl((textio *)self); |
1071 | 0 | Py_END_CRITICAL_SECTION(); |
1072 | |
|
1073 | 0 | return return_value; |
1074 | 0 | } |
1075 | | |
1076 | | PyDoc_STRVAR(_io_TextIOWrapper_writable__doc__, |
1077 | | "writable($self, /)\n" |
1078 | | "--\n" |
1079 | | "\n"); |
1080 | | |
1081 | | #define _IO_TEXTIOWRAPPER_WRITABLE_METHODDEF \ |
1082 | | {"writable", (PyCFunction)_io_TextIOWrapper_writable, METH_NOARGS, _io_TextIOWrapper_writable__doc__}, |
1083 | | |
1084 | | static PyObject * |
1085 | | _io_TextIOWrapper_writable_impl(textio *self); |
1086 | | |
1087 | | static PyObject * |
1088 | | _io_TextIOWrapper_writable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1089 | 0 | { |
1090 | 0 | PyObject *return_value = NULL; |
1091 | |
|
1092 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1093 | 0 | return_value = _io_TextIOWrapper_writable_impl((textio *)self); |
1094 | 0 | Py_END_CRITICAL_SECTION(); |
1095 | |
|
1096 | 0 | return return_value; |
1097 | 0 | } |
1098 | | |
1099 | | PyDoc_STRVAR(_io_TextIOWrapper_isatty__doc__, |
1100 | | "isatty($self, /)\n" |
1101 | | "--\n" |
1102 | | "\n"); |
1103 | | |
1104 | | #define _IO_TEXTIOWRAPPER_ISATTY_METHODDEF \ |
1105 | | {"isatty", (PyCFunction)_io_TextIOWrapper_isatty, METH_NOARGS, _io_TextIOWrapper_isatty__doc__}, |
1106 | | |
1107 | | static PyObject * |
1108 | | _io_TextIOWrapper_isatty_impl(textio *self); |
1109 | | |
1110 | | static PyObject * |
1111 | | _io_TextIOWrapper_isatty(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1112 | 0 | { |
1113 | 0 | PyObject *return_value = NULL; |
1114 | |
|
1115 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1116 | 0 | return_value = _io_TextIOWrapper_isatty_impl((textio *)self); |
1117 | 0 | Py_END_CRITICAL_SECTION(); |
1118 | |
|
1119 | 0 | return return_value; |
1120 | 0 | } |
1121 | | |
1122 | | PyDoc_STRVAR(_io_TextIOWrapper_flush__doc__, |
1123 | | "flush($self, /)\n" |
1124 | | "--\n" |
1125 | | "\n"); |
1126 | | |
1127 | | #define _IO_TEXTIOWRAPPER_FLUSH_METHODDEF \ |
1128 | | {"flush", (PyCFunction)_io_TextIOWrapper_flush, METH_NOARGS, _io_TextIOWrapper_flush__doc__}, |
1129 | | |
1130 | | static PyObject * |
1131 | | _io_TextIOWrapper_flush_impl(textio *self); |
1132 | | |
1133 | | static PyObject * |
1134 | | _io_TextIOWrapper_flush(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1135 | 19 | { |
1136 | 19 | PyObject *return_value = NULL; |
1137 | | |
1138 | 19 | Py_BEGIN_CRITICAL_SECTION(self); |
1139 | 19 | return_value = _io_TextIOWrapper_flush_impl((textio *)self); |
1140 | 19 | Py_END_CRITICAL_SECTION(); |
1141 | | |
1142 | 19 | return return_value; |
1143 | 19 | } |
1144 | | |
1145 | | PyDoc_STRVAR(_io_TextIOWrapper_close__doc__, |
1146 | | "close($self, /)\n" |
1147 | | "--\n" |
1148 | | "\n"); |
1149 | | |
1150 | | #define _IO_TEXTIOWRAPPER_CLOSE_METHODDEF \ |
1151 | | {"close", (PyCFunction)_io_TextIOWrapper_close, METH_NOARGS, _io_TextIOWrapper_close__doc__}, |
1152 | | |
1153 | | static PyObject * |
1154 | | _io_TextIOWrapper_close_impl(textio *self); |
1155 | | |
1156 | | static PyObject * |
1157 | | _io_TextIOWrapper_close(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1158 | 19 | { |
1159 | 19 | PyObject *return_value = NULL; |
1160 | | |
1161 | 19 | Py_BEGIN_CRITICAL_SECTION(self); |
1162 | 19 | return_value = _io_TextIOWrapper_close_impl((textio *)self); |
1163 | 19 | Py_END_CRITICAL_SECTION(); |
1164 | | |
1165 | 19 | return return_value; |
1166 | 19 | } |
1167 | | |
1168 | | static PyObject * |
1169 | | textiowrapper_iternext_impl(textio *self); |
1170 | | |
1171 | | static PyObject * |
1172 | | textiowrapper_iternext(PyObject *self) |
1173 | 23.6k | { |
1174 | 23.6k | PyObject *return_value = NULL; |
1175 | | |
1176 | 23.6k | Py_BEGIN_CRITICAL_SECTION(self); |
1177 | 23.6k | return_value = textiowrapper_iternext_impl((textio *)self); |
1178 | 23.6k | Py_END_CRITICAL_SECTION(); |
1179 | | |
1180 | 23.6k | return return_value; |
1181 | 23.6k | } |
1182 | | |
1183 | | static PyObject * |
1184 | | _io_TextIOWrapper_name_get_impl(textio *self); |
1185 | | |
1186 | | static PyObject * |
1187 | | _io_TextIOWrapper_name_get(PyObject *self, void *Py_UNUSED(context)) |
1188 | 0 | { |
1189 | 0 | PyObject *return_value = NULL; |
1190 | |
|
1191 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1192 | 0 | return_value = _io_TextIOWrapper_name_get_impl((textio *)self); |
1193 | 0 | Py_END_CRITICAL_SECTION(); |
1194 | |
|
1195 | 0 | return return_value; |
1196 | 0 | } |
1197 | | |
1198 | | static PyObject * |
1199 | | _io_TextIOWrapper_closed_get_impl(textio *self); |
1200 | | |
1201 | | static PyObject * |
1202 | | _io_TextIOWrapper_closed_get(PyObject *self, void *Py_UNUSED(context)) |
1203 | 48 | { |
1204 | 48 | PyObject *return_value = NULL; |
1205 | | |
1206 | 48 | Py_BEGIN_CRITICAL_SECTION(self); |
1207 | 48 | return_value = _io_TextIOWrapper_closed_get_impl((textio *)self); |
1208 | 48 | Py_END_CRITICAL_SECTION(); |
1209 | | |
1210 | 48 | return return_value; |
1211 | 48 | } |
1212 | | |
1213 | | static PyObject * |
1214 | | _io_TextIOWrapper_newlines_get_impl(textio *self); |
1215 | | |
1216 | | static PyObject * |
1217 | | _io_TextIOWrapper_newlines_get(PyObject *self, void *Py_UNUSED(context)) |
1218 | 0 | { |
1219 | 0 | PyObject *return_value = NULL; |
1220 | |
|
1221 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1222 | 0 | return_value = _io_TextIOWrapper_newlines_get_impl((textio *)self); |
1223 | 0 | Py_END_CRITICAL_SECTION(); |
1224 | |
|
1225 | 0 | return return_value; |
1226 | 0 | } |
1227 | | |
1228 | | static PyObject * |
1229 | | _io_TextIOWrapper_errors_get_impl(textio *self); |
1230 | | |
1231 | | static PyObject * |
1232 | | _io_TextIOWrapper_errors_get(PyObject *self, void *Py_UNUSED(context)) |
1233 | 0 | { |
1234 | 0 | PyObject *return_value = NULL; |
1235 | |
|
1236 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1237 | 0 | return_value = _io_TextIOWrapper_errors_get_impl((textio *)self); |
1238 | 0 | Py_END_CRITICAL_SECTION(); |
1239 | |
|
1240 | 0 | return return_value; |
1241 | 0 | } |
1242 | | |
1243 | | static Py_ssize_t |
1244 | | _io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self); |
1245 | | |
1246 | | static PyObject * |
1247 | | _io_TextIOWrapper__CHUNK_SIZE_get(PyObject *self, void *Py_UNUSED(context)) |
1248 | 0 | { |
1249 | 0 | PyObject *return_value = NULL; |
1250 | 0 | Py_ssize_t _return_value; |
1251 | |
|
1252 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1253 | 0 | _return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl((textio *)self); |
1254 | 0 | Py_END_CRITICAL_SECTION(); |
1255 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
1256 | 0 | goto exit; |
1257 | 0 | } |
1258 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
1259 | |
|
1260 | 0 | exit: |
1261 | 0 | return return_value; |
1262 | 0 | } |
1263 | | |
1264 | | static int |
1265 | | _io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, Py_ssize_t value); |
1266 | | |
1267 | | static int |
1268 | | _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) |
1269 | 0 | { |
1270 | 0 | int return_value = -1; |
1271 | 0 | Py_ssize_t value; |
1272 | |
|
1273 | 0 | if (arg == NULL) { |
1274 | 0 | PyErr_Format(PyExc_AttributeError, |
1275 | 0 | "attribute '_CHUNK_SIZE' of '%.100s' objects cannot be deleted", |
1276 | 0 | Py_TYPE(self)->tp_name); |
1277 | 0 | return -1; |
1278 | 0 | } |
1279 | 0 | { |
1280 | 0 | Py_ssize_t ival = -1; |
1281 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
1282 | 0 | if (iobj != NULL) { |
1283 | 0 | ival = PyLong_AsSsize_t(iobj); |
1284 | 0 | Py_DECREF(iobj); |
1285 | 0 | } |
1286 | 0 | if (ival == -1 && PyErr_Occurred()) { |
1287 | 0 | goto exit; |
1288 | 0 | } |
1289 | 0 | value = ival; |
1290 | 0 | } |
1291 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1292 | 0 | return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl((textio *)self, value); |
1293 | 0 | Py_END_CRITICAL_SECTION(); |
1294 | |
|
1295 | 0 | exit: |
1296 | 0 | return return_value; |
1297 | 0 | } |
1298 | | |
1299 | | static PyObject * |
1300 | | _io_TextIOWrapper_buffer_get_impl(textio *self); |
1301 | | |
1302 | | static PyObject * |
1303 | | _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) |
1304 | 0 | { |
1305 | 0 | PyObject *return_value = NULL; |
1306 | |
|
1307 | 0 | Py_BEGIN_CRITICAL_SECTION(self); |
1308 | 0 | return_value = _io_TextIOWrapper_buffer_get_impl((textio *)self); |
1309 | 0 | Py_END_CRITICAL_SECTION(); |
1310 | |
|
1311 | 0 | return return_value; |
1312 | 0 | } |
1313 | | #define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)NULL, _io__TextIOBase_encoding__doc__}, |
1314 | | |
1315 | | #define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)NULL, _io__TextIOBase_newlines__doc__}, |
1316 | | |
1317 | | #define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)NULL, _io__TextIOBase_errors__doc__}, |
1318 | | |
1319 | | #define _IO_INCREMENTALNEWLINEDECODER_NEWLINES_GETSETDEF {"newlines", (getter)_io_IncrementalNewlineDecoder_newlines_get, (setter)NULL, NULL}, |
1320 | | |
1321 | | #define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)NULL, NULL}, |
1322 | | |
1323 | | #define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)NULL, NULL}, |
1324 | | |
1325 | | #define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)NULL, NULL}, |
1326 | | |
1327 | | #define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)NULL, NULL}, |
1328 | | |
1329 | | #define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, |
1330 | | |
1331 | | #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, |
1332 | | |
1333 | | /*[clinic end generated code: output=d96cd0f7c06f36f5 input=a9049054013a1b77]*/ |