blob: 1b7cb0ff702793487f7f4b52cce6b2be7f057dcb [file] [log] [blame]
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +00001/*
2 An implementation of the I/O abstract base classes hierarchy
3 as defined by PEP 3116 - "New I/O"
Victor Stinnercc024d12013-10-29 02:23:46 +01004
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +00005 Classes defined here: IOBase, RawIOBase.
Victor Stinnercc024d12013-10-29 02:23:46 +01006
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +00007 Written by Amaury Forgeot d'Arc and Antoine Pitrou
8*/
9
10
11#define PY_SSIZE_T_CLEAN
12#include "Python.h"
13#include "structmember.h"
14#include "_iomodule.h"
15
16/*
17 * IOBase class, an abstract class
18 */
19
20typedef struct {
21 PyObject_HEAD
Victor Stinnercc024d12013-10-29 02:23:46 +010022
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000023 PyObject *dict;
24 PyObject *weakreflist;
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000025} iobase;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000026
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000027PyDoc_STRVAR(iobase_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000028 "The abstract base class for all I/O classes, acting on streams of\n"
29 "bytes. There is no public constructor.\n"
30 "\n"
31 "This class provides dummy implementations for many methods that\n"
32 "derived classes can override selectively; the default implementations\n"
33 "represent a file that cannot be read, written or seeked.\n"
34 "\n"
35 "Even though IOBase does not declare read, readinto, or write because\n"
36 "their signatures will vary, implementations and clients should\n"
37 "consider those methods part of the interface. Also, implementations\n"
Amaury Forgeot d'Arc616453c2010-09-06 22:31:52 +000038 "may raise UnsupportedOperation when operations they do not support are\n"
39 "called.\n"
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000040 "\n"
41 "The basic type used for binary data read from or written to a file is\n"
42 "bytes. bytearrays are accepted too, and in some cases (such as\n"
43 "readinto) needed. Text I/O classes work with str data.\n"
44 "\n"
45 "Note that calling any method (even inquiries) on a closed stream is\n"
46 "undefined. Implementations may raise IOError in this case.\n"
47 "\n"
48 "IOBase (and its subclasses) support the iterator protocol, meaning\n"
49 "that an IOBase object can be iterated over yielding the lines in a\n"
50 "stream.\n"
51 "\n"
52 "IOBase also supports the :keyword:`with` statement. In this example,\n"
Ezio Melotti13925002011-03-16 11:05:33 +020053 "fp is closed after the suite of the with statement is complete:\n"
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000054 "\n"
55 "with open('spam.txt', 'r') as fp:\n"
56 " fp.write('Spam and eggs!')\n");
57
58/* Use this macro whenever you want to check the internal `closed` status
59 of the IOBase object rather than the virtual `closed` attribute as returned
60 by whatever subclass. */
61
Martin v. Löwis767046a2011-10-14 15:35:36 +020062_Py_IDENTIFIER(__IOBase_closed);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000063#define IS_CLOSED(self) \
Martin v. Löwis767046a2011-10-14 15:35:36 +020064 _PyObject_HasAttrId(self, &PyId___IOBase_closed)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000065
Victor Stinner3f36a572013-11-12 21:39:02 +010066_Py_IDENTIFIER(read);
67
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000068/* Internal methods */
69static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000070iobase_unsupported(const char *message)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000071{
72 PyErr_SetString(IO_STATE->unsupported_operation, message);
73 return NULL;
74}
75
76/* Positionning */
77
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000078PyDoc_STRVAR(iobase_seek_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000079 "Change stream position.\n"
80 "\n"
Terry Jan Reedy0158af32013-03-11 17:42:46 -040081 "Change the stream position to the given byte offset. The offset is\n"
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000082 "interpreted relative to the position indicated by whence. Values\n"
83 "for whence are:\n"
84 "\n"
85 "* 0 -- start of stream (the default); offset should be zero or positive\n"
86 "* 1 -- current stream position; offset may be negative\n"
87 "* 2 -- end of stream; offset is usually negative\n"
88 "\n"
89 "Return the new absolute position.");
90
91static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000092iobase_seek(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000093{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000094 return iobase_unsupported("seek");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000095}
96
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000097PyDoc_STRVAR(iobase_tell_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000098 "Return current stream position.");
99
100static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000101iobase_tell(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000102{
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200103 _Py_IDENTIFIER(seek);
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200104
105 return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000106}
107
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000108PyDoc_STRVAR(iobase_truncate_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000109 "Truncate file to size bytes.\n"
110 "\n"
Antoine Pitrou905a2ff2010-01-31 22:47:27 +0000111 "File pointer is left unchanged. Size defaults to the current IO\n"
112 "position as reported by tell(). Returns the new size.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000113
114static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000115iobase_truncate(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000116{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000117 return iobase_unsupported("truncate");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000118}
119
120/* Flush and close methods */
121
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000122PyDoc_STRVAR(iobase_flush_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000123 "Flush write buffers, if applicable.\n"
124 "\n"
125 "This is not implemented for read-only and non-blocking streams.\n");
126
127static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000128iobase_flush(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000129{
130 /* XXX Should this return the number of bytes written??? */
131 if (IS_CLOSED(self)) {
132 PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
133 return NULL;
134 }
135 Py_RETURN_NONE;
136}
137
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000138PyDoc_STRVAR(iobase_close_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000139 "Flush and close the IO object.\n"
140 "\n"
141 "This method has no effect if the file is already closed.\n");
142
143static int
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000144iobase_closed(PyObject *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000145{
146 PyObject *res;
147 int closed;
148 /* This gets the derived attribute, which is *not* __IOBase_closed
149 in most cases! */
150 res = PyObject_GetAttr(self, _PyIO_str_closed);
151 if (res == NULL)
152 return 0;
153 closed = PyObject_IsTrue(res);
154 Py_DECREF(res);
155 return closed;
156}
157
158static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000159iobase_closed_get(PyObject *self, void *context)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000160{
161 return PyBool_FromLong(IS_CLOSED(self));
162}
163
164PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000165_PyIOBase_check_closed(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000166{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000167 if (iobase_closed(self)) {
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000168 PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
169 return NULL;
170 }
171 if (args == Py_True)
172 return Py_None;
173 else
174 Py_RETURN_NONE;
175}
176
177/* XXX: IOBase thinks it has to maintain its own internal state in
178 `__IOBase_closed` and call flush() by itself, but it is redundant with
179 whatever behaviour a non-trivial derived class will implement. */
180
181static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000182iobase_close(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000183{
184 PyObject *res;
185
186 if (IS_CLOSED(self))
187 Py_RETURN_NONE;
188
189 res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
Victor Stinneraa5bbfa2013-11-08 00:29:41 +0100190
191 if (_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True) < 0) {
192 Py_XDECREF(res);
Antoine Pitrou6be88762010-05-03 16:48:20 +0000193 return NULL;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000194 }
Victor Stinneraa5bbfa2013-11-08 00:29:41 +0100195
196 if (res == NULL)
197 return NULL;
198
199 Py_DECREF(res);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000200 Py_RETURN_NONE;
201}
202
203/* Finalization and garbage collection support */
204
Antoine Pitrou796564c2013-07-30 19:59:21 +0200205static void
206iobase_finalize(PyObject *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000207{
208 PyObject *res;
Antoine Pitrou796564c2013-07-30 19:59:21 +0200209 PyObject *error_type, *error_value, *error_traceback;
210 int closed;
211 _Py_IDENTIFIER(_finalizing);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000212
Antoine Pitrou796564c2013-07-30 19:59:21 +0200213 /* Save the current exception, if any. */
214 PyErr_Fetch(&error_type, &error_value, &error_traceback);
215
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000216 /* If `closed` doesn't exist or can't be evaluated as bool, then the
217 object is probably in an unusable state, so ignore. */
218 res = PyObject_GetAttr(self, _PyIO_str_closed);
Christian Heimes72f455e2013-07-31 01:33:50 +0200219 if (res == NULL) {
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000220 PyErr_Clear();
Christian Heimes72f455e2013-07-31 01:33:50 +0200221 closed = -1;
222 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000223 else {
224 closed = PyObject_IsTrue(res);
225 Py_DECREF(res);
226 if (closed == -1)
227 PyErr_Clear();
228 }
229 if (closed == 0) {
Antoine Pitrou796564c2013-07-30 19:59:21 +0200230 /* Signal close() that it was called as part of the object
231 finalization process. */
232 if (_PyObject_SetAttrId(self, &PyId__finalizing, Py_True))
233 PyErr_Clear();
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000234 res = PyObject_CallMethodObjArgs((PyObject *) self, _PyIO_str_close,
235 NULL);
236 /* Silencing I/O errors is bad, but printing spurious tracebacks is
237 equally as bad, and potentially more frequent (because of
238 shutdown issues). */
239 if (res == NULL)
240 PyErr_Clear();
241 else
242 Py_DECREF(res);
243 }
Antoine Pitrou796564c2013-07-30 19:59:21 +0200244
245 /* Restore the saved exception. */
246 PyErr_Restore(error_type, error_value, error_traceback);
247}
248
249int
250_PyIOBase_finalize(PyObject *self)
251{
252 int is_zombie;
253
254 /* If _PyIOBase_finalize() is called from a destructor, we need to
255 resurrect the object as calling close() can invoke arbitrary code. */
256 is_zombie = (Py_REFCNT(self) == 0);
257 if (is_zombie)
258 return PyObject_CallFinalizerFromDealloc(self);
259 else {
260 PyObject_CallFinalizer(self);
261 return 0;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000262 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000263}
264
265static int
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000266iobase_traverse(iobase *self, visitproc visit, void *arg)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000267{
268 Py_VISIT(self->dict);
269 return 0;
270}
271
272static int
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000273iobase_clear(iobase *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000274{
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000275 Py_CLEAR(self->dict);
276 return 0;
277}
278
279/* Destructor */
280
281static void
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000282iobase_dealloc(iobase *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000283{
284 /* NOTE: since IOBaseObject has its own dict, Python-defined attributes
285 are still available here for close() to use.
286 However, if the derived class declares a __slots__, those slots are
287 already gone.
288 */
289 if (_PyIOBase_finalize((PyObject *) self) < 0) {
290 /* When called from a heap type's dealloc, the type will be
291 decref'ed on return (see e.g. subtype_dealloc in typeobject.c). */
292 if (PyType_HasFeature(Py_TYPE(self), Py_TPFLAGS_HEAPTYPE))
293 Py_INCREF(Py_TYPE(self));
294 return;
295 }
296 _PyObject_GC_UNTRACK(self);
297 if (self->weakreflist != NULL)
298 PyObject_ClearWeakRefs((PyObject *) self);
299 Py_CLEAR(self->dict);
300 Py_TYPE(self)->tp_free((PyObject *) self);
301}
302
303/* Inquiry methods */
304
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000305PyDoc_STRVAR(iobase_seekable_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000306 "Return whether object supports random access.\n"
307 "\n"
Amaury Forgeot d'Arc616453c2010-09-06 22:31:52 +0000308 "If False, seek(), tell() and truncate() will raise UnsupportedOperation.\n"
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000309 "This method may need to do a test seek().");
310
311static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000312iobase_seekable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000313{
314 Py_RETURN_FALSE;
315}
316
317PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000318_PyIOBase_check_seekable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000319{
320 PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL);
321 if (res == NULL)
322 return NULL;
323 if (res != Py_True) {
324 Py_CLEAR(res);
Antoine Pitrou0d739d72010-09-05 23:01:12 +0000325 iobase_unsupported("File or stream is not seekable.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000326 return NULL;
327 }
328 if (args == Py_True) {
329 Py_DECREF(res);
330 }
331 return res;
332}
333
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000334PyDoc_STRVAR(iobase_readable_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000335 "Return whether object was opened for reading.\n"
336 "\n"
Amaury Forgeot d'Arc616453c2010-09-06 22:31:52 +0000337 "If False, read() will raise UnsupportedOperation.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000338
339static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000340iobase_readable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000341{
342 Py_RETURN_FALSE;
343}
344
345/* May be called with any object */
346PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000347_PyIOBase_check_readable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000348{
349 PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL);
350 if (res == NULL)
351 return NULL;
352 if (res != Py_True) {
353 Py_CLEAR(res);
Antoine Pitrou0d739d72010-09-05 23:01:12 +0000354 iobase_unsupported("File or stream is not readable.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000355 return NULL;
356 }
357 if (args == Py_True) {
358 Py_DECREF(res);
359 }
360 return res;
361}
362
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000363PyDoc_STRVAR(iobase_writable_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000364 "Return whether object was opened for writing.\n"
365 "\n"
Amaury Forgeot d'Arc616453c2010-09-06 22:31:52 +0000366 "If False, write() will raise UnsupportedOperation.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000367
368static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000369iobase_writable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000370{
371 Py_RETURN_FALSE;
372}
373
374/* May be called with any object */
375PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000376_PyIOBase_check_writable(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000377{
378 PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL);
379 if (res == NULL)
380 return NULL;
381 if (res != Py_True) {
382 Py_CLEAR(res);
Antoine Pitrou0d739d72010-09-05 23:01:12 +0000383 iobase_unsupported("File or stream is not writable.");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000384 return NULL;
385 }
386 if (args == Py_True) {
387 Py_DECREF(res);
388 }
389 return res;
390}
391
392/* Context manager */
393
394static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000395iobase_enter(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000396{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000397 if (_PyIOBase_check_closed(self, Py_True) == NULL)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000398 return NULL;
399
400 Py_INCREF(self);
401 return self;
402}
403
404static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000405iobase_exit(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000406{
407 return PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL);
408}
409
410/* Lower-level APIs */
411
412/* XXX Should these be present even if unimplemented? */
413
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000414PyDoc_STRVAR(iobase_fileno_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000415 "Returns underlying file descriptor if one exists.\n"
416 "\n"
417 "An IOError is raised if the IO object does not use a file descriptor.\n");
418
419static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000420iobase_fileno(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000421{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000422 return iobase_unsupported("fileno");
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000423}
424
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000425PyDoc_STRVAR(iobase_isatty_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000426 "Return whether this is an 'interactive' stream.\n"
427 "\n"
428 "Return False if it can't be determined.\n");
429
430static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000431iobase_isatty(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000432{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000433 if (_PyIOBase_check_closed(self, Py_True) == NULL)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000434 return NULL;
435 Py_RETURN_FALSE;
436}
437
438/* Readline(s) and writelines */
439
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000440PyDoc_STRVAR(iobase_readline_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000441 "Read and return a line from the stream.\n"
442 "\n"
443 "If limit is specified, at most limit bytes will be read.\n"
444 "\n"
Ezio Melotti16d2b472012-09-18 07:20:18 +0300445 "The line terminator is always b'\\n' for binary files; for text\n"
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000446 "files, the newlines argument to open can be used to select the line\n"
447 "terminator(s) recognized.\n");
448
449static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000450iobase_readline(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000451{
452 /* For backwards compatibility, a (slowish) readline(). */
453
454 Py_ssize_t limit = -1;
455 int has_peek = 0;
456 PyObject *buffer, *result;
457 Py_ssize_t old_size = -1;
Martin v. Löwis767046a2011-10-14 15:35:36 +0200458 _Py_IDENTIFIER(peek);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000459
Benjamin Petersonbf5ff762009-12-13 19:25:34 +0000460 if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) {
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000461 return NULL;
462 }
463
Martin v. Löwis767046a2011-10-14 15:35:36 +0200464 if (_PyObject_HasAttrId(self, &PyId_peek))
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000465 has_peek = 1;
466
467 buffer = PyByteArray_FromStringAndSize(NULL, 0);
468 if (buffer == NULL)
469 return NULL;
470
471 while (limit < 0 || Py_SIZE(buffer) < limit) {
472 Py_ssize_t nreadahead = 1;
473 PyObject *b;
474
475 if (has_peek) {
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200476 PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1);
Gregory P. Smith51359922012-06-23 23:55:39 -0700477 if (readahead == NULL) {
478 /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
479 when EINTR occurs so we needn't do it ourselves. */
480 if (_PyIO_trap_eintr()) {
481 continue;
482 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000483 goto fail;
Gregory P. Smith51359922012-06-23 23:55:39 -0700484 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000485 if (!PyBytes_Check(readahead)) {
486 PyErr_Format(PyExc_IOError,
487 "peek() should have returned a bytes object, "
488 "not '%.200s'", Py_TYPE(readahead)->tp_name);
489 Py_DECREF(readahead);
490 goto fail;
491 }
492 if (PyBytes_GET_SIZE(readahead) > 0) {
493 Py_ssize_t n = 0;
494 const char *buf = PyBytes_AS_STRING(readahead);
495 if (limit >= 0) {
496 do {
497 if (n >= PyBytes_GET_SIZE(readahead) || n >= limit)
498 break;
499 if (buf[n++] == '\n')
500 break;
501 } while (1);
502 }
503 else {
504 do {
505 if (n >= PyBytes_GET_SIZE(readahead))
506 break;
507 if (buf[n++] == '\n')
508 break;
509 } while (1);
510 }
511 nreadahead = n;
512 }
513 Py_DECREF(readahead);
514 }
515
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200516 b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead);
Gregory P. Smith51359922012-06-23 23:55:39 -0700517 if (b == NULL) {
518 /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
519 when EINTR occurs so we needn't do it ourselves. */
520 if (_PyIO_trap_eintr()) {
521 continue;
522 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000523 goto fail;
Gregory P. Smith51359922012-06-23 23:55:39 -0700524 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000525 if (!PyBytes_Check(b)) {
526 PyErr_Format(PyExc_IOError,
527 "read() should have returned a bytes object, "
528 "not '%.200s'", Py_TYPE(b)->tp_name);
529 Py_DECREF(b);
530 goto fail;
531 }
532 if (PyBytes_GET_SIZE(b) == 0) {
533 Py_DECREF(b);
534 break;
535 }
536
537 old_size = PyByteArray_GET_SIZE(buffer);
Victor Stinnercc024d12013-10-29 02:23:46 +0100538 if (PyByteArray_Resize(buffer, old_size + PyBytes_GET_SIZE(b)) < 0) {
539 Py_DECREF(b);
540 goto fail;
541 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000542 memcpy(PyByteArray_AS_STRING(buffer) + old_size,
543 PyBytes_AS_STRING(b), PyBytes_GET_SIZE(b));
544
545 Py_DECREF(b);
546
547 if (PyByteArray_AS_STRING(buffer)[PyByteArray_GET_SIZE(buffer) - 1] == '\n')
548 break;
549 }
550
551 result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(buffer),
552 PyByteArray_GET_SIZE(buffer));
553 Py_DECREF(buffer);
554 return result;
555 fail:
556 Py_DECREF(buffer);
557 return NULL;
558}
559
560static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000561iobase_iter(PyObject *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000562{
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000563 if (_PyIOBase_check_closed(self, Py_True) == NULL)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000564 return NULL;
565
566 Py_INCREF(self);
567 return self;
568}
569
570static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000571iobase_iternext(PyObject *self)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000572{
573 PyObject *line = PyObject_CallMethodObjArgs(self, _PyIO_str_readline, NULL);
574
575 if (line == NULL)
576 return NULL;
577
578 if (PyObject_Size(line) == 0) {
579 Py_DECREF(line);
580 return NULL;
581 }
582
583 return line;
584}
585
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000586PyDoc_STRVAR(iobase_readlines_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000587 "Return a list of lines from the stream.\n"
588 "\n"
589 "hint can be specified to control the number of lines read: no more\n"
590 "lines will be read if the total size (in bytes/characters) of all\n"
591 "lines so far exceeds hint.");
592
593static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000594iobase_readlines(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000595{
596 Py_ssize_t hint = -1, length = 0;
Benjamin Peterson05516132009-12-13 19:28:09 +0000597 PyObject *result;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000598
Benjamin Petersonbf5ff762009-12-13 19:25:34 +0000599 if (!PyArg_ParseTuple(args, "|O&:readlines", &_PyIO_ConvertSsize_t, &hint)) {
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000600 return NULL;
601 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000602
603 result = PyList_New(0);
604 if (result == NULL)
605 return NULL;
606
607 if (hint <= 0) {
608 /* XXX special-casing this made sense in the Python version in order
609 to remove the bytecode interpretation overhead, but it could
610 probably be removed here. */
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200611 _Py_IDENTIFIER(extend);
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200612 PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
613
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000614 if (ret == NULL) {
615 Py_DECREF(result);
616 return NULL;
617 }
618 Py_DECREF(ret);
619 return result;
620 }
621
622 while (1) {
623 PyObject *line = PyIter_Next(self);
624 if (line == NULL) {
625 if (PyErr_Occurred()) {
626 Py_DECREF(result);
627 return NULL;
628 }
629 else
630 break; /* StopIteration raised */
631 }
632
633 if (PyList_Append(result, line) < 0) {
634 Py_DECREF(line);
635 Py_DECREF(result);
636 return NULL;
637 }
638 length += PyObject_Size(line);
639 Py_DECREF(line);
640
641 if (length > hint)
642 break;
643 }
644 return result;
645}
646
647static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000648iobase_writelines(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000649{
650 PyObject *lines, *iter, *res;
651
652 if (!PyArg_ParseTuple(args, "O:writelines", &lines)) {
653 return NULL;
654 }
655
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000656 if (_PyIOBase_check_closed(self, Py_True) == NULL)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000657 return NULL;
658
659 iter = PyObject_GetIter(lines);
660 if (iter == NULL)
661 return NULL;
662
663 while (1) {
664 PyObject *line = PyIter_Next(iter);
665 if (line == NULL) {
666 if (PyErr_Occurred()) {
667 Py_DECREF(iter);
668 return NULL;
669 }
670 else
671 break; /* Stop Iteration */
672 }
673
Gregory P. Smithb9817b02013-02-01 13:03:39 -0800674 res = NULL;
675 do {
676 res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL);
677 } while (res == NULL && _PyIO_trap_eintr());
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000678 Py_DECREF(line);
679 if (res == NULL) {
680 Py_DECREF(iter);
681 return NULL;
682 }
683 Py_DECREF(res);
684 }
685 Py_DECREF(iter);
686 Py_RETURN_NONE;
687}
688
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000689static PyMethodDef iobase_methods[] = {
690 {"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
691 {"tell", iobase_tell, METH_NOARGS, iobase_tell_doc},
692 {"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
693 {"flush", iobase_flush, METH_NOARGS, iobase_flush_doc},
694 {"close", iobase_close, METH_NOARGS, iobase_close_doc},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000695
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000696 {"seekable", iobase_seekable, METH_NOARGS, iobase_seekable_doc},
697 {"readable", iobase_readable, METH_NOARGS, iobase_readable_doc},
698 {"writable", iobase_writable, METH_NOARGS, iobase_writable_doc},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000699
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000700 {"_checkClosed", _PyIOBase_check_closed, METH_NOARGS},
701 {"_checkSeekable", _PyIOBase_check_seekable, METH_NOARGS},
702 {"_checkReadable", _PyIOBase_check_readable, METH_NOARGS},
703 {"_checkWritable", _PyIOBase_check_writable, METH_NOARGS},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000704
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000705 {"fileno", iobase_fileno, METH_NOARGS, iobase_fileno_doc},
706 {"isatty", iobase_isatty, METH_NOARGS, iobase_isatty_doc},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000707
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000708 {"__enter__", iobase_enter, METH_NOARGS},
709 {"__exit__", iobase_exit, METH_VARARGS},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000710
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000711 {"readline", iobase_readline, METH_VARARGS, iobase_readline_doc},
712 {"readlines", iobase_readlines, METH_VARARGS, iobase_readlines_doc},
713 {"writelines", iobase_writelines, METH_VARARGS},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000714
715 {NULL, NULL}
716};
717
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000718static PyGetSetDef iobase_getset[] = {
Benjamin Peterson23d7f122012-02-19 20:02:57 -0500719 {"__dict__", PyObject_GenericGetDict, NULL, NULL},
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000720 {"closed", (getter)iobase_closed_get, NULL, NULL},
Benjamin Peterson1fea3212009-04-19 03:15:20 +0000721 {NULL}
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000722};
723
724
725PyTypeObject PyIOBase_Type = {
726 PyVarObject_HEAD_INIT(NULL, 0)
727 "_io._IOBase", /*tp_name*/
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000728 sizeof(iobase), /*tp_basicsize*/
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000729 0, /*tp_itemsize*/
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000730 (destructor)iobase_dealloc, /*tp_dealloc*/
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000731 0, /*tp_print*/
732 0, /*tp_getattr*/
733 0, /*tp_setattr*/
734 0, /*tp_compare */
735 0, /*tp_repr*/
736 0, /*tp_as_number*/
737 0, /*tp_as_sequence*/
738 0, /*tp_as_mapping*/
739 0, /*tp_hash */
740 0, /*tp_call*/
741 0, /*tp_str*/
742 0, /*tp_getattro*/
743 0, /*tp_setattro*/
744 0, /*tp_as_buffer*/
745 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
Antoine Pitrou796564c2013-07-30 19:59:21 +0200746 | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000747 iobase_doc, /* tp_doc */
748 (traverseproc)iobase_traverse, /* tp_traverse */
749 (inquiry)iobase_clear, /* tp_clear */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000750 0, /* tp_richcompare */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000751 offsetof(iobase, weakreflist), /* tp_weaklistoffset */
752 iobase_iter, /* tp_iter */
753 iobase_iternext, /* tp_iternext */
754 iobase_methods, /* tp_methods */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000755 0, /* tp_members */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000756 iobase_getset, /* tp_getset */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000757 0, /* tp_base */
758 0, /* tp_dict */
759 0, /* tp_descr_get */
760 0, /* tp_descr_set */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000761 offsetof(iobase, dict), /* tp_dictoffset */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000762 0, /* tp_init */
763 0, /* tp_alloc */
764 PyType_GenericNew, /* tp_new */
Antoine Pitrou796564c2013-07-30 19:59:21 +0200765 0, /* tp_free */
766 0, /* tp_is_gc */
767 0, /* tp_bases */
768 0, /* tp_mro */
769 0, /* tp_cache */
770 0, /* tp_subclasses */
771 0, /* tp_weaklist */
772 0, /* tp_del */
773 0, /* tp_version_tag */
774 (destructor)iobase_finalize, /* tp_finalize */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000775};
776
777
778/*
779 * RawIOBase class, Inherits from IOBase.
780 */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000781PyDoc_STRVAR(rawiobase_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000782 "Base class for raw binary I/O.");
783
784/*
785 * The read() method is implemented by calling readinto(); derived classes
786 * that want to support read() only need to implement readinto() as a
787 * primitive operation. In general, readinto() can be more efficient than
788 * read().
789 *
790 * (It would be tempting to also provide an implementation of readinto() in
791 * terms of read(), in case the latter is a more suitable primitive operation,
792 * but that would lead to nasty recursion in case a subclass doesn't implement
793 * either.)
794*/
795
796static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000797rawiobase_read(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000798{
799 Py_ssize_t n = -1;
800 PyObject *b, *res;
801
802 if (!PyArg_ParseTuple(args, "|n:read", &n)) {
803 return NULL;
804 }
805
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200806 if (n < 0) {
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200807 _Py_IDENTIFIER(readall);
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200808
809 return _PyObject_CallMethodId(self, &PyId_readall, NULL);
810 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000811
812 /* TODO: allocate a bytes object directly instead and manually construct
813 a writable memoryview pointing to it. */
814 b = PyByteArray_FromStringAndSize(NULL, n);
815 if (b == NULL)
816 return NULL;
817
818 res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL);
Antoine Pitrou328ec742010-09-14 18:37:24 +0000819 if (res == NULL || res == Py_None) {
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000820 Py_DECREF(b);
Antoine Pitrou328ec742010-09-14 18:37:24 +0000821 return res;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000822 }
823
824 n = PyNumber_AsSsize_t(res, PyExc_ValueError);
825 Py_DECREF(res);
826 if (n == -1 && PyErr_Occurred()) {
827 Py_DECREF(b);
828 return NULL;
829 }
830
831 res = PyBytes_FromStringAndSize(PyByteArray_AsString(b), n);
832 Py_DECREF(b);
833 return res;
834}
835
836
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000837PyDoc_STRVAR(rawiobase_readall_doc,
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000838 "Read until EOF, using multiple read() call.");
839
840static PyObject *
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000841rawiobase_readall(PyObject *self, PyObject *args)
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000842{
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000843 int r;
844 PyObject *chunks = PyList_New(0);
845 PyObject *result;
Victor Stinnercc024d12013-10-29 02:23:46 +0100846
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000847 if (chunks == NULL)
848 return NULL;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000849
850 while (1) {
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200851 PyObject *data = _PyObject_CallMethodId(self, &PyId_read,
852 "i", DEFAULT_BUFFER_SIZE);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000853 if (!data) {
Gregory P. Smith51359922012-06-23 23:55:39 -0700854 /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
855 when EINTR occurs so we needn't do it ourselves. */
856 if (_PyIO_trap_eintr()) {
857 continue;
858 }
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000859 Py_DECREF(chunks);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000860 return NULL;
861 }
Victor Stinnera80987f2011-05-25 22:47:16 +0200862 if (data == Py_None) {
863 if (PyList_GET_SIZE(chunks) == 0) {
864 Py_DECREF(chunks);
865 return data;
866 }
867 Py_DECREF(data);
868 break;
869 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000870 if (!PyBytes_Check(data)) {
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000871 Py_DECREF(chunks);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000872 Py_DECREF(data);
873 PyErr_SetString(PyExc_TypeError, "read() should return bytes");
874 return NULL;
875 }
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000876 if (PyBytes_GET_SIZE(data) == 0) {
877 /* EOF */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000878 Py_DECREF(data);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000879 break;
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000880 }
881 r = PyList_Append(chunks, data);
882 Py_DECREF(data);
883 if (r < 0) {
884 Py_DECREF(chunks);
885 return NULL;
886 }
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000887 }
Antoine Pitrou00a9b732009-03-29 19:19:49 +0000888 result = _PyBytes_Join(_PyIO_empty_bytes, chunks);
889 Py_DECREF(chunks);
890 return result;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000891}
892
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000893static PyMethodDef rawiobase_methods[] = {
894 {"read", rawiobase_read, METH_VARARGS},
895 {"readall", rawiobase_readall, METH_NOARGS, rawiobase_readall_doc},
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000896 {NULL, NULL}
897};
898
899PyTypeObject PyRawIOBase_Type = {
900 PyVarObject_HEAD_INIT(NULL, 0)
901 "_io._RawIOBase", /*tp_name*/
902 0, /*tp_basicsize*/
903 0, /*tp_itemsize*/
904 0, /*tp_dealloc*/
905 0, /*tp_print*/
906 0, /*tp_getattr*/
907 0, /*tp_setattr*/
908 0, /*tp_compare */
909 0, /*tp_repr*/
910 0, /*tp_as_number*/
911 0, /*tp_as_sequence*/
912 0, /*tp_as_mapping*/
913 0, /*tp_hash */
914 0, /*tp_call*/
915 0, /*tp_str*/
916 0, /*tp_getattro*/
917 0, /*tp_setattro*/
918 0, /*tp_as_buffer*/
Antoine Pitrou796564c2013-07-30 19:59:21 +0200919 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000920 rawiobase_doc, /* tp_doc */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000921 0, /* tp_traverse */
922 0, /* tp_clear */
923 0, /* tp_richcompare */
924 0, /* tp_weaklistoffset */
925 0, /* tp_iter */
926 0, /* tp_iternext */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +0000927 rawiobase_methods, /* tp_methods */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000928 0, /* tp_members */
929 0, /* tp_getset */
930 &PyIOBase_Type, /* tp_base */
931 0, /* tp_dict */
932 0, /* tp_descr_get */
933 0, /* tp_descr_set */
934 0, /* tp_dictoffset */
935 0, /* tp_init */
936 0, /* tp_alloc */
937 0, /* tp_new */
Antoine Pitrou796564c2013-07-30 19:59:21 +0200938 0, /* tp_free */
939 0, /* tp_is_gc */
940 0, /* tp_bases */
941 0, /* tp_mro */
942 0, /* tp_cache */
943 0, /* tp_subclasses */
944 0, /* tp_weaklist */
945 0, /* tp_del */
946 0, /* tp_version_tag */
947 0, /* tp_finalize */
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000948};