blob: 5d69911ff66e69f658c05f2473cae6b7f5833b38 [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 */
Jack Jansen7b8c7542002-04-14 20:12:41 +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,
Guido van Rossum2dced8b2007-10-30 17:27:30 +000030 char *newline, int closefd)
Tim Peters59c9a642001-09-13 05:38:56 +000031{
Guido van Rossum40d20bc2007-10-22 00:09:51 +000032 PyObject *io, *stream, *nameobj = NULL;
Guido van Rossum53970392007-06-12 00:28:30 +000033
34 io = PyImport_ImportModule("io");
35 if (io == NULL)
36 return NULL;
Guido van Rossum2dced8b2007-10-30 17:27:30 +000037 stream = PyObject_CallMethod(io, "open", "isissi", fd, mode,
38 buffering, encoding, newline, closefd);
Guido van Rossumce3a72a2007-10-19 23:16:50 +000039 Py_DECREF(io);
Guido van Rossumda5b8f22007-06-12 23:30:11 +000040 if (stream == NULL)
Guido van Rossum53970392007-06-12 00:28:30 +000041 return NULL;
Guido van Rossumce3a72a2007-10-19 23:16:50 +000042 if (name != NULL) {
43 nameobj = PyUnicode_FromString(name);
44 if (nameobj == NULL)
Guido van Rossumda5b8f22007-06-12 23:30:11 +000045 PyErr_Clear();
Guido van Rossumce3a72a2007-10-19 23:16:50 +000046 else {
47 if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
48 PyErr_Clear();
49 Py_DECREF(nameobj);
50 }
Tim Peters59c9a642001-09-13 05:38:56 +000051 }
Guido van Rossum53970392007-06-12 00:28:30 +000052 return stream;
Tim Peters59c9a642001-09-13 05:38:56 +000053}
54
55PyObject *
Fred Drakefd99de62000-07-09 05:02:18 +000056PyFile_GetLine(PyObject *f, int n)
Guido van Rossum0bd24411991-04-04 15:21:57 +000057{
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000058 PyObject *result;
59
Guido van Rossum3165fe61992-09-25 21:59:05 +000060 if (f == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +000061 PyErr_BadInternalCall();
Guido van Rossum0bd24411991-04-04 15:21:57 +000062 return NULL;
63 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000064
Guido van Rossumda5b8f22007-06-12 23:30:11 +000065 {
Guido van Rossumc0b618a1997-05-02 03:12:38 +000066 PyObject *reader;
67 PyObject *args;
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000068
Guido van Rossumc0b618a1997-05-02 03:12:38 +000069 reader = PyObject_GetAttrString(f, "readline");
Guido van Rossum3165fe61992-09-25 21:59:05 +000070 if (reader == NULL)
71 return NULL;
72 if (n <= 0)
Raymond Hettinger8ae46892003-10-12 19:09:37 +000073 args = PyTuple_New(0);
Guido van Rossum3165fe61992-09-25 21:59:05 +000074 else
Guido van Rossumc0b618a1997-05-02 03:12:38 +000075 args = Py_BuildValue("(i)", n);
Guido van Rossum3165fe61992-09-25 21:59:05 +000076 if (args == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +000077 Py_DECREF(reader);
Guido van Rossum3165fe61992-09-25 21:59:05 +000078 return NULL;
79 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +000080 result = PyEval_CallObject(reader, args);
81 Py_DECREF(reader);
82 Py_DECREF(args);
Martin v. Löwisaf6a27a2003-01-03 19:16:14 +000083 if (result != NULL && !PyString_Check(result) &&
84 !PyUnicode_Check(result)) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +000085 Py_DECREF(result);
Guido van Rossum3165fe61992-09-25 21:59:05 +000086 result = NULL;
Guido van Rossumc0b618a1997-05-02 03:12:38 +000087 PyErr_SetString(PyExc_TypeError,
Guido van Rossum3165fe61992-09-25 21:59:05 +000088 "object.readline() returned non-string");
89 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000090 }
91
92 if (n < 0 && result != NULL && PyString_Check(result)) {
93 char *s = PyString_AS_STRING(result);
Martin v. Löwis18e16552006-02-15 17:27:45 +000094 Py_ssize_t len = PyString_GET_SIZE(result);
Guido van Rossum4ddf0a02001-01-07 20:51:39 +000095 if (len == 0) {
96 Py_DECREF(result);
97 result = NULL;
98 PyErr_SetString(PyExc_EOFError,
99 "EOF when reading a line");
100 }
101 else if (s[len-1] == '\n') {
102 if (result->ob_refcnt == 1)
103 _PyString_Resize(&result, len-1);
104 else {
105 PyObject *v;
106 v = PyString_FromStringAndSize(s, len-1);
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000107 Py_DECREF(result);
Guido van Rossum4ddf0a02001-01-07 20:51:39 +0000108 result = v;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000109 }
110 }
Guido van Rossum3165fe61992-09-25 21:59:05 +0000111 }
Martin v. Löwisaf6a27a2003-01-03 19:16:14 +0000112 if (n < 0 && result != NULL && PyUnicode_Check(result)) {
113 Py_UNICODE *s = PyUnicode_AS_UNICODE(result);
Martin v. Löwis18e16552006-02-15 17:27:45 +0000114 Py_ssize_t len = PyUnicode_GET_SIZE(result);
Martin v. Löwisaf6a27a2003-01-03 19:16:14 +0000115 if (len == 0) {
116 Py_DECREF(result);
117 result = NULL;
118 PyErr_SetString(PyExc_EOFError,
119 "EOF when reading a line");
120 }
121 else if (s[len-1] == '\n') {
122 if (result->ob_refcnt == 1)
123 PyUnicode_Resize(&result, len-1);
124 else {
125 PyObject *v;
126 v = PyUnicode_FromUnicode(s, len-1);
127 Py_DECREF(result);
128 result = v;
129 }
130 }
131 }
Guido van Rossum4ddf0a02001-01-07 20:51:39 +0000132 return result;
Guido van Rossum0bd24411991-04-04 15:21:57 +0000133}
134
Guido van Rossum3165fe61992-09-25 21:59:05 +0000135/* Interfaces to write objects/strings to file-like objects */
136
137int
Fred Drakefd99de62000-07-09 05:02:18 +0000138PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000139{
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000140 PyObject *writer, *value, *args, *result;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000141 if (f == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000142 PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
Guido van Rossum3165fe61992-09-25 21:59:05 +0000143 return -1;
144 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000145 writer = PyObject_GetAttrString(f, "write");
Guido van Rossum3165fe61992-09-25 21:59:05 +0000146 if (writer == NULL)
147 return -1;
Martin v. Löwis2777c022001-09-19 13:47:32 +0000148 if (flags & Py_PRINT_RAW) {
Guido van Rossum98297ee2007-11-06 21:34:58 +0000149 value = PyObject_Str(v);
Martin v. Löwis2777c022001-09-19 13:47:32 +0000150 }
Guido van Rossum55b4a7b2007-07-11 09:28:11 +0000151 else
Guido van Rossume518bf32007-10-09 21:55:58 +0000152 value = PyObject_Repr(v);
Guido van Rossumc6004111993-11-05 10:22:19 +0000153 if (value == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000154 Py_DECREF(writer);
Guido van Rossumc6004111993-11-05 10:22:19 +0000155 return -1;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000156 }
Raymond Hettinger8ae46892003-10-12 19:09:37 +0000157 args = PyTuple_Pack(1, value);
Guido van Rossume9eec541997-05-22 14:02:25 +0000158 if (args == NULL) {
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000159 Py_DECREF(value);
160 Py_DECREF(writer);
Guido van Rossumd3f9a1a1995-07-10 23:32:26 +0000161 return -1;
162 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000163 result = PyEval_CallObject(writer, args);
164 Py_DECREF(args);
165 Py_DECREF(value);
166 Py_DECREF(writer);
Guido van Rossum3165fe61992-09-25 21:59:05 +0000167 if (result == NULL)
168 return -1;
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000169 Py_DECREF(result);
Guido van Rossum3165fe61992-09-25 21:59:05 +0000170 return 0;
171}
172
Guido van Rossum27a60b11997-05-22 22:25:11 +0000173int
Tim Petersc1bbcb82001-11-28 22:13:25 +0000174PyFile_WriteString(const char *s, PyObject *f)
Guido van Rossum3165fe61992-09-25 21:59:05 +0000175{
176 if (f == NULL) {
Guido van Rossum27a60b11997-05-22 22:25:11 +0000177 /* Should be caused by a pre-existing error */
Fred Drakefd99de62000-07-09 05:02:18 +0000178 if (!PyErr_Occurred())
Guido van Rossum27a60b11997-05-22 22:25:11 +0000179 PyErr_SetString(PyExc_SystemError,
180 "null file for PyFile_WriteString");
181 return -1;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000182 }
Guido van Rossumc0b618a1997-05-02 03:12:38 +0000183 else if (!PyErr_Occurred()) {
Guido van Rossum11019802007-08-09 22:58:05 +0000184 PyObject *v = PyUnicode_FromString(s);
Guido van Rossum27a60b11997-05-22 22:25:11 +0000185 int err;
186 if (v == NULL)
187 return -1;
188 err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
189 Py_DECREF(v);
190 return err;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000191 }
Guido van Rossum74ba2471997-07-13 03:56:50 +0000192 else
193 return -1;
Guido van Rossum3165fe61992-09-25 21:59:05 +0000194}
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000195
196/* Try to get a file-descriptor from a Python object. If the object
197 is an integer or long integer, its value is returned. If not, the
198 object's fileno() method is called if it exists; the method must return
199 an integer or long integer, which is returned as the file descriptor value.
200 -1 is returned on failure.
201*/
202
Guido van Rossumda5b8f22007-06-12 23:30:11 +0000203int
204PyObject_AsFileDescriptor(PyObject *o)
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000205{
206 int fd;
207 PyObject *meth;
208
Georg Brandlb6538a82007-10-23 18:25:20 +0000209 if (PyLong_Check(o)) {
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000210 fd = PyLong_AsLong(o);
211 }
212 else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
213 {
214 PyObject *fno = PyEval_CallObject(meth, NULL);
215 Py_DECREF(meth);
216 if (fno == NULL)
217 return -1;
Tim Peters86821b22001-01-07 21:19:34 +0000218
Georg Brandlb6538a82007-10-23 18:25:20 +0000219 if (PyLong_Check(fno)) {
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000220 fd = PyLong_AsLong(fno);
221 Py_DECREF(fno);
222 }
223 else {
224 PyErr_SetString(PyExc_TypeError,
225 "fileno() returned a non-integer");
226 Py_DECREF(fno);
227 return -1;
228 }
229 }
230 else {
231 PyErr_SetString(PyExc_TypeError,
232 "argument must be an int, or have a fileno() method.");
233 return -1;
234 }
235
Guido van Rossumddefaf32007-01-14 03:31:43 +0000236 if (fd == -1 && PyErr_Occurred())
237 return -1;
Andrew M. Kuchling06051ed2000-07-13 23:56:54 +0000238 if (fd < 0) {
239 PyErr_Format(PyExc_ValueError,
240 "file descriptor cannot be a negative integer (%i)",
241 fd);
242 return -1;
243 }
244 return fd;
245}
Jack Jansen7b8c7542002-04-14 20:12:41 +0000246
Jack Jansen7b8c7542002-04-14 20:12:41 +0000247/*
248** Py_UniversalNewlineFgets is an fgets variation that understands
249** all of \r, \n and \r\n conventions.
250** The stream should be opened in binary mode.
251** If fobj is NULL the routine always does newline conversion, and
252** it may peek one char ahead to gobble the second char in \r\n.
253** If fobj is non-NULL it must be a PyFileObject. In this case there
254** is no readahead but in stead a flag is used to skip a following
255** \n on the next read. Also, if the file is open in binary mode
256** the whole conversion is skipped. Finally, the routine keeps track of
257** the different types of newlines seen.
258** Note that we need no error handling: fgets() treats error and eof
259** identically.
260*/
261char *
262Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
263{
264 char *p = buf;
265 int c;
266 int newlinetypes = 0;
267 int skipnextlf = 0;
Tim Peters058b1412002-04-21 07:29:14 +0000268
Jack Jansen7b8c7542002-04-14 20:12:41 +0000269 if (fobj) {
Guido van Rossumda5b8f22007-06-12 23:30:11 +0000270 errno = ENXIO; /* What can you do... */
271 return NULL;
Jack Jansen7b8c7542002-04-14 20:12:41 +0000272 }
273 FLOCKFILE(stream);
274 c = 'x'; /* Shut up gcc warning */
275 while (--n > 0 && (c = GETC(stream)) != EOF ) {
276 if (skipnextlf ) {
277 skipnextlf = 0;
278 if (c == '\n') {
279 /* Seeing a \n here with skipnextlf true
280 ** means we saw a \r before.
281 */
282 newlinetypes |= NEWLINE_CRLF;
283 c = GETC(stream);
284 if (c == EOF) break;
285 } else {
286 /*
287 ** Note that c == EOF also brings us here,
288 ** so we're okay if the last char in the file
289 ** is a CR.
290 */
291 newlinetypes |= NEWLINE_CR;
292 }
293 }
294 if (c == '\r') {
295 /* A \r is translated into a \n, and we skip
296 ** an adjacent \n, if any. We don't set the
297 ** newlinetypes flag until we've seen the next char.
298 */
299 skipnextlf = 1;
300 c = '\n';
301 } else if ( c == '\n') {
302 newlinetypes |= NEWLINE_LF;
303 }
304 *p++ = c;
305 if (c == '\n') break;
306 }
307 if ( c == EOF && skipnextlf )
308 newlinetypes |= NEWLINE_CR;
309 FUNLOCKFILE(stream);
310 *p = '\0';
Guido van Rossumda5b8f22007-06-12 23:30:11 +0000311 if ( skipnextlf ) {
Jack Jansen7b8c7542002-04-14 20:12:41 +0000312 /* If we have no file object we cannot save the
313 ** skipnextlf flag. We have to readahead, which
314 ** will cause a pause if we're reading from an
315 ** interactive stream, but that is very unlikely
316 ** unless we're doing something silly like
Neal Norwitz01688022007-08-12 00:43:29 +0000317 ** exec(open("/dev/tty").read()).
Jack Jansen7b8c7542002-04-14 20:12:41 +0000318 */
319 c = GETC(stream);
320 if ( c != '\n' )
321 ungetc(c, stream);
322 }
323 if (p == buf)
324 return NULL;
325 return buf;
326}
327
Christian Heimesaf935e32007-11-12 16:05:45 +0000328/* **************************** std printer ****************************
329 * The stdprinter is used during the boot strapping phase as a preliminary
330 * file like object for sys.stderr.
331 */
Guido van Rossum826d8972007-10-30 18:34:07 +0000332
333typedef struct {
334 PyObject_HEAD
335 int fd;
336} PyStdPrinter_Object;
337
338static PyObject *
339stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
340{
341 PyStdPrinter_Object *self;
342
343 assert(type != NULL && type->tp_alloc != NULL);
344
345 self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
346 if (self != NULL) {
347 self->fd = -1;
348 }
349
350 return (PyObject *) self;
351}
352
Christian Heimesaf935e32007-11-12 16:05:45 +0000353static int
354fileio_init(PyObject *self, PyObject *args, PyObject *kwds)
355{
356 PyErr_SetString(PyExc_TypeError,
357 "cannot create 'stderrprinter' instances");
358 return -1;
359}
360
Guido van Rossum826d8972007-10-30 18:34:07 +0000361PyObject *
362PyFile_NewStdPrinter(int fd)
363{
364 PyStdPrinter_Object *self;
365
Christian Heimes58cb1b82007-11-13 02:19:40 +0000366 if (fd != fileno(stdout) && fd != fileno(stderr)) {
Christian Heimese018b302007-11-10 00:30:14 +0000367 /* not enough infrastructure for PyErr_BadInternalCall() */
Guido van Rossum826d8972007-10-30 18:34:07 +0000368 return NULL;
369 }
370
371 self = PyObject_New(PyStdPrinter_Object,
372 &PyStdPrinter_Type);
Guido van Rossumc6ecfcd2007-10-30 18:36:44 +0000373 if (self != NULL) {
374 self->fd = fd;
375 }
Guido van Rossum826d8972007-10-30 18:34:07 +0000376 return (PyObject*)self;
377}
378
379PyObject *
380stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
381{
382 char *c;
383 Py_ssize_t n;
384
385 if (self->fd < 0) {
Christian Heimesaf935e32007-11-12 16:05:45 +0000386 /* fd might be invalid on Windows
387 * I can't raise an exception here. It may lead to an
388 * unlimited recursion in the case stderr is invalid.
389 */
Christian Heimes16072782007-11-12 17:02:51 +0000390 Py_RETURN_NONE;
Guido van Rossum826d8972007-10-30 18:34:07 +0000391 }
392
Christian Heimesaf935e32007-11-12 16:05:45 +0000393 if (!PyArg_ParseTuple(args, "s", &c)) {
Guido van Rossum826d8972007-10-30 18:34:07 +0000394 return NULL;
395 }
Christian Heimesaf935e32007-11-12 16:05:45 +0000396 n = strlen(c);
Guido van Rossum826d8972007-10-30 18:34:07 +0000397
398 Py_BEGIN_ALLOW_THREADS
399 errno = 0;
400 n = write(self->fd, c, n);
401 Py_END_ALLOW_THREADS
402
403 if (n < 0) {
404 if (errno == EAGAIN)
405 Py_RETURN_NONE;
406 PyErr_SetFromErrno(PyExc_IOError);
407 return NULL;
408 }
409
Christian Heimesaf935e32007-11-12 16:05:45 +0000410 return PyLong_FromSsize_t(n);
411}
412
413static PyObject *
414stdprinter_fileno(PyStdPrinter_Object *self)
415{
416 return PyInt_FromLong((long) self->fd);
417}
418
419static PyObject *
420stdprinter_repr(PyStdPrinter_Object *self)
421{
422 return PyUnicode_FromFormat("<stdprinter(fd=%d) object at 0x%x>",
423 self->fd, self);
424}
425
426static PyObject *
427stdprinter_noop(PyStdPrinter_Object *self)
428{
429 Py_RETURN_NONE;
430}
431
432static PyObject *
433stdprinter_isatty(PyStdPrinter_Object *self)
434{
435 long res;
436 if (self->fd < 0) {
Christian Heimes16072782007-11-12 17:02:51 +0000437 Py_RETURN_FALSE;
Christian Heimesaf935e32007-11-12 16:05:45 +0000438 }
439
440 Py_BEGIN_ALLOW_THREADS
441 res = isatty(self->fd);
442 Py_END_ALLOW_THREADS
443
444 return PyBool_FromLong(res);
Guido van Rossum826d8972007-10-30 18:34:07 +0000445}
446
447static PyMethodDef stdprinter_methods[] = {
Christian Heimesaf935e32007-11-12 16:05:45 +0000448 {"close", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
449 {"flush", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
450 {"fileno", (PyCFunction)stdprinter_fileno, METH_NOARGS, ""},
451 {"isatty", (PyCFunction)stdprinter_isatty, METH_NOARGS, ""},
452 {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""},
453 {NULL, NULL} /*sentinel */
454};
455
456static PyObject *
457get_closed(PyStdPrinter_Object *self, void *closure)
458{
459 Py_INCREF(Py_False);
460 return Py_False;
461}
462
463static PyObject *
464get_mode(PyStdPrinter_Object *self, void *closure)
465{
466 return PyUnicode_FromString("w");
467}
468
469static PyObject *
470get_encoding(PyStdPrinter_Object *self, void *closure)
471{
472 Py_RETURN_NONE;
473}
474
475static PyGetSetDef stdprinter_getsetlist[] = {
476 {"closed", (getter)get_closed, NULL, "True if the file is closed"},
477 {"encoding", (getter)get_encoding, NULL, "Encoding of the file"},
478 {"mode", (getter)get_mode, NULL, "String giving the file mode"},
479 {0},
Guido van Rossum826d8972007-10-30 18:34:07 +0000480};
481
482PyTypeObject PyStdPrinter_Type = {
483 PyVarObject_HEAD_INIT(&PyType_Type, 0)
484 "stderrprinter", /* tp_name */
485 sizeof(PyStdPrinter_Object), /* tp_basicsize */
486 0, /* tp_itemsize */
487 /* methods */
488 0, /* tp_dealloc */
489 0, /* tp_print */
490 0, /* tp_getattr */
491 0, /* tp_setattr */
492 0, /* tp_compare */
Christian Heimesaf935e32007-11-12 16:05:45 +0000493 (reprfunc)stdprinter_repr, /* tp_repr */
Guido van Rossum826d8972007-10-30 18:34:07 +0000494 0, /* tp_as_number */
495 0, /* tp_as_sequence */
496 0, /* tp_as_mapping */
497 0, /* tp_hash */
498 0, /* tp_call */
499 0, /* tp_str */
500 PyObject_GenericGetAttr, /* tp_getattro */
501 0, /* tp_setattro */
502 0, /* tp_as_buffer */
503 Py_TPFLAGS_DEFAULT, /* tp_flags */
504 0, /* tp_doc */
505 0, /* tp_traverse */
506 0, /* tp_clear */
507 0, /* tp_richcompare */
508 0, /* tp_weaklistoffset */
509 0, /* tp_iter */
510 0, /* tp_iternext */
511 stdprinter_methods, /* tp_methods */
512 0, /* tp_members */
Christian Heimesaf935e32007-11-12 16:05:45 +0000513 stdprinter_getsetlist, /* tp_getset */
Guido van Rossum826d8972007-10-30 18:34:07 +0000514 0, /* tp_base */
515 0, /* tp_dict */
516 0, /* tp_descr_get */
517 0, /* tp_descr_set */
518 0, /* tp_dictoffset */
Christian Heimesaf935e32007-11-12 16:05:45 +0000519 fileio_init, /* tp_init */
Guido van Rossum826d8972007-10-30 18:34:07 +0000520 PyType_GenericAlloc, /* tp_alloc */
521 stdprinter_new, /* tp_new */
522 PyObject_Del, /* tp_free */
523};
524
525
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000526#ifdef __cplusplus
527}
528#endif