Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | An implementation of the I/O abstract base classes hierarchy |
| 3 | as defined by PEP 3116 - "New I/O" |
Victor Stinner | cc024d1 | 2013-10-29 02:23:46 +0100 | [diff] [blame] | 4 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 5 | Classes defined here: IOBase, RawIOBase. |
Victor Stinner | cc024d1 | 2013-10-29 02:23:46 +0100 | [diff] [blame] | 6 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 7 | 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 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 16 | /*[clinic input] |
| 17 | module _io |
| 18 | class _io._IOBase "PyObject *" "&PyIOBase_Type" |
| 19 | class _io._RawIOBase "PyObject *" "&PyRawIOBase_Type" |
| 20 | [clinic start generated code]*/ |
| 21 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=d29a4d076c2b211c]*/ |
| 22 | |
| 23 | /*[python input] |
| 24 | class io_ssize_t_converter(CConverter): |
| 25 | type = 'Py_ssize_t' |
| 26 | converter = '_PyIO_ConvertSsize_t' |
| 27 | [python start generated code]*/ |
| 28 | /*[python end generated code: output=da39a3ee5e6b4b0d input=d0a811d3cbfd1b33]*/ |
| 29 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 30 | /* |
| 31 | * IOBase class, an abstract class |
| 32 | */ |
| 33 | |
| 34 | typedef struct { |
| 35 | PyObject_HEAD |
Victor Stinner | cc024d1 | 2013-10-29 02:23:46 +0100 | [diff] [blame] | 36 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 37 | PyObject *dict; |
| 38 | PyObject *weakreflist; |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 39 | } iobase; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 40 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 41 | PyDoc_STRVAR(iobase_doc, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 42 | "The abstract base class for all I/O classes, acting on streams of\n" |
| 43 | "bytes. There is no public constructor.\n" |
| 44 | "\n" |
| 45 | "This class provides dummy implementations for many methods that\n" |
| 46 | "derived classes can override selectively; the default implementations\n" |
| 47 | "represent a file that cannot be read, written or seeked.\n" |
| 48 | "\n" |
| 49 | "Even though IOBase does not declare read, readinto, or write because\n" |
| 50 | "their signatures will vary, implementations and clients should\n" |
| 51 | "consider those methods part of the interface. Also, implementations\n" |
Amaury Forgeot d'Arc | 616453c | 2010-09-06 22:31:52 +0000 | [diff] [blame] | 52 | "may raise UnsupportedOperation when operations they do not support are\n" |
| 53 | "called.\n" |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 54 | "\n" |
| 55 | "The basic type used for binary data read from or written to a file is\n" |
Martin Panter | 6bb91f3 | 2016-05-28 00:41:57 +0000 | [diff] [blame] | 56 | "bytes. Other bytes-like objects are accepted as method arguments too.\n" |
| 57 | "In some cases (such as readinto), a writable object is required. Text\n" |
| 58 | "I/O classes work with str data.\n" |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 59 | "\n" |
Andrew Kuchling | 7646620 | 2014-04-15 21:11:36 -0400 | [diff] [blame] | 60 | "Note that calling any method (except additional calls to close(),\n" |
| 61 | "which are ignored) on a closed stream should raise a ValueError.\n" |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 62 | "\n" |
| 63 | "IOBase (and its subclasses) support the iterator protocol, meaning\n" |
| 64 | "that an IOBase object can be iterated over yielding the lines in a\n" |
| 65 | "stream.\n" |
| 66 | "\n" |
| 67 | "IOBase also supports the :keyword:`with` statement. In this example,\n" |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 68 | "fp is closed after the suite of the with statement is complete:\n" |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 69 | "\n" |
| 70 | "with open('spam.txt', 'r') as fp:\n" |
| 71 | " fp.write('Spam and eggs!')\n"); |
| 72 | |
| 73 | /* Use this macro whenever you want to check the internal `closed` status |
| 74 | of the IOBase object rather than the virtual `closed` attribute as returned |
| 75 | by whatever subclass. */ |
| 76 | |
Martin v. Löwis | 767046a | 2011-10-14 15:35:36 +0200 | [diff] [blame] | 77 | _Py_IDENTIFIER(__IOBase_closed); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 78 | #define IS_CLOSED(self) \ |
Martin v. Löwis | 767046a | 2011-10-14 15:35:36 +0200 | [diff] [blame] | 79 | _PyObject_HasAttrId(self, &PyId___IOBase_closed) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 80 | |
Victor Stinner | 3f36a57 | 2013-11-12 21:39:02 +0100 | [diff] [blame] | 81 | _Py_IDENTIFIER(read); |
| 82 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 83 | /* Internal methods */ |
| 84 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 85 | iobase_unsupported(const char *message) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 86 | { |
Antoine Pitrou | 712cb73 | 2013-12-21 15:51:54 +0100 | [diff] [blame] | 87 | _PyIO_State *state = IO_STATE(); |
| 88 | if (state != NULL) |
| 89 | PyErr_SetString(state->unsupported_operation, message); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 90 | return NULL; |
| 91 | } |
| 92 | |
Raymond Hettinger | 15f44ab | 2016-08-30 10:47:49 -0700 | [diff] [blame] | 93 | /* Positioning */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 94 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 95 | PyDoc_STRVAR(iobase_seek_doc, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 96 | "Change stream position.\n" |
| 97 | "\n" |
Terry Jan Reedy | 0158af3 | 2013-03-11 17:42:46 -0400 | [diff] [blame] | 98 | "Change the stream position to the given byte offset. The offset is\n" |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 99 | "interpreted relative to the position indicated by whence. Values\n" |
| 100 | "for whence are:\n" |
| 101 | "\n" |
| 102 | "* 0 -- start of stream (the default); offset should be zero or positive\n" |
| 103 | "* 1 -- current stream position; offset may be negative\n" |
| 104 | "* 2 -- end of stream; offset is usually negative\n" |
| 105 | "\n" |
| 106 | "Return the new absolute position."); |
| 107 | |
| 108 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 109 | iobase_seek(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 110 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 111 | return iobase_unsupported("seek"); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 114 | /*[clinic input] |
| 115 | _io._IOBase.tell |
| 116 | |
| 117 | Return current stream position. |
| 118 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 119 | |
| 120 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 121 | _io__IOBase_tell_impl(PyObject *self) |
| 122 | /*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 123 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 124 | _Py_IDENTIFIER(seek); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 125 | |
| 126 | return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 129 | PyDoc_STRVAR(iobase_truncate_doc, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 130 | "Truncate file to size bytes.\n" |
| 131 | "\n" |
Antoine Pitrou | 905a2ff | 2010-01-31 22:47:27 +0000 | [diff] [blame] | 132 | "File pointer is left unchanged. Size defaults to the current IO\n" |
| 133 | "position as reported by tell(). Returns the new size."); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 134 | |
| 135 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 136 | iobase_truncate(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 137 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 138 | return iobase_unsupported("truncate"); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* Flush and close methods */ |
| 142 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 143 | /*[clinic input] |
| 144 | _io._IOBase.flush |
| 145 | |
| 146 | Flush write buffers, if applicable. |
| 147 | |
| 148 | This is not implemented for read-only and non-blocking streams. |
| 149 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 150 | |
| 151 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 152 | _io__IOBase_flush_impl(PyObject *self) |
| 153 | /*[clinic end generated code: output=7cef4b4d54656a3b input=773be121abe270aa]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 154 | { |
| 155 | /* XXX Should this return the number of bytes written??? */ |
| 156 | if (IS_CLOSED(self)) { |
| 157 | PyErr_SetString(PyExc_ValueError, "I/O operation on closed file."); |
| 158 | return NULL; |
| 159 | } |
| 160 | Py_RETURN_NONE; |
| 161 | } |
| 162 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 163 | static int |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 164 | iobase_closed(PyObject *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 165 | { |
| 166 | PyObject *res; |
| 167 | int closed; |
| 168 | /* This gets the derived attribute, which is *not* __IOBase_closed |
| 169 | in most cases! */ |
| 170 | res = PyObject_GetAttr(self, _PyIO_str_closed); |
| 171 | if (res == NULL) |
| 172 | return 0; |
| 173 | closed = PyObject_IsTrue(res); |
| 174 | Py_DECREF(res); |
| 175 | return closed; |
| 176 | } |
| 177 | |
| 178 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 179 | iobase_closed_get(PyObject *self, void *context) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 180 | { |
| 181 | return PyBool_FromLong(IS_CLOSED(self)); |
| 182 | } |
| 183 | |
| 184 | PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 185 | _PyIOBase_check_closed(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 186 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 187 | if (iobase_closed(self)) { |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 188 | PyErr_SetString(PyExc_ValueError, "I/O operation on closed file."); |
| 189 | return NULL; |
| 190 | } |
| 191 | if (args == Py_True) |
| 192 | return Py_None; |
| 193 | else |
| 194 | Py_RETURN_NONE; |
| 195 | } |
| 196 | |
| 197 | /* XXX: IOBase thinks it has to maintain its own internal state in |
| 198 | `__IOBase_closed` and call flush() by itself, but it is redundant with |
| 199 | whatever behaviour a non-trivial derived class will implement. */ |
| 200 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 201 | /*[clinic input] |
| 202 | _io._IOBase.close |
| 203 | |
| 204 | Flush and close the IO object. |
| 205 | |
| 206 | This method has no effect if the file is already closed. |
| 207 | [clinic start generated code]*/ |
| 208 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 209 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 210 | _io__IOBase_close_impl(PyObject *self) |
| 211 | /*[clinic end generated code: output=63c6a6f57d783d6d input=f4494d5c31dbc6b7]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 212 | { |
| 213 | PyObject *res; |
| 214 | |
| 215 | if (IS_CLOSED(self)) |
| 216 | Py_RETURN_NONE; |
| 217 | |
| 218 | res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL); |
Victor Stinner | aa5bbfa | 2013-11-08 00:29:41 +0100 | [diff] [blame] | 219 | |
| 220 | if (_PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True) < 0) { |
| 221 | Py_XDECREF(res); |
Antoine Pitrou | 6be8876 | 2010-05-03 16:48:20 +0000 | [diff] [blame] | 222 | return NULL; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 223 | } |
Victor Stinner | aa5bbfa | 2013-11-08 00:29:41 +0100 | [diff] [blame] | 224 | |
| 225 | if (res == NULL) |
| 226 | return NULL; |
| 227 | |
| 228 | Py_DECREF(res); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 229 | Py_RETURN_NONE; |
| 230 | } |
| 231 | |
| 232 | /* Finalization and garbage collection support */ |
| 233 | |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 234 | static void |
| 235 | iobase_finalize(PyObject *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 236 | { |
| 237 | PyObject *res; |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 238 | PyObject *error_type, *error_value, *error_traceback; |
| 239 | int closed; |
| 240 | _Py_IDENTIFIER(_finalizing); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 241 | |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 242 | /* Save the current exception, if any. */ |
| 243 | PyErr_Fetch(&error_type, &error_value, &error_traceback); |
| 244 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 245 | /* If `closed` doesn't exist or can't be evaluated as bool, then the |
| 246 | object is probably in an unusable state, so ignore. */ |
| 247 | res = PyObject_GetAttr(self, _PyIO_str_closed); |
Christian Heimes | 72f455e | 2013-07-31 01:33:50 +0200 | [diff] [blame] | 248 | if (res == NULL) { |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 249 | PyErr_Clear(); |
Christian Heimes | 72f455e | 2013-07-31 01:33:50 +0200 | [diff] [blame] | 250 | closed = -1; |
| 251 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 252 | else { |
| 253 | closed = PyObject_IsTrue(res); |
| 254 | Py_DECREF(res); |
| 255 | if (closed == -1) |
| 256 | PyErr_Clear(); |
| 257 | } |
| 258 | if (closed == 0) { |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 259 | /* Signal close() that it was called as part of the object |
| 260 | finalization process. */ |
| 261 | if (_PyObject_SetAttrId(self, &PyId__finalizing, Py_True)) |
| 262 | PyErr_Clear(); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 263 | res = PyObject_CallMethodObjArgs((PyObject *) self, _PyIO_str_close, |
| 264 | NULL); |
| 265 | /* Silencing I/O errors is bad, but printing spurious tracebacks is |
| 266 | equally as bad, and potentially more frequent (because of |
| 267 | shutdown issues). */ |
| 268 | if (res == NULL) |
| 269 | PyErr_Clear(); |
| 270 | else |
| 271 | Py_DECREF(res); |
| 272 | } |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 273 | |
| 274 | /* Restore the saved exception. */ |
| 275 | PyErr_Restore(error_type, error_value, error_traceback); |
| 276 | } |
| 277 | |
| 278 | int |
| 279 | _PyIOBase_finalize(PyObject *self) |
| 280 | { |
| 281 | int is_zombie; |
| 282 | |
| 283 | /* If _PyIOBase_finalize() is called from a destructor, we need to |
| 284 | resurrect the object as calling close() can invoke arbitrary code. */ |
| 285 | is_zombie = (Py_REFCNT(self) == 0); |
| 286 | if (is_zombie) |
| 287 | return PyObject_CallFinalizerFromDealloc(self); |
| 288 | else { |
| 289 | PyObject_CallFinalizer(self); |
| 290 | return 0; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 291 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static int |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 295 | iobase_traverse(iobase *self, visitproc visit, void *arg) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 296 | { |
| 297 | Py_VISIT(self->dict); |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 302 | iobase_clear(iobase *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 303 | { |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 304 | Py_CLEAR(self->dict); |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | /* Destructor */ |
| 309 | |
| 310 | static void |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 311 | iobase_dealloc(iobase *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 312 | { |
| 313 | /* NOTE: since IOBaseObject has its own dict, Python-defined attributes |
| 314 | are still available here for close() to use. |
| 315 | However, if the derived class declares a __slots__, those slots are |
| 316 | already gone. |
| 317 | */ |
| 318 | if (_PyIOBase_finalize((PyObject *) self) < 0) { |
| 319 | /* When called from a heap type's dealloc, the type will be |
| 320 | decref'ed on return (see e.g. subtype_dealloc in typeobject.c). */ |
| 321 | if (PyType_HasFeature(Py_TYPE(self), Py_TPFLAGS_HEAPTYPE)) |
| 322 | Py_INCREF(Py_TYPE(self)); |
| 323 | return; |
| 324 | } |
| 325 | _PyObject_GC_UNTRACK(self); |
| 326 | if (self->weakreflist != NULL) |
| 327 | PyObject_ClearWeakRefs((PyObject *) self); |
| 328 | Py_CLEAR(self->dict); |
| 329 | Py_TYPE(self)->tp_free((PyObject *) self); |
| 330 | } |
| 331 | |
| 332 | /* Inquiry methods */ |
| 333 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 334 | /*[clinic input] |
| 335 | _io._IOBase.seekable |
| 336 | |
| 337 | Return whether object supports random access. |
| 338 | |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 339 | If False, seek(), tell() and truncate() will raise OSError. |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 340 | This method may need to do a test seek(). |
| 341 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 342 | |
| 343 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 344 | _io__IOBase_seekable_impl(PyObject *self) |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 345 | /*[clinic end generated code: output=4c24c67f5f32a43d input=b976622f7fdf3063]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 346 | { |
| 347 | Py_RETURN_FALSE; |
| 348 | } |
| 349 | |
| 350 | PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 351 | _PyIOBase_check_seekable(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 352 | { |
| 353 | PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL); |
| 354 | if (res == NULL) |
| 355 | return NULL; |
| 356 | if (res != Py_True) { |
| 357 | Py_CLEAR(res); |
Antoine Pitrou | 0d739d7 | 2010-09-05 23:01:12 +0000 | [diff] [blame] | 358 | iobase_unsupported("File or stream is not seekable."); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 359 | return NULL; |
| 360 | } |
| 361 | if (args == Py_True) { |
| 362 | Py_DECREF(res); |
| 363 | } |
| 364 | return res; |
| 365 | } |
| 366 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 367 | /*[clinic input] |
| 368 | _io._IOBase.readable |
| 369 | |
| 370 | Return whether object was opened for reading. |
| 371 | |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 372 | If False, read() will raise OSError. |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 373 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 374 | |
| 375 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 376 | _io__IOBase_readable_impl(PyObject *self) |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 377 | /*[clinic end generated code: output=e48089250686388b input=285b3b866a0ec35f]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 378 | { |
| 379 | Py_RETURN_FALSE; |
| 380 | } |
| 381 | |
| 382 | /* May be called with any object */ |
| 383 | PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 384 | _PyIOBase_check_readable(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 385 | { |
| 386 | PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL); |
| 387 | if (res == NULL) |
| 388 | return NULL; |
| 389 | if (res != Py_True) { |
| 390 | Py_CLEAR(res); |
Antoine Pitrou | 0d739d7 | 2010-09-05 23:01:12 +0000 | [diff] [blame] | 391 | iobase_unsupported("File or stream is not readable."); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 392 | return NULL; |
| 393 | } |
| 394 | if (args == Py_True) { |
| 395 | Py_DECREF(res); |
| 396 | } |
| 397 | return res; |
| 398 | } |
| 399 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 400 | /*[clinic input] |
| 401 | _io._IOBase.writable |
| 402 | |
| 403 | Return whether object was opened for writing. |
| 404 | |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 405 | If False, write() will raise OSError. |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 406 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 407 | |
| 408 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 409 | _io__IOBase_writable_impl(PyObject *self) |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 410 | /*[clinic end generated code: output=406001d0985be14f input=9dcac18a013a05b5]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 411 | { |
| 412 | Py_RETURN_FALSE; |
| 413 | } |
| 414 | |
| 415 | /* May be called with any object */ |
| 416 | PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 417 | _PyIOBase_check_writable(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 418 | { |
| 419 | PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL); |
| 420 | if (res == NULL) |
| 421 | return NULL; |
| 422 | if (res != Py_True) { |
| 423 | Py_CLEAR(res); |
Antoine Pitrou | 0d739d7 | 2010-09-05 23:01:12 +0000 | [diff] [blame] | 424 | iobase_unsupported("File or stream is not writable."); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 425 | return NULL; |
| 426 | } |
| 427 | if (args == Py_True) { |
| 428 | Py_DECREF(res); |
| 429 | } |
| 430 | return res; |
| 431 | } |
| 432 | |
| 433 | /* Context manager */ |
| 434 | |
| 435 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 436 | iobase_enter(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 437 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 438 | if (_PyIOBase_check_closed(self, Py_True) == NULL) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 439 | return NULL; |
| 440 | |
| 441 | Py_INCREF(self); |
| 442 | return self; |
| 443 | } |
| 444 | |
| 445 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 446 | iobase_exit(PyObject *self, PyObject *args) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 447 | { |
| 448 | return PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL); |
| 449 | } |
| 450 | |
| 451 | /* Lower-level APIs */ |
| 452 | |
| 453 | /* XXX Should these be present even if unimplemented? */ |
| 454 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 455 | /*[clinic input] |
| 456 | _io._IOBase.fileno |
| 457 | |
| 458 | Returns underlying file descriptor if one exists. |
| 459 | |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 460 | OSError is raised if the IO object does not use a file descriptor. |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 461 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 462 | |
| 463 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 464 | _io__IOBase_fileno_impl(PyObject *self) |
Martin Panter | 754aab2 | 2016-03-31 07:21:56 +0000 | [diff] [blame] | 465 | /*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 466 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 467 | return iobase_unsupported("fileno"); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 470 | /*[clinic input] |
| 471 | _io._IOBase.isatty |
| 472 | |
| 473 | Return whether this is an 'interactive' stream. |
| 474 | |
| 475 | Return False if it can't be determined. |
| 476 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 477 | |
| 478 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 479 | _io__IOBase_isatty_impl(PyObject *self) |
| 480 | /*[clinic end generated code: output=60cab77cede41cdd input=9ef76530d368458b]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 481 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 482 | if (_PyIOBase_check_closed(self, Py_True) == NULL) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 483 | return NULL; |
| 484 | Py_RETURN_FALSE; |
| 485 | } |
| 486 | |
| 487 | /* Readline(s) and writelines */ |
| 488 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 489 | /*[clinic input] |
| 490 | _io._IOBase.readline |
| 491 | size as limit: io_ssize_t = -1 |
| 492 | / |
| 493 | |
| 494 | Read and return a line from the stream. |
| 495 | |
| 496 | If size is specified, at most size bytes will be read. |
| 497 | |
| 498 | The line terminator is always b'\n' for binary files; for text |
| 499 | files, the newlines argument to open can be used to select the line |
| 500 | terminator(s) recognized. |
| 501 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 502 | |
| 503 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 504 | _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) |
| 505 | /*[clinic end generated code: output=4479f79b58187840 input=df4cc8884f553cab]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 506 | { |
| 507 | /* For backwards compatibility, a (slowish) readline(). */ |
| 508 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 509 | int has_peek = 0; |
| 510 | PyObject *buffer, *result; |
| 511 | Py_ssize_t old_size = -1; |
Martin v. Löwis | 767046a | 2011-10-14 15:35:36 +0200 | [diff] [blame] | 512 | _Py_IDENTIFIER(peek); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 513 | |
Martin v. Löwis | 767046a | 2011-10-14 15:35:36 +0200 | [diff] [blame] | 514 | if (_PyObject_HasAttrId(self, &PyId_peek)) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 515 | has_peek = 1; |
| 516 | |
| 517 | buffer = PyByteArray_FromStringAndSize(NULL, 0); |
| 518 | if (buffer == NULL) |
| 519 | return NULL; |
| 520 | |
| 521 | while (limit < 0 || Py_SIZE(buffer) < limit) { |
| 522 | Py_ssize_t nreadahead = 1; |
| 523 | PyObject *b; |
| 524 | |
| 525 | if (has_peek) { |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 526 | PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1); |
Gregory P. Smith | 5135992 | 2012-06-23 23:55:39 -0700 | [diff] [blame] | 527 | if (readahead == NULL) { |
| 528 | /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() |
| 529 | when EINTR occurs so we needn't do it ourselves. */ |
| 530 | if (_PyIO_trap_eintr()) { |
| 531 | continue; |
| 532 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 533 | goto fail; |
Gregory P. Smith | 5135992 | 2012-06-23 23:55:39 -0700 | [diff] [blame] | 534 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 535 | if (!PyBytes_Check(readahead)) { |
| 536 | PyErr_Format(PyExc_IOError, |
| 537 | "peek() should have returned a bytes object, " |
| 538 | "not '%.200s'", Py_TYPE(readahead)->tp_name); |
| 539 | Py_DECREF(readahead); |
| 540 | goto fail; |
| 541 | } |
| 542 | if (PyBytes_GET_SIZE(readahead) > 0) { |
| 543 | Py_ssize_t n = 0; |
| 544 | const char *buf = PyBytes_AS_STRING(readahead); |
| 545 | if (limit >= 0) { |
| 546 | do { |
| 547 | if (n >= PyBytes_GET_SIZE(readahead) || n >= limit) |
| 548 | break; |
| 549 | if (buf[n++] == '\n') |
| 550 | break; |
| 551 | } while (1); |
| 552 | } |
| 553 | else { |
| 554 | do { |
| 555 | if (n >= PyBytes_GET_SIZE(readahead)) |
| 556 | break; |
| 557 | if (buf[n++] == '\n') |
| 558 | break; |
| 559 | } while (1); |
| 560 | } |
| 561 | nreadahead = n; |
| 562 | } |
| 563 | Py_DECREF(readahead); |
| 564 | } |
| 565 | |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 566 | b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead); |
Gregory P. Smith | 5135992 | 2012-06-23 23:55:39 -0700 | [diff] [blame] | 567 | if (b == NULL) { |
| 568 | /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() |
| 569 | when EINTR occurs so we needn't do it ourselves. */ |
| 570 | if (_PyIO_trap_eintr()) { |
| 571 | continue; |
| 572 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 573 | goto fail; |
Gregory P. Smith | 5135992 | 2012-06-23 23:55:39 -0700 | [diff] [blame] | 574 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 575 | if (!PyBytes_Check(b)) { |
| 576 | PyErr_Format(PyExc_IOError, |
| 577 | "read() should have returned a bytes object, " |
| 578 | "not '%.200s'", Py_TYPE(b)->tp_name); |
| 579 | Py_DECREF(b); |
| 580 | goto fail; |
| 581 | } |
| 582 | if (PyBytes_GET_SIZE(b) == 0) { |
| 583 | Py_DECREF(b); |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | old_size = PyByteArray_GET_SIZE(buffer); |
Victor Stinner | cc024d1 | 2013-10-29 02:23:46 +0100 | [diff] [blame] | 588 | if (PyByteArray_Resize(buffer, old_size + PyBytes_GET_SIZE(b)) < 0) { |
| 589 | Py_DECREF(b); |
| 590 | goto fail; |
| 591 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 592 | memcpy(PyByteArray_AS_STRING(buffer) + old_size, |
| 593 | PyBytes_AS_STRING(b), PyBytes_GET_SIZE(b)); |
| 594 | |
| 595 | Py_DECREF(b); |
| 596 | |
| 597 | if (PyByteArray_AS_STRING(buffer)[PyByteArray_GET_SIZE(buffer) - 1] == '\n') |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(buffer), |
| 602 | PyByteArray_GET_SIZE(buffer)); |
| 603 | Py_DECREF(buffer); |
| 604 | return result; |
| 605 | fail: |
| 606 | Py_DECREF(buffer); |
| 607 | return NULL; |
| 608 | } |
| 609 | |
| 610 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 611 | iobase_iter(PyObject *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 612 | { |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 613 | if (_PyIOBase_check_closed(self, Py_True) == NULL) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 614 | return NULL; |
| 615 | |
| 616 | Py_INCREF(self); |
| 617 | return self; |
| 618 | } |
| 619 | |
| 620 | static PyObject * |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 621 | iobase_iternext(PyObject *self) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 622 | { |
| 623 | PyObject *line = PyObject_CallMethodObjArgs(self, _PyIO_str_readline, NULL); |
| 624 | |
| 625 | if (line == NULL) |
| 626 | return NULL; |
| 627 | |
| 628 | if (PyObject_Size(line) == 0) { |
| 629 | Py_DECREF(line); |
| 630 | return NULL; |
| 631 | } |
| 632 | |
| 633 | return line; |
| 634 | } |
| 635 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 636 | /*[clinic input] |
| 637 | _io._IOBase.readlines |
| 638 | hint: io_ssize_t = -1 |
| 639 | / |
| 640 | |
| 641 | Return a list of lines from the stream. |
| 642 | |
| 643 | hint can be specified to control the number of lines read: no more |
| 644 | lines will be read if the total size (in bytes/characters) of all |
| 645 | lines so far exceeds hint. |
| 646 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 647 | |
| 648 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 649 | _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) |
| 650 | /*[clinic end generated code: output=2f50421677fa3dea input=1961c4a95e96e661]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 651 | { |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 652 | Py_ssize_t length = 0; |
Benjamin Peterson | 0551613 | 2009-12-13 19:28:09 +0000 | [diff] [blame] | 653 | PyObject *result; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 654 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 655 | result = PyList_New(0); |
| 656 | if (result == NULL) |
| 657 | return NULL; |
| 658 | |
| 659 | if (hint <= 0) { |
| 660 | /* XXX special-casing this made sense in the Python version in order |
| 661 | to remove the bytecode interpretation overhead, but it could |
| 662 | probably be removed here. */ |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 663 | _Py_IDENTIFIER(extend); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 664 | PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self); |
| 665 | |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 666 | if (ret == NULL) { |
| 667 | Py_DECREF(result); |
| 668 | return NULL; |
| 669 | } |
| 670 | Py_DECREF(ret); |
| 671 | return result; |
| 672 | } |
| 673 | |
| 674 | while (1) { |
| 675 | PyObject *line = PyIter_Next(self); |
| 676 | if (line == NULL) { |
| 677 | if (PyErr_Occurred()) { |
| 678 | Py_DECREF(result); |
| 679 | return NULL; |
| 680 | } |
| 681 | else |
| 682 | break; /* StopIteration raised */ |
| 683 | } |
| 684 | |
| 685 | if (PyList_Append(result, line) < 0) { |
| 686 | Py_DECREF(line); |
| 687 | Py_DECREF(result); |
| 688 | return NULL; |
| 689 | } |
| 690 | length += PyObject_Size(line); |
| 691 | Py_DECREF(line); |
| 692 | |
| 693 | if (length > hint) |
| 694 | break; |
| 695 | } |
| 696 | return result; |
| 697 | } |
| 698 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 699 | /*[clinic input] |
| 700 | _io._IOBase.writelines |
| 701 | lines: object |
| 702 | / |
| 703 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 704 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 705 | static PyObject * |
| 706 | _io__IOBase_writelines(PyObject *self, PyObject *lines) |
| 707 | /*[clinic end generated code: output=976eb0a9b60a6628 input=432e729a8450b3cb]*/ |
| 708 | { |
| 709 | PyObject *iter, *res; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 710 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 711 | if (_PyIOBase_check_closed(self, Py_True) == NULL) |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 712 | return NULL; |
| 713 | |
| 714 | iter = PyObject_GetIter(lines); |
| 715 | if (iter == NULL) |
| 716 | return NULL; |
| 717 | |
| 718 | while (1) { |
| 719 | PyObject *line = PyIter_Next(iter); |
| 720 | if (line == NULL) { |
| 721 | if (PyErr_Occurred()) { |
| 722 | Py_DECREF(iter); |
| 723 | return NULL; |
| 724 | } |
| 725 | else |
| 726 | break; /* Stop Iteration */ |
| 727 | } |
| 728 | |
Gregory P. Smith | b9817b0 | 2013-02-01 13:03:39 -0800 | [diff] [blame] | 729 | res = NULL; |
| 730 | do { |
| 731 | res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL); |
| 732 | } while (res == NULL && _PyIO_trap_eintr()); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 733 | Py_DECREF(line); |
| 734 | if (res == NULL) { |
| 735 | Py_DECREF(iter); |
| 736 | return NULL; |
| 737 | } |
| 738 | Py_DECREF(res); |
| 739 | } |
| 740 | Py_DECREF(iter); |
| 741 | Py_RETURN_NONE; |
| 742 | } |
| 743 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 744 | #include "clinic/iobase.c.h" |
| 745 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 746 | static PyMethodDef iobase_methods[] = { |
| 747 | {"seek", iobase_seek, METH_VARARGS, iobase_seek_doc}, |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 748 | _IO__IOBASE_TELL_METHODDEF |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 749 | {"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc}, |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 750 | _IO__IOBASE_FLUSH_METHODDEF |
| 751 | _IO__IOBASE_CLOSE_METHODDEF |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 752 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 753 | _IO__IOBASE_SEEKABLE_METHODDEF |
| 754 | _IO__IOBASE_READABLE_METHODDEF |
| 755 | _IO__IOBASE_WRITABLE_METHODDEF |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 756 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 757 | {"_checkClosed", _PyIOBase_check_closed, METH_NOARGS}, |
| 758 | {"_checkSeekable", _PyIOBase_check_seekable, METH_NOARGS}, |
| 759 | {"_checkReadable", _PyIOBase_check_readable, METH_NOARGS}, |
| 760 | {"_checkWritable", _PyIOBase_check_writable, METH_NOARGS}, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 761 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 762 | _IO__IOBASE_FILENO_METHODDEF |
| 763 | _IO__IOBASE_ISATTY_METHODDEF |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 764 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 765 | {"__enter__", iobase_enter, METH_NOARGS}, |
| 766 | {"__exit__", iobase_exit, METH_VARARGS}, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 767 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 768 | _IO__IOBASE_READLINE_METHODDEF |
| 769 | _IO__IOBASE_READLINES_METHODDEF |
| 770 | _IO__IOBASE_WRITELINES_METHODDEF |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 771 | |
| 772 | {NULL, NULL} |
| 773 | }; |
| 774 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 775 | static PyGetSetDef iobase_getset[] = { |
Benjamin Peterson | 23d7f12 | 2012-02-19 20:02:57 -0500 | [diff] [blame] | 776 | {"__dict__", PyObject_GenericGetDict, NULL, NULL}, |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 777 | {"closed", (getter)iobase_closed_get, NULL, NULL}, |
Benjamin Peterson | 1fea321 | 2009-04-19 03:15:20 +0000 | [diff] [blame] | 778 | {NULL} |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | |
| 782 | PyTypeObject PyIOBase_Type = { |
| 783 | PyVarObject_HEAD_INIT(NULL, 0) |
| 784 | "_io._IOBase", /*tp_name*/ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 785 | sizeof(iobase), /*tp_basicsize*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 786 | 0, /*tp_itemsize*/ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 787 | (destructor)iobase_dealloc, /*tp_dealloc*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 788 | 0, /*tp_print*/ |
| 789 | 0, /*tp_getattr*/ |
| 790 | 0, /*tp_setattr*/ |
| 791 | 0, /*tp_compare */ |
| 792 | 0, /*tp_repr*/ |
| 793 | 0, /*tp_as_number*/ |
| 794 | 0, /*tp_as_sequence*/ |
| 795 | 0, /*tp_as_mapping*/ |
| 796 | 0, /*tp_hash */ |
| 797 | 0, /*tp_call*/ |
| 798 | 0, /*tp_str*/ |
| 799 | 0, /*tp_getattro*/ |
| 800 | 0, /*tp_setattro*/ |
| 801 | 0, /*tp_as_buffer*/ |
| 802 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 803 | | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 804 | iobase_doc, /* tp_doc */ |
| 805 | (traverseproc)iobase_traverse, /* tp_traverse */ |
| 806 | (inquiry)iobase_clear, /* tp_clear */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 807 | 0, /* tp_richcompare */ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 808 | offsetof(iobase, weakreflist), /* tp_weaklistoffset */ |
| 809 | iobase_iter, /* tp_iter */ |
| 810 | iobase_iternext, /* tp_iternext */ |
| 811 | iobase_methods, /* tp_methods */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 812 | 0, /* tp_members */ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 813 | iobase_getset, /* tp_getset */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 814 | 0, /* tp_base */ |
| 815 | 0, /* tp_dict */ |
| 816 | 0, /* tp_descr_get */ |
| 817 | 0, /* tp_descr_set */ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 818 | offsetof(iobase, dict), /* tp_dictoffset */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 819 | 0, /* tp_init */ |
| 820 | 0, /* tp_alloc */ |
| 821 | PyType_GenericNew, /* tp_new */ |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 822 | 0, /* tp_free */ |
| 823 | 0, /* tp_is_gc */ |
| 824 | 0, /* tp_bases */ |
| 825 | 0, /* tp_mro */ |
| 826 | 0, /* tp_cache */ |
| 827 | 0, /* tp_subclasses */ |
| 828 | 0, /* tp_weaklist */ |
| 829 | 0, /* tp_del */ |
| 830 | 0, /* tp_version_tag */ |
Victor Stinner | 928bff0 | 2016-03-19 10:36:36 +0100 | [diff] [blame] | 831 | iobase_finalize, /* tp_finalize */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 832 | }; |
| 833 | |
| 834 | |
| 835 | /* |
| 836 | * RawIOBase class, Inherits from IOBase. |
| 837 | */ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 838 | PyDoc_STRVAR(rawiobase_doc, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 839 | "Base class for raw binary I/O."); |
| 840 | |
| 841 | /* |
| 842 | * The read() method is implemented by calling readinto(); derived classes |
| 843 | * that want to support read() only need to implement readinto() as a |
| 844 | * primitive operation. In general, readinto() can be more efficient than |
| 845 | * read(). |
| 846 | * |
| 847 | * (It would be tempting to also provide an implementation of readinto() in |
| 848 | * terms of read(), in case the latter is a more suitable primitive operation, |
| 849 | * but that would lead to nasty recursion in case a subclass doesn't implement |
| 850 | * either.) |
| 851 | */ |
| 852 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 853 | /*[clinic input] |
| 854 | _io._RawIOBase.read |
| 855 | size as n: Py_ssize_t = -1 |
| 856 | / |
| 857 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 858 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 859 | static PyObject * |
| 860 | _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) |
| 861 | /*[clinic end generated code: output=6cdeb731e3c9f13c input=b6d0dcf6417d1374]*/ |
| 862 | { |
| 863 | PyObject *b, *res; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 864 | |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 865 | if (n < 0) { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 866 | _Py_IDENTIFIER(readall); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 867 | |
| 868 | return _PyObject_CallMethodId(self, &PyId_readall, NULL); |
| 869 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 870 | |
| 871 | /* TODO: allocate a bytes object directly instead and manually construct |
| 872 | a writable memoryview pointing to it. */ |
| 873 | b = PyByteArray_FromStringAndSize(NULL, n); |
| 874 | if (b == NULL) |
| 875 | return NULL; |
| 876 | |
| 877 | res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL); |
Antoine Pitrou | 328ec74 | 2010-09-14 18:37:24 +0000 | [diff] [blame] | 878 | if (res == NULL || res == Py_None) { |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 879 | Py_DECREF(b); |
Antoine Pitrou | 328ec74 | 2010-09-14 18:37:24 +0000 | [diff] [blame] | 880 | return res; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | n = PyNumber_AsSsize_t(res, PyExc_ValueError); |
| 884 | Py_DECREF(res); |
| 885 | if (n == -1 && PyErr_Occurred()) { |
| 886 | Py_DECREF(b); |
| 887 | return NULL; |
| 888 | } |
| 889 | |
| 890 | res = PyBytes_FromStringAndSize(PyByteArray_AsString(b), n); |
| 891 | Py_DECREF(b); |
| 892 | return res; |
| 893 | } |
| 894 | |
| 895 | |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 896 | /*[clinic input] |
| 897 | _io._RawIOBase.readall |
| 898 | |
| 899 | Read until EOF, using multiple read() call. |
| 900 | [clinic start generated code]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 901 | |
| 902 | static PyObject * |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 903 | _io__RawIOBase_readall_impl(PyObject *self) |
| 904 | /*[clinic end generated code: output=1987b9ce929425a0 input=688874141213622a]*/ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 905 | { |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 906 | int r; |
| 907 | PyObject *chunks = PyList_New(0); |
| 908 | PyObject *result; |
Victor Stinner | cc024d1 | 2013-10-29 02:23:46 +0100 | [diff] [blame] | 909 | |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 910 | if (chunks == NULL) |
| 911 | return NULL; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 912 | |
| 913 | while (1) { |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 914 | PyObject *data = _PyObject_CallMethodId(self, &PyId_read, |
| 915 | "i", DEFAULT_BUFFER_SIZE); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 916 | if (!data) { |
Gregory P. Smith | 5135992 | 2012-06-23 23:55:39 -0700 | [diff] [blame] | 917 | /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() |
| 918 | when EINTR occurs so we needn't do it ourselves. */ |
| 919 | if (_PyIO_trap_eintr()) { |
| 920 | continue; |
| 921 | } |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 922 | Py_DECREF(chunks); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 923 | return NULL; |
| 924 | } |
Victor Stinner | a80987f | 2011-05-25 22:47:16 +0200 | [diff] [blame] | 925 | if (data == Py_None) { |
| 926 | if (PyList_GET_SIZE(chunks) == 0) { |
| 927 | Py_DECREF(chunks); |
| 928 | return data; |
| 929 | } |
| 930 | Py_DECREF(data); |
| 931 | break; |
| 932 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 933 | if (!PyBytes_Check(data)) { |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 934 | Py_DECREF(chunks); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 935 | Py_DECREF(data); |
| 936 | PyErr_SetString(PyExc_TypeError, "read() should return bytes"); |
| 937 | return NULL; |
| 938 | } |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 939 | if (PyBytes_GET_SIZE(data) == 0) { |
| 940 | /* EOF */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 941 | Py_DECREF(data); |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 942 | break; |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 943 | } |
| 944 | r = PyList_Append(chunks, data); |
| 945 | Py_DECREF(data); |
| 946 | if (r < 0) { |
| 947 | Py_DECREF(chunks); |
| 948 | return NULL; |
| 949 | } |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 950 | } |
Antoine Pitrou | 00a9b73 | 2009-03-29 19:19:49 +0000 | [diff] [blame] | 951 | result = _PyBytes_Join(_PyIO_empty_bytes, chunks); |
| 952 | Py_DECREF(chunks); |
| 953 | return result; |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Antoine Pitrou | 45d6156 | 2015-05-20 21:50:59 +0200 | [diff] [blame] | 956 | static PyObject * |
| 957 | rawiobase_readinto(PyObject *self, PyObject *args) |
| 958 | { |
| 959 | PyErr_SetNone(PyExc_NotImplementedError); |
| 960 | return NULL; |
| 961 | } |
| 962 | |
| 963 | static PyObject * |
| 964 | rawiobase_write(PyObject *self, PyObject *args) |
| 965 | { |
| 966 | PyErr_SetNone(PyExc_NotImplementedError); |
| 967 | return NULL; |
| 968 | } |
| 969 | |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 970 | static PyMethodDef rawiobase_methods[] = { |
Serhiy Storchaka | f24131f | 2015-04-16 11:19:43 +0300 | [diff] [blame] | 971 | _IO__RAWIOBASE_READ_METHODDEF |
| 972 | _IO__RAWIOBASE_READALL_METHODDEF |
Antoine Pitrou | 45d6156 | 2015-05-20 21:50:59 +0200 | [diff] [blame] | 973 | {"readinto", rawiobase_readinto, METH_VARARGS}, |
| 974 | {"write", rawiobase_write, METH_VARARGS}, |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 975 | {NULL, NULL} |
| 976 | }; |
| 977 | |
| 978 | PyTypeObject PyRawIOBase_Type = { |
| 979 | PyVarObject_HEAD_INIT(NULL, 0) |
| 980 | "_io._RawIOBase", /*tp_name*/ |
| 981 | 0, /*tp_basicsize*/ |
| 982 | 0, /*tp_itemsize*/ |
| 983 | 0, /*tp_dealloc*/ |
| 984 | 0, /*tp_print*/ |
| 985 | 0, /*tp_getattr*/ |
| 986 | 0, /*tp_setattr*/ |
| 987 | 0, /*tp_compare */ |
| 988 | 0, /*tp_repr*/ |
| 989 | 0, /*tp_as_number*/ |
| 990 | 0, /*tp_as_sequence*/ |
| 991 | 0, /*tp_as_mapping*/ |
| 992 | 0, /*tp_hash */ |
| 993 | 0, /*tp_call*/ |
| 994 | 0, /*tp_str*/ |
| 995 | 0, /*tp_getattro*/ |
| 996 | 0, /*tp_setattro*/ |
| 997 | 0, /*tp_as_buffer*/ |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 998 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 999 | rawiobase_doc, /* tp_doc */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 1000 | 0, /* tp_traverse */ |
| 1001 | 0, /* tp_clear */ |
| 1002 | 0, /* tp_richcompare */ |
| 1003 | 0, /* tp_weaklistoffset */ |
| 1004 | 0, /* tp_iter */ |
| 1005 | 0, /* tp_iternext */ |
Benjamin Peterson | 680bf1a | 2009-06-12 02:07:12 +0000 | [diff] [blame] | 1006 | rawiobase_methods, /* tp_methods */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 1007 | 0, /* tp_members */ |
| 1008 | 0, /* tp_getset */ |
| 1009 | &PyIOBase_Type, /* tp_base */ |
| 1010 | 0, /* tp_dict */ |
| 1011 | 0, /* tp_descr_get */ |
| 1012 | 0, /* tp_descr_set */ |
| 1013 | 0, /* tp_dictoffset */ |
| 1014 | 0, /* tp_init */ |
| 1015 | 0, /* tp_alloc */ |
| 1016 | 0, /* tp_new */ |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 1017 | 0, /* tp_free */ |
| 1018 | 0, /* tp_is_gc */ |
| 1019 | 0, /* tp_bases */ |
| 1020 | 0, /* tp_mro */ |
| 1021 | 0, /* tp_cache */ |
| 1022 | 0, /* tp_subclasses */ |
| 1023 | 0, /* tp_weaklist */ |
| 1024 | 0, /* tp_del */ |
| 1025 | 0, /* tp_version_tag */ |
| 1026 | 0, /* tp_finalize */ |
Benjamin Peterson | 4fa88fa | 2009-03-04 00:14:51 +0000 | [diff] [blame] | 1027 | }; |