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 version(Python_3_8_Or_Later) { 124 }else { 125 /** The default encoding used by the platform file system APIs 126 If non-NULL, this is different than the default encoding for strings 127 */ 128 mixin(PyAPI_DATA!"const(char)* Py_FileSystemDefaultEncoding"); 129 } 130 131 version(Python_3_6_Or_Later) { 132 /// _ 133 mixin(PyAPI_DATA!"const(char)* Py_FileSystemDefaultEncodeError"); 134 } 135 136 version(Python_3_7_Or_Later) { 137 /// Availablility: >= 3.7 138 mixin(PyAPI_DATA!"int Py_UTF8Mode"); 139 } 140 141 /// _ 142 enum PY_STDIOTEXTMODE = "b"; 143 /// _ 144 /* Routine to replace fgets() which accept any of \r, \n 145 or \r\n as line terminators. 146 */ 147 char* Py_UniversalNewlineFgets(char*, int, FILE*, PyObject*); 148 149 version(Python_3_0_Or_Later) { 150 /// Availability: 3.* 151 mixin(PyAPI_DATA!"int Py_HasFileSystemDefaultEncoding"); 152 /// Availability: 3.* 153 PyObject* PyFile_NewStdPrinter(int); 154 /// Availability: 3.* 155 mixin(PyAPI_DATA!"PyTypeObject PyStdPrinter_Type"); 156 }else{ 157 /** Routines to replace fread() and fgets() which accept any of \r, \n 158 or \r\n as line terminators. 159 */ 160 /// Availability: 2.* 161 size_t Py_UniversalNewlineFread(char*, size_t, FILE*, PyObject*); 162 } 163 164 version(Python_3_0_Or_Later) { 165 }else version(Python_2_5_Or_Later) { 166 /** A routine to do sanity checking on the file mode string. returns 167 non-zero on if an exception occurred 168 */ 169 /// Availability: 2.* 170 int _PyFile_SanitizeMode(char *mode); 171 } 172 173 version(Python_2_7_Or_Later) { 174 //#if defined _MSC_VER && _MSC_VER >= 1400 175 //int _PyVerify_fd(int fd); 176 }