Mercurial > cpython-lru_cache-weakref
annotate Include/fileobject.h @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | c1eb668525e1 |
| children | bf1634b023d5 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* File object interface */ |
| 3 | |
|
13444
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
4 #ifndef Py_FILEOBJECT_H |
|
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
5 #define Py_FILEOBJECT_H |
|
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
6 #ifdef __cplusplus |
|
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
7 extern "C" { |
|
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
8 #endif |
|
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
9 |
|
22312
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
10 typedef struct { |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
11 PyObject_HEAD |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
12 FILE *f_fp; |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
13 PyObject *f_name; |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
14 PyObject *f_mode; |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
15 int (*f_close)(FILE *); |
|
24594
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
16 int f_softspace; /* Flag used by 'print' command */ |
|
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
17 int f_binary; /* Flag which indicates whether the file is |
|
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
18 open in binary (1) or text (0) mode */ |
|
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
19 char* f_buf; /* Allocated readahead buffer */ |
|
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
20 char* f_bufend; /* Points after last occupied position */ |
|
f928f7eea2d6
SF patch 580331 by Oren Tirosh: make file objects their own iterator.
Guido van Rossum <guido@python.org>
parents:
23537
diff
changeset
|
21 char* f_bufptr; /* Current buffer position */ |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
22 #ifdef WITH_UNIVERSAL_NEWLINES |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
23 int f_univ_newline; /* Handle any newline convention */ |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
24 int f_newlinetypes; /* Types of newlines seen */ |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
25 int f_skipnextlf; /* Skip next \n */ |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
26 #endif |
|
22312
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
27 } PyFileObject; |
|
19d1d35020bd
Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents:
21095
diff
changeset
|
28 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
29 PyAPI_DATA(PyTypeObject) PyFile_Type; |
| 6 | 30 |
|
19894
51cc82605d32
SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents:
17822
diff
changeset
|
31 #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type) |
|
51cc82605d32
SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents:
17822
diff
changeset
|
32 #define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type) |
| 6 | 33 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
34 PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
35 PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
36 PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *, |
|
13444
5709ddba423c
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
37 int (*)(FILE *)); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
38 PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
39 PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
40 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
41 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
42 PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
43 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
44 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *); |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
45 |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
46 /* The default encoding used by the platform file system APIs |
|
23201
c408e8b2675a
Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents:
23029
diff
changeset
|
47 If non-NULL, this is different than the default encoding for strings |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
48 */ |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24594
diff
changeset
|
49 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding; |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
50 |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
51 #ifdef WITH_UNIVERSAL_NEWLINES |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
52 /* Routines to replace fread() and fgets() which accept any of \r, \n |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
53 or \r\n as line terminators. |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
54 */ |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
55 #define PY_STDIOTEXTMODE "b" |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
56 char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); |
|
23201
c408e8b2675a
Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents:
23029
diff
changeset
|
57 size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *); |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
58 #else |
|
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
59 #define PY_STDIOTEXTMODE "" |
|
23201
c408e8b2675a
Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents:
23029
diff
changeset
|
60 #define Py_UniversalNewlineFgets(buf, len, fp, obj) fgets((buf), (len), (fp)) |
|
23537
fa8fe2e98062
Add missing \ to macro definition only used when universal newlines
Guido van Rossum <guido@python.org>
parents:
23201
diff
changeset
|
61 #define Py_UniversalNewlineFread(buf, len, fp, obj) \ |
|
23201
c408e8b2675a
Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents:
23029
diff
changeset
|
62 fread((buf), 1, (len), (fp)) |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22312
diff
changeset
|
63 #endif /* WITH_UNIVERSAL_NEWLINES */ |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
64 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
65 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
66 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
67 #endif /* !Py_FILEOBJECT_H */ |
