blob: f3006d0fb5db91e104aab7f6267a6a344ead3e24 [file] [log] [blame]
Guido van Rossumda5b8f22007-06-12 23:30:11 +00001/* File object implementation (what's left of it -- see io.py) */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002
Martin v. Löwis18e16552006-02-15 17:27:45 +00003#define PY_SSIZE_T_CLEAN
Guido van Rossumc0b618a1997-05-02 03:12:38 +00004#include "Python.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00005
Jack Jansen7b8c7542002-04-14 20:12:41 +00006#ifdef HAVE_GETC_UNLOCKED
7#define GETC(f) getc_unlocked(f)
8#define FLOCKFILE(f) flockfile(f)
9#define FUNLOCKFILE(f) funlockfile(f)
10#else
11#define GETC(f) getc(f)
12#define FLOCKFILE(f)
13#define FUNLOCKFILE(f)
14#endif
15
Guido van Rossumda5b8f22007-06-12 23:30:11 +000016/* Newline flags */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000017#define NEWLINE_UNKNOWN 0 /* No newline seen, yet */
18#define NEWLINE_CR 1 /* \r newline seen */
19#define NEWLINE_LF 2 /* \n newline seen */
20#define NEWLINE_CRLF 4 /* \r\n newline seen */
Trent Mickf29f47b2000-08-11 19:02:59 +000021
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000022#ifdef __cplusplus
23extern "C" {
24#endif
25
Guido van Rossumda5b8f22007-06-12 23:30:11 +000026/* External C interface */
Tim Peters59c9a642001-09-13 05:38:56 +000027
28PyObject *
Guido van Rossum40d20bc2007-10-22 00:09:51 +000029PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000030 char *errors, char *newline, int closefd)
Tim Peters59c9a642001-09-13 05:38:56 +000031{
Victor Stinner3603cc52010-08-13 13:34:52 +000032 PyObject *io, *stream;
Martin v. Löwisafe55bb2011-10-09 10:38:36 +020033 _Py_identifier(open);
Guido van Rossum53970392007-06-12 00:28:30 +000034
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000035 io = PyImport_ImportModule("io");
36 if (io == NULL)
37 return NULL;
Martin v. Löwisafe55bb2011-10-09 10:38:36 +020038 stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000039 buffering, encoding, errors,
40 newline, closefd);
41 Py_DECREF(io);
42 if (stream == NULL)
43 return NULL;
Victor Stinner3603cc52010-08-13 13:34:52 +000044 /* ignore name attribute because the name attribute of _BufferedIOMixin
45 and TextIOWrapper is read only */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000046 return stream;
Tim Peters59c9a642001-09-13 05:38:56 +000047}
48
49PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +000050PyFile_GetLine(PyObject *f, int n)
Guido van Rossum0bd24411991-04-04 15:21:57 +000051{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000052 PyObject *result;
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000053
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000054 if (f == NULL) {
55 PyErr_BadInternalCall();
56 return NULL;
57 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000058
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000059 {
60 PyObject *reader;
61 PyObject *args;
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000062
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000063 reader = PyObject_GetAttrString(f, "readline");
64 if (reader == NULL)
65 return NULL;
66 if (n <= 0)
67 args = PyTuple_New(0);
68 else
69 args = Py_BuildValue("(i)", n);
70 if (args == NULL) {
71 Py_DECREF(reader);
72 return NULL;
73 }
74 result = PyEval_CallObject(reader, args);
75 Py_DECREF(reader);
76 Py_DECREF(args);
77 if (result != NULL && !PyBytes_Check(result) &&
78 !PyUnicode_Check(result)) {
79 Py_DECREF(result);
80 result = NULL;
81 PyErr_SetString(PyExc_TypeError,
82 "object.readline() returned non-string");
83 }
84 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000085
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000086 if (n < 0 && result != NULL && PyBytes_Check(result)) {
87 char *s = PyBytes_AS_STRING(result);
88 Py_ssize_t len = PyBytes_GET_SIZE(result);
89 if (len == 0) {
90 Py_DECREF(result);
91 result = NULL;
92 PyErr_SetString(PyExc_EOFError,
93 "EOF when reading a line");
94 }
95 else if (s[len-1] == '\n') {
96 if (result->ob_refcnt == 1)
97 _PyBytes_Resize(&result, len-1);
98 else {
99 PyObject *v;
100 v = PyBytes_FromStringAndSize(s, len-1);
101 Py_DECREF(result);
102 result = v;
103 }
104 }
105 }
106 if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Martin v. Löwisd63a3b82011-09-28 07:41:54 +0200107 Py_ssize_t len = PyUnicode_GET_LENGTH(result);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000108 if (len == 0) {
109 Py_DECREF(result);
110 result = NULL;
111 PyErr_SetString(PyExc_EOFError,
112 "EOF when reading a line");
113 }
Martin v. Löwisd63a3b82011-09-28 07:41:54 +0200114 else if (PyUnicode_READ_CHAR(result, len-1) == '\n') {
115 PyObject *v;
116 v = PyUnicode_Substring(result, 0, len-1);
117 Py_DECREF(result);
118 result = v;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000119 }
120 }
121 return result;
Guido van Rossum0bd24411991-04-04 15:21:57 +0000122}
123
Guido van Rossum3165fe61992-09-25 21:59:05 +0000124/* Interfaces to write objects/strings to file-like objects */
125
126int
Fred Drakefd99de62000-07-09 05:02:18 +0000127PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000128{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000129 PyObject *writer, *value, *args, *result;
130 if (f == NULL) {
131 PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
132 return -1;
133 }
134 writer = PyObject_GetAttrString(f, "write");
135 if (writer == NULL)
136 return -1;
137 if (flags & Py_PRINT_RAW) {
138 value = PyObject_Str(v);
139 }
140 else
141 value = PyObject_Repr(v);
142 if (value == NULL) {
143 Py_DECREF(writer);
144 return -1;
145 }
146 args = PyTuple_Pack(1, value);
147 if (args == NULL) {
148 Py_DECREF(value);
149 Py_DECREF(writer);
150 return -1;
151 }
152 result = PyEval_CallObject(writer, args);
153 Py_DECREF(args);
154 Py_DECREF(value);
155 Py_DECREF(writer);
156 if (result == NULL)
157 return -1;
158 Py_DECREF(result);
159 return 0;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000160}
161
Guido van Rossum27a60b11997-05-22 22:25:11 +0000162int
Tim Petersc1bbcb82001-11-28 22:13:25 +0000163PyFile_WriteString(const char *s, PyObject *f)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000164{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000165 if (f == NULL) {
166 /* Should be caused by a pre-existing error */
167 if (!PyErr_Occurred())
168 PyErr_SetString(PyExc_SystemError,
169 "null file for PyFile_WriteString");
170 return -1;
171 }
172 else if (!PyErr_Occurred()) {
173 PyObject *v = PyUnicode_FromString(s);
174 int err;
175 if (v == NULL)
176 return -1;
177 err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
178 Py_DECREF(v);
179 return err;
180 }
181 else
182 return -1;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000183}
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000184
185/* Try to get a file-descriptor from a Python object. If the object
186 is an integer or long integer, its value is returned. If not, the
187 object's fileno() method is called if it exists; the method must return
188 an integer or long integer, which is returned as the file descriptor value.
189 -1 is returned on failure.
190*/
191
Guido van Rossumda5b8f22007-06-12 23:30:11 +0000192int
193PyObject_AsFileDescriptor(PyObject *o)
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000194{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000195 int fd;
196 PyObject *meth;
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000197
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000198 if (PyLong_Check(o)) {
199 fd = PyLong_AsLong(o);
200 }
201 else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
202 {
203 PyObject *fno = PyEval_CallObject(meth, NULL);
204 Py_DECREF(meth);
205 if (fno == NULL)
206 return -1;
Tim Peters86821b22001-01-07 21:19:34 +0000207
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000208 if (PyLong_Check(fno)) {
209 fd = PyLong_AsLong(fno);
210 Py_DECREF(fno);
211 }
212 else {
213 PyErr_SetString(PyExc_TypeError,
214 "fileno() returned a non-integer");
215 Py_DECREF(fno);
216 return -1;
217 }
218 }
219 else {
220 PyErr_SetString(PyExc_TypeError,
221 "argument must be an int, or have a fileno() method.");
222 return -1;
223 }
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000224
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000225 if (fd == -1 && PyErr_Occurred())
226 return -1;
227 if (fd < 0) {
228 PyErr_Format(PyExc_ValueError,
229 "file descriptor cannot be a negative integer (%i)",
230 fd);
231 return -1;
232 }
233 return fd;
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000234}
Jack Jansen7b8c7542002-04-14 20:12:41 +0000235
Jack Jansen7b8c7542002-04-14 20:12:41 +0000236/*
237** Py_UniversalNewlineFgets is an fgets variation that understands
238** all of \r, \n and \r\n conventions.
239** The stream should be opened in binary mode.
240** If fobj is NULL the routine always does newline conversion, and
241** it may peek one char ahead to gobble the second char in \r\n.
242** If fobj is non-NULL it must be a PyFileObject. In this case there
243** is no readahead but in stead a flag is used to skip a following
244** \n on the next read. Also, if the file is open in binary mode
245** the whole conversion is skipped. Finally, the routine keeps track of
246** the different types of newlines seen.
247** Note that we need no error handling: fgets() treats error and eof
248** identically.
249*/
250char *
251Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
252{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000253 char *p = buf;
254 int c;
255 int newlinetypes = 0;
256 int skipnextlf = 0;
Tim Peters058b1412002-04-21 07:29:14 +0000257
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000258 if (fobj) {
259 errno = ENXIO; /* What can you do... */
260 return NULL;
261 }
262 FLOCKFILE(stream);
263 c = 'x'; /* Shut up gcc warning */
264 while (--n > 0 && (c = GETC(stream)) != EOF ) {
265 if (skipnextlf ) {
266 skipnextlf = 0;
267 if (c == '\n') {
268 /* Seeing a \n here with skipnextlf true
269 ** means we saw a \r before.
270 */
271 newlinetypes |= NEWLINE_CRLF;
272 c = GETC(stream);
273 if (c == EOF) break;
274 } else {
275 /*
276 ** Note that c == EOF also brings us here,
277 ** so we're okay if the last char in the file
278 ** is a CR.
279 */
280 newlinetypes |= NEWLINE_CR;
281 }
282 }
283 if (c == '\r') {
284 /* A \r is translated into a \n, and we skip
285 ** an adjacent \n, if any. We don't set the
286 ** newlinetypes flag until we've seen the next char.
287 */
288 skipnextlf = 1;
289 c = '\n';
290 } else if ( c == '\n') {
291 newlinetypes |= NEWLINE_LF;
292 }
293 *p++ = c;
294 if (c == '\n') break;
295 }
Brett Cannonb94767f2011-02-22 20:15:44 +0000296 /* if ( c == EOF && skipnextlf )
297 newlinetypes |= NEWLINE_CR; */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000298 FUNLOCKFILE(stream);
299 *p = '\0';
300 if ( skipnextlf ) {
301 /* If we have no file object we cannot save the
302 ** skipnextlf flag. We have to readahead, which
303 ** will cause a pause if we're reading from an
304 ** interactive stream, but that is very unlikely
305 ** unless we're doing something silly like
306 ** exec(open("/dev/tty").read()).
307 */
308 c = GETC(stream);
309 if ( c != '\n' )
310 ungetc(c, stream);
311 }
312 if (p == buf)
313 return NULL;
314 return buf;
Jack Jansen7b8c7542002-04-14 20:12:41 +0000315}
316
Christian Heimesaf935e32007-11-12 16:05:45 +0000317/* **************************** std printer ****************************
318 * The stdprinter is used during the boot strapping phase as a preliminary
319 * file like object for sys.stderr.
320 */
Guido van Rossum826d8972007-10-30 18:34:07 +0000321
322typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000323 PyObject_HEAD
324 int fd;
Guido van Rossum826d8972007-10-30 18:34:07 +0000325} PyStdPrinter_Object;
326
327static PyObject *
328stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
329{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000330 PyStdPrinter_Object *self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000331
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000332 assert(type != NULL && type->tp_alloc != NULL);
Guido van Rossum826d8972007-10-30 18:34:07 +0000333
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000334 self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
335 if (self != NULL) {
336 self->fd = -1;
337 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000338
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000339 return (PyObject *) self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000340}
341
Christian Heimesaf935e32007-11-12 16:05:45 +0000342static int
Victor Stinnerdc555402011-01-04 13:15:39 +0000343stdprinter_init(PyObject *self, PyObject *args, PyObject *kwds)
Christian Heimesaf935e32007-11-12 16:05:45 +0000344{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000345 PyErr_SetString(PyExc_TypeError,
346 "cannot create 'stderrprinter' instances");
347 return -1;
Christian Heimesaf935e32007-11-12 16:05:45 +0000348}
349
Guido van Rossum826d8972007-10-30 18:34:07 +0000350PyObject *
351PyFile_NewStdPrinter(int fd)
352{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000353 PyStdPrinter_Object *self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000354
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000355 if (fd != fileno(stdout) && fd != fileno(stderr)) {
356 /* not enough infrastructure for PyErr_BadInternalCall() */
357 return NULL;
358 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000359
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000360 self = PyObject_New(PyStdPrinter_Object,
361 &PyStdPrinter_Type);
362 if (self != NULL) {
363 self->fd = fd;
364 }
365 return (PyObject*)self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000366}
367
Martin v. Löwisff649b42008-06-13 07:24:48 +0000368static PyObject *
Guido van Rossum826d8972007-10-30 18:34:07 +0000369stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
370{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000371 char *c;
372 Py_ssize_t n;
Guido van Rossum826d8972007-10-30 18:34:07 +0000373
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000374 if (self->fd < 0) {
375 /* fd might be invalid on Windows
376 * I can't raise an exception here. It may lead to an
377 * unlimited recursion in the case stderr is invalid.
378 */
379 Py_RETURN_NONE;
380 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000381
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000382 if (!PyArg_ParseTuple(args, "s", &c)) {
383 return NULL;
384 }
385 n = strlen(c);
Guido van Rossum826d8972007-10-30 18:34:07 +0000386
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000387 Py_BEGIN_ALLOW_THREADS
388 errno = 0;
Victor Stinnerdc555402011-01-04 13:15:39 +0000389#if defined(MS_WIN64) || defined(MS_WINDOWS)
390 if (n > INT_MAX)
391 n = INT_MAX;
392 n = write(self->fd, c, (int)n);
393#else
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000394 n = write(self->fd, c, n);
Victor Stinnerdc555402011-01-04 13:15:39 +0000395#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000396 Py_END_ALLOW_THREADS
Guido van Rossum826d8972007-10-30 18:34:07 +0000397
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000398 if (n < 0) {
399 if (errno == EAGAIN)
400 Py_RETURN_NONE;
401 PyErr_SetFromErrno(PyExc_IOError);
402 return NULL;
403 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000404
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000405 return PyLong_FromSsize_t(n);
Christian Heimesaf935e32007-11-12 16:05:45 +0000406}
407
408static PyObject *
409stdprinter_fileno(PyStdPrinter_Object *self)
410{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000411 return PyLong_FromLong((long) self->fd);
Christian Heimesaf935e32007-11-12 16:05:45 +0000412}
413
414static PyObject *
415stdprinter_repr(PyStdPrinter_Object *self)
416{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000417 return PyUnicode_FromFormat("<stdprinter(fd=%d) object at 0x%x>",
418 self->fd, self);
Christian Heimesaf935e32007-11-12 16:05:45 +0000419}
420
421static PyObject *
422stdprinter_noop(PyStdPrinter_Object *self)
423{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000424 Py_RETURN_NONE;
Christian Heimesaf935e32007-11-12 16:05:45 +0000425}
426
427static PyObject *
428stdprinter_isatty(PyStdPrinter_Object *self)
429{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000430 long res;
431 if (self->fd < 0) {
432 Py_RETURN_FALSE;
433 }
Christian Heimesaf935e32007-11-12 16:05:45 +0000434
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000435 Py_BEGIN_ALLOW_THREADS
436 res = isatty(self->fd);
437 Py_END_ALLOW_THREADS
Christian Heimesaf935e32007-11-12 16:05:45 +0000438
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000439 return PyBool_FromLong(res);
Guido van Rossum826d8972007-10-30 18:34:07 +0000440}
441
442static PyMethodDef stdprinter_methods[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000443 {"close", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
444 {"flush", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
445 {"fileno", (PyCFunction)stdprinter_fileno, METH_NOARGS, ""},
446 {"isatty", (PyCFunction)stdprinter_isatty, METH_NOARGS, ""},
447 {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""},
448 {NULL, NULL} /*sentinel */
Christian Heimesaf935e32007-11-12 16:05:45 +0000449};
450
451static PyObject *
452get_closed(PyStdPrinter_Object *self, void *closure)
453{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000454 Py_INCREF(Py_False);
455 return Py_False;
Christian Heimesaf935e32007-11-12 16:05:45 +0000456}
457
458static PyObject *
459get_mode(PyStdPrinter_Object *self, void *closure)
460{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000461 return PyUnicode_FromString("w");
Christian Heimesaf935e32007-11-12 16:05:45 +0000462}
463
464static PyObject *
465get_encoding(PyStdPrinter_Object *self, void *closure)
466{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000467 Py_RETURN_NONE;
Christian Heimesaf935e32007-11-12 16:05:45 +0000468}
469
470static PyGetSetDef stdprinter_getsetlist[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000471 {"closed", (getter)get_closed, NULL, "True if the file is closed"},
472 {"encoding", (getter)get_encoding, NULL, "Encoding of the file"},
473 {"mode", (getter)get_mode, NULL, "String giving the file mode"},
474 {0},
Guido van Rossum826d8972007-10-30 18:34:07 +0000475};
476
477PyTypeObject PyStdPrinter_Type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000478 PyVarObject_HEAD_INIT(&PyType_Type, 0)
479 "stderrprinter", /* tp_name */
480 sizeof(PyStdPrinter_Object), /* tp_basicsize */
481 0, /* tp_itemsize */
482 /* methods */
483 0, /* tp_dealloc */
484 0, /* tp_print */
485 0, /* tp_getattr */
486 0, /* tp_setattr */
487 0, /* tp_reserved */
488 (reprfunc)stdprinter_repr, /* tp_repr */
489 0, /* tp_as_number */
490 0, /* tp_as_sequence */
491 0, /* tp_as_mapping */
492 0, /* tp_hash */
493 0, /* tp_call */
494 0, /* tp_str */
495 PyObject_GenericGetAttr, /* tp_getattro */
496 0, /* tp_setattro */
497 0, /* tp_as_buffer */
498 Py_TPFLAGS_DEFAULT, /* tp_flags */
499 0, /* tp_doc */
500 0, /* tp_traverse */
501 0, /* tp_clear */
502 0, /* tp_richcompare */
503 0, /* tp_weaklistoffset */
504 0, /* tp_iter */
505 0, /* tp_iternext */
506 stdprinter_methods, /* tp_methods */
507 0, /* tp_members */
508 stdprinter_getsetlist, /* tp_getset */
509 0, /* tp_base */
510 0, /* tp_dict */
511 0, /* tp_descr_get */
512 0, /* tp_descr_set */
513 0, /* tp_dictoffset */
Victor Stinnerdc555402011-01-04 13:15:39 +0000514 stdprinter_init, /* tp_init */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000515 PyType_GenericAlloc, /* tp_alloc */
516 stdprinter_new, /* tp_new */
517 PyObject_Del, /* tp_free */
Guido van Rossum826d8972007-10-30 18:34:07 +0000518};
519
520
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000521#ifdef __cplusplus
522}
523#endif