1 /**
2   Mirror _fileobject.h
3   */
4 module deimos.python.fileobject;
5 
6 import core.stdc.stdio;
7 import deimos.python.pyport;
8 import deimos.python.object;
9 
10 extern(C):
11 // Python-header-file: Include/fileobject.h:
12 
13 version(Python_3_0_Or_Later) {
14 }else{
15     /// subclass of PyObject
16     /// Availability: 2.*
17     struct PyFileObject {
18         mixin PyObject_HEAD;
19 
20         /// _
21         FILE* f_fp;
22         /// _
23         PyObject* f_name;
24         /// _
25         PyObject* f_mode;
26         /// _
27         int function(FILE*) f_close;
28         /** Flag used by 'print' command */
29         int f_softspace;
30         /** Flag which indicates whether the file is
31            open in binary (1) or text (0) mode */
32         int f_binary;
33         /** Allocated readahead buffer */
34         char* f_buf;
35         /** Points after last occupied position */
36         char* f_bufend;
37         /** Current buffer position */
38         char* f_bufptr;
39         /** Buffer for setbuf(3) and setvbuf(3) */
40         char* f_setbuf;
41         /** Handle any newline convention */
42         int f_univ_newline;
43         /** Types of newlines seen */
44         int f_newlinetypes;
45         /** Skip next \n */
46         int f_skipnextlf;
47         /// _
48         PyObject* f_encoding;
49         version(Python_2_6_Or_Later){
50             /// Availability: >= 2.6
51             PyObject* f_errors;
52         }
53         /** List of weak references */
54         PyObject* weakreflist;
55         version(Python_2_6_Or_Later){
56             /** Num. currently running sections of code
57                using f_fp with the GIL released. */
58             /// Availability: >= 2.6
59             int unlocked_count;
60             /// Availability: >= 2.6
61             int readable;
62             /// Availability: >= 2.6
63             int writable;
64         }
65     }
66 
67     /// Availability: 2.*
68     mixin(PyAPI_DATA!"PyTypeObject PyFile_Type");
69 
70     // D translation of C macro:
71     /// Availability: 2.*
72     int PyFile_Check()(PyObject* op) {
73         return PyObject_TypeCheck(op, &PyFile_Type);
74     }
75     // D translation of C macro:
76     /// Availability: 2.*
77     int PyFile_CheckExact()(PyObject* op) {
78         return Py_TYPE(op) == &PyFile_Type;
79     }
80 
81     /// Availability: 2.*
82     PyObject* PyFile_FromString(char*, char*);
83     /// Availability: 2.*
84     void PyFile_SetBufSize(PyObject*, int);
85     /// Availability: 2.*
86     int PyFile_SetEncoding(PyObject*, const(char)*);
87     version(Python_2_6_Or_Later){
88         /// Availability: >= 2.6
89         int PyFile_SetEncodingAndErrors(PyObject* , const(char)*, const(char)* errors);
90     }
91     /// Availability: 2.*
92     PyObject* PyFile_FromFile(FILE*, char*, char*, int function(FILE*));
93     /// Availability: 2.*
94     FILE* PyFile_AsFile(PyObject*);
95     version(Python_2_6_Or_Later){
96         /// Availability: >= 2.6
97         void PyFile_IncUseCount(PyFileObject*);
98         /// Availability: >= 2.6
99         void PyFile_DecUseCount(PyFileObject*);
100     }
101     /// Availability: 2.*
102     PyObject_BorrowedRef* PyFile_Name(PyObject*);
103 }
104 version(Python_3_0_Or_Later) {
105     /// Availability: 3.*
106     PyObject* PyFile_FromFd(int, char *, char *, int, char *, char *,
107             char *, int);
108 }
109 /// _
110 PyObject* PyFile_GetLine(PyObject* , int);
111 /// _
112 int PyFile_WriteObject(PyObject*, PyObject*, int);
113 version(Python_3_0_Or_Later) {
114 }else {
115     /// Availability: 2.*
116     int PyFile_SoftSpace(PyObject*, int);
117 }
118 /// _
119 int PyFile_WriteString(const(char)*, PyObject*);
120 /// _
121 int PyObject_AsFileDescriptor(PyObject*);
122 
123 /** The default encoding used by the platform file system APIs
124    If non-NULL, this is different than the default encoding for strings
125 */
126 mixin(PyAPI_DATA!"const(char)* Py_FileSystemDefaultEncoding");
127 
128 version(Python_3_6_Or_Later) {
129     /// _
130     mixin(PyAPI_DATA!"const(char)* Py_FileSystemDefaultEncodeError");
131 }
132 
133 /// _
134 enum PY_STDIOTEXTMODE = "b";
135 
136 /// _
137 /* Routine to replace fgets() which accept any of \r, \n
138    or \r\n as line terminators.
139 */
140 char* Py_UniversalNewlineFgets(char*, int, FILE*, PyObject*);
141 version(Python_3_0_Or_Later) {
142     /// Availability: 3.*
143     mixin(PyAPI_DATA!"int Py_HasFileSystemDefaultEncoding");
144     /// Availability: 3.*
145     PyObject* PyFile_NewStdPrinter(int);
146     /// Availability: 3.*
147     mixin(PyAPI_DATA!"PyTypeObject PyStdPrinter_Type");
148 }else{
149     /** Routines to replace fread() and fgets() which accept any of \r, \n
150       or \r\n as line terminators.
151      */
152     /// Availability: 2.*
153     size_t Py_UniversalNewlineFread(char*, size_t, FILE*, PyObject*);
154 }
155 
156 version(Python_3_0_Or_Later) {
157 }else version(Python_2_5_Or_Later) {
158     /** A routine to do sanity checking on the file mode string.  returns
159       non-zero on if an exception occurred
160      */
161     /// Availability: 2.*
162     int _PyFile_SanitizeMode(char *mode);
163 }
164 
165 version(Python_2_7_Or_Later) {
166     //#if defined _MSC_VER && _MSC_VER >= 1400
167     //int _PyVerify_fd(int fd);
168 }