blob: 3a31314086fef3d508e3d0fb471c29904cecf6a9 [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öwisbd928fe2011-10-14 10:20:37 +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;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020062 _Py_IDENTIFIER(readline);
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000063
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +020064 reader = _PyObject_GetAttrId(f, &PyId_readline);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000065 if (reader == NULL)
66 return NULL;
67 if (n <= 0)
68 args = PyTuple_New(0);
69 else
70 args = Py_BuildValue("(i)", n);
71 if (args == NULL) {
72 Py_DECREF(reader);
73 return NULL;
74 }
75 result = PyEval_CallObject(reader, args);
76 Py_DECREF(reader);
77 Py_DECREF(args);
78 if (result != NULL && !PyBytes_Check(result) &&
79 !PyUnicode_Check(result)) {
80 Py_DECREF(result);
81 result = NULL;
82 PyErr_SetString(PyExc_TypeError,
83 "object.readline() returned non-string");
84 }
85 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000086
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000087 if (n < 0 && result != NULL && PyBytes_Check(result)) {
88 char *s = PyBytes_AS_STRING(result);
89 Py_ssize_t len = PyBytes_GET_SIZE(result);
90 if (len == 0) {
91 Py_DECREF(result);
92 result = NULL;
93 PyErr_SetString(PyExc_EOFError,
94 "EOF when reading a line");
95 }
96 else if (s[len-1] == '\n') {
97 if (result->ob_refcnt == 1)
98 _PyBytes_Resize(&result, len-1);
99 else {
100 PyObject *v;
101 v = PyBytes_FromStringAndSize(s, len-1);
102 Py_DECREF(result);
103 result = v;
104 }
105 }
106 }
107 if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Martin v. Löwisd63a3b82011-09-28 07:41:54 +0200108 Py_ssize_t len = PyUnicode_GET_LENGTH(result);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000109 if (len == 0) {
110 Py_DECREF(result);
111 result = NULL;
112 PyErr_SetString(PyExc_EOFError,
113 "EOF when reading a line");
114 }
Martin v. Löwisd63a3b82011-09-28 07:41:54 +0200115 else if (PyUnicode_READ_CHAR(result, len-1) == '\n') {
116 PyObject *v;
117 v = PyUnicode_Substring(result, 0, len-1);
118 Py_DECREF(result);
119 result = v;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000120 }
121 }
122 return result;
Guido van Rossum0bd24411991-04-04 15:21:57 +0000123}
124
Guido van Rossum3165fe61992-09-25 21:59:05 +0000125/* Interfaces to write objects/strings to file-like objects */
126
127int
Fred Drakefd99de62000-07-09 05:02:18 +0000128PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000129{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000130 PyObject *writer, *value, *args, *result;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200131 _Py_IDENTIFIER(write);
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +0200132
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000133 if (f == NULL) {
134 PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
135 return -1;
136 }
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +0200137 writer = _PyObject_GetAttrId(f, &PyId_write);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000138 if (writer == NULL)
139 return -1;
140 if (flags & Py_PRINT_RAW) {
141 value = PyObject_Str(v);
142 }
143 else
144 value = PyObject_Repr(v);
145 if (value == NULL) {
146 Py_DECREF(writer);
147 return -1;
148 }
149 args = PyTuple_Pack(1, value);
150 if (args == NULL) {
151 Py_DECREF(value);
152 Py_DECREF(writer);
153 return -1;
154 }
155 result = PyEval_CallObject(writer, args);
156 Py_DECREF(args);
157 Py_DECREF(value);
158 Py_DECREF(writer);
159 if (result == NULL)
160 return -1;
161 Py_DECREF(result);
162 return 0;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000163}
164
Guido van Rossum27a60b11997-05-22 22:25:11 +0000165int
Tim Petersc1bbcb82001-11-28 22:13:25 +0000166PyFile_WriteString(const char *s, PyObject *f)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000167{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000168 if (f == NULL) {
169 /* Should be caused by a pre-existing error */
170 if (!PyErr_Occurred())
171 PyErr_SetString(PyExc_SystemError,
172 "null file for PyFile_WriteString");
173 return -1;
174 }
175 else if (!PyErr_Occurred()) {
176 PyObject *v = PyUnicode_FromString(s);
177 int err;
178 if (v == NULL)
179 return -1;
180 err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
181 Py_DECREF(v);
182 return err;
183 }
184 else
185 return -1;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000186}
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000187
188/* Try to get a file-descriptor from a Python object. If the object
189 is an integer or long integer, its value is returned. If not, the
190 object's fileno() method is called if it exists; the method must return
191 an integer or long integer, which is returned as the file descriptor value.
192 -1 is returned on failure.
193*/
194
Guido van Rossumda5b8f22007-06-12 23:30:11 +0000195int
196PyObject_AsFileDescriptor(PyObject *o)
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000197{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000198 int fd;
199 PyObject *meth;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200200 _Py_IDENTIFIER(fileno);
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000201
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000202 if (PyLong_Check(o)) {
Serhiy Storchaka78980432013-01-15 01:12:17 +0200203 fd = _PyLong_AsInt(o);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000204 }
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +0200205 else if ((meth = _PyObject_GetAttrId(o, &PyId_fileno)) != NULL)
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000206 {
207 PyObject *fno = PyEval_CallObject(meth, NULL);
208 Py_DECREF(meth);
209 if (fno == NULL)
210 return -1;
Tim Peters86821b22001-01-07 21:19:34 +0000211
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000212 if (PyLong_Check(fno)) {
Serhiy Storchaka78980432013-01-15 01:12:17 +0200213 fd = _PyLong_AsInt(fno);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000214 Py_DECREF(fno);
215 }
216 else {
217 PyErr_SetString(PyExc_TypeError,
218 "fileno() returned a non-integer");
219 Py_DECREF(fno);
220 return -1;
221 }
222 }
223 else {
224 PyErr_SetString(PyExc_TypeError,
225 "argument must be an int, or have a fileno() method.");
226 return -1;
227 }
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000228
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000229 if (fd == -1 && PyErr_Occurred())
230 return -1;
231 if (fd < 0) {
232 PyErr_Format(PyExc_ValueError,
233 "file descriptor cannot be a negative integer (%i)",
234 fd);
235 return -1;
236 }
237 return fd;
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000238}
Jack Jansen7b8c7542002-04-14 20:12:41 +0000239
Jack Jansen7b8c7542002-04-14 20:12:41 +0000240/*
241** Py_UniversalNewlineFgets is an fgets variation that understands
242** all of \r, \n and \r\n conventions.
243** The stream should be opened in binary mode.
244** If fobj is NULL the routine always does newline conversion, and
245** it may peek one char ahead to gobble the second char in \r\n.
246** If fobj is non-NULL it must be a PyFileObject. In this case there
247** is no readahead but in stead a flag is used to skip a following
248** \n on the next read. Also, if the file is open in binary mode
249** the whole conversion is skipped. Finally, the routine keeps track of
250** the different types of newlines seen.
251** Note that we need no error handling: fgets() treats error and eof
252** identically.
253*/
254char *
255Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
256{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000257 char *p = buf;
258 int c;
259 int newlinetypes = 0;
260 int skipnextlf = 0;
Tim Peters058b1412002-04-21 07:29:14 +0000261
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000262 if (fobj) {
263 errno = ENXIO; /* What can you do... */
264 return NULL;
265 }
266 FLOCKFILE(stream);
267 c = 'x'; /* Shut up gcc warning */
268 while (--n > 0 && (c = GETC(stream)) != EOF ) {
269 if (skipnextlf ) {
270 skipnextlf = 0;
271 if (c == '\n') {
272 /* Seeing a \n here with skipnextlf true
273 ** means we saw a \r before.
274 */
275 newlinetypes |= NEWLINE_CRLF;
276 c = GETC(stream);
277 if (c == EOF) break;
278 } else {
279 /*
280 ** Note that c == EOF also brings us here,
281 ** so we're okay if the last char in the file
282 ** is a CR.
283 */
284 newlinetypes |= NEWLINE_CR;
285 }
286 }
287 if (c == '\r') {
288 /* A \r is translated into a \n, and we skip
289 ** an adjacent \n, if any. We don't set the
290 ** newlinetypes flag until we've seen the next char.
291 */
292 skipnextlf = 1;
293 c = '\n';
294 } else if ( c == '\n') {
295 newlinetypes |= NEWLINE_LF;
296 }
297 *p++ = c;
298 if (c == '\n') break;
299 }
Brett Cannonb94767f2011-02-22 20:15:44 +0000300 /* if ( c == EOF && skipnextlf )
301 newlinetypes |= NEWLINE_CR; */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000302 FUNLOCKFILE(stream);
303 *p = '\0';
304 if ( skipnextlf ) {
305 /* If we have no file object we cannot save the
306 ** skipnextlf flag. We have to readahead, which
307 ** will cause a pause if we're reading from an
308 ** interactive stream, but that is very unlikely
309 ** unless we're doing something silly like
310 ** exec(open("/dev/tty").read()).
311 */
312 c = GETC(stream);
313 if ( c != '\n' )
314 ungetc(c, stream);
315 }
316 if (p == buf)
317 return NULL;
318 return buf;
Jack Jansen7b8c7542002-04-14 20:12:41 +0000319}
320
Christian Heimesaf935e32007-11-12 16:05:45 +0000321/* **************************** std printer ****************************
322 * The stdprinter is used during the boot strapping phase as a preliminary
323 * file like object for sys.stderr.
324 */
Guido van Rossum826d8972007-10-30 18:34:07 +0000325
326typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000327 PyObject_HEAD
328 int fd;
Guido van Rossum826d8972007-10-30 18:34:07 +0000329} PyStdPrinter_Object;
330
331static PyObject *
332stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
333{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000334 PyStdPrinter_Object *self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000335
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000336 assert(type != NULL && type->tp_alloc != NULL);
Guido van Rossum826d8972007-10-30 18:34:07 +0000337
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000338 self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
339 if (self != NULL) {
340 self->fd = -1;
341 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000342
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000343 return (PyObject *) self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000344}
345
Christian Heimesaf935e32007-11-12 16:05:45 +0000346static int
Victor Stinnerdc555402011-01-04 13:15:39 +0000347stdprinter_init(PyObject *self, PyObject *args, PyObject *kwds)
Christian Heimesaf935e32007-11-12 16:05:45 +0000348{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000349 PyErr_SetString(PyExc_TypeError,
350 "cannot create 'stderrprinter' instances");
351 return -1;
Christian Heimesaf935e32007-11-12 16:05:45 +0000352}
353
Guido van Rossum826d8972007-10-30 18:34:07 +0000354PyObject *
355PyFile_NewStdPrinter(int fd)
356{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000357 PyStdPrinter_Object *self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000358
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000359 if (fd != fileno(stdout) && fd != fileno(stderr)) {
360 /* not enough infrastructure for PyErr_BadInternalCall() */
361 return NULL;
362 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000363
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000364 self = PyObject_New(PyStdPrinter_Object,
365 &PyStdPrinter_Type);
366 if (self != NULL) {
367 self->fd = fd;
368 }
369 return (PyObject*)self;
Guido van Rossum826d8972007-10-30 18:34:07 +0000370}
371
Martin v. Löwisff649b42008-06-13 07:24:48 +0000372static PyObject *
Guido van Rossum826d8972007-10-30 18:34:07 +0000373stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
374{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000375 char *c;
376 Py_ssize_t n;
Guido van Rossum826d8972007-10-30 18:34:07 +0000377
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000378 if (self->fd < 0) {
379 /* fd might be invalid on Windows
380 * I can't raise an exception here. It may lead to an
381 * unlimited recursion in the case stderr is invalid.
382 */
383 Py_RETURN_NONE;
384 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000385
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000386 if (!PyArg_ParseTuple(args, "s", &c)) {
387 return NULL;
388 }
389 n = strlen(c);
Guido van Rossum826d8972007-10-30 18:34:07 +0000390
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000391 Py_BEGIN_ALLOW_THREADS
392 errno = 0;
Victor Stinnerdc555402011-01-04 13:15:39 +0000393#if defined(MS_WIN64) || defined(MS_WINDOWS)
394 if (n > INT_MAX)
395 n = INT_MAX;
396 n = write(self->fd, c, (int)n);
397#else
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000398 n = write(self->fd, c, n);
Victor Stinnerdc555402011-01-04 13:15:39 +0000399#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000400 Py_END_ALLOW_THREADS
Guido van Rossum826d8972007-10-30 18:34:07 +0000401
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000402 if (n < 0) {
403 if (errno == EAGAIN)
404 Py_RETURN_NONE;
405 PyErr_SetFromErrno(PyExc_IOError);
406 return NULL;
407 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000408
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000409 return PyLong_FromSsize_t(n);
Christian Heimesaf935e32007-11-12 16:05:45 +0000410}
411
412static PyObject *
413stdprinter_fileno(PyStdPrinter_Object *self)
414{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000415 return PyLong_FromLong((long) self->fd);
Christian Heimesaf935e32007-11-12 16:05:45 +0000416}
417
418static PyObject *
419stdprinter_repr(PyStdPrinter_Object *self)
420{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000421 return PyUnicode_FromFormat("<stdprinter(fd=%d) object at 0x%x>",
422 self->fd, self);
Christian Heimesaf935e32007-11-12 16:05:45 +0000423}
424
425static PyObject *
426stdprinter_noop(PyStdPrinter_Object *self)
427{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000428 Py_RETURN_NONE;
Christian Heimesaf935e32007-11-12 16:05:45 +0000429}
430
431static PyObject *
432stdprinter_isatty(PyStdPrinter_Object *self)
433{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000434 long res;
435 if (self->fd < 0) {
436 Py_RETURN_FALSE;
437 }
Christian Heimesaf935e32007-11-12 16:05:45 +0000438
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000439 Py_BEGIN_ALLOW_THREADS
440 res = isatty(self->fd);
441 Py_END_ALLOW_THREADS
Christian Heimesaf935e32007-11-12 16:05:45 +0000442
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000443 return PyBool_FromLong(res);
Guido van Rossum826d8972007-10-30 18:34:07 +0000444}
445
446static PyMethodDef stdprinter_methods[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000447 {"close", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
448 {"flush", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
449 {"fileno", (PyCFunction)stdprinter_fileno, METH_NOARGS, ""},
450 {"isatty", (PyCFunction)stdprinter_isatty, METH_NOARGS, ""},
451 {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""},
452 {NULL, NULL} /*sentinel */
Christian Heimesaf935e32007-11-12 16:05:45 +0000453};
454
455static PyObject *
456get_closed(PyStdPrinter_Object *self, void *closure)
457{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000458 Py_INCREF(Py_False);
459 return Py_False;
Christian Heimesaf935e32007-11-12 16:05:45 +0000460}
461
462static PyObject *
463get_mode(PyStdPrinter_Object *self, void *closure)
464{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000465 return PyUnicode_FromString("w");
Christian Heimesaf935e32007-11-12 16:05:45 +0000466}
467
468static PyObject *
469get_encoding(PyStdPrinter_Object *self, void *closure)
470{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000471 Py_RETURN_NONE;
Christian Heimesaf935e32007-11-12 16:05:45 +0000472}
473
474static PyGetSetDef stdprinter_getsetlist[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000475 {"closed", (getter)get_closed, NULL, "True if the file is closed"},
476 {"encoding", (getter)get_encoding, NULL, "Encoding of the file"},
477 {"mode", (getter)get_mode, NULL, "String giving the file mode"},
478 {0},
Guido van Rossum826d8972007-10-30 18:34:07 +0000479};
480
481PyTypeObject PyStdPrinter_Type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000482 PyVarObject_HEAD_INIT(&PyType_Type, 0)
483 "stderrprinter", /* tp_name */
484 sizeof(PyStdPrinter_Object), /* tp_basicsize */
485 0, /* tp_itemsize */
486 /* methods */
487 0, /* tp_dealloc */
488 0, /* tp_print */
489 0, /* tp_getattr */
490 0, /* tp_setattr */
491 0, /* tp_reserved */
492 (reprfunc)stdprinter_repr, /* tp_repr */
493 0, /* tp_as_number */
494 0, /* tp_as_sequence */
495 0, /* tp_as_mapping */
496 0, /* tp_hash */
497 0, /* tp_call */
498 0, /* tp_str */
499 PyObject_GenericGetAttr, /* tp_getattro */
500 0, /* tp_setattro */
501 0, /* tp_as_buffer */
502 Py_TPFLAGS_DEFAULT, /* tp_flags */
503 0, /* tp_doc */
504 0, /* tp_traverse */
505 0, /* tp_clear */
506 0, /* tp_richcompare */
507 0, /* tp_weaklistoffset */
508 0, /* tp_iter */
509 0, /* tp_iternext */
510 stdprinter_methods, /* tp_methods */
511 0, /* tp_members */
512 stdprinter_getsetlist, /* tp_getset */
513 0, /* tp_base */
514 0, /* tp_dict */
515 0, /* tp_descr_get */
516 0, /* tp_descr_set */
517 0, /* tp_dictoffset */
Victor Stinnerdc555402011-01-04 13:15:39 +0000518 stdprinter_init, /* tp_init */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000519 PyType_GenericAlloc, /* tp_alloc */
520 stdprinter_new, /* tp_new */
521 PyObject_Del, /* tp_free */
Guido van Rossum826d8972007-10-30 18:34:07 +0000522};
523
524
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000525#ifdef __cplusplus
526}
527#endif