1 /**
2   Mirror _cStringIO.h
3 
4   This header provides access to _cStringIO objects from C.
5   Functions are provided for calling _cStringIO objects and
6   macros are provided for testing whether you have _cStringIO 
7   objects.
8 
9   Before calling any of the functions or macros, you must initialize
10   the routines with:
11 
12     PycString_IMPORT()
13 
14   This would typically be done in your init function.
15 
16   Note _cStringIO.h goes away in python 3
17   */
18 module deimos.python.cStringIO;
19 
20 import deimos.python.pyport;
21 import deimos.python.object;
22 import deimos.python.cobject;
23 
24 version(Python_3_0_Or_Later) {
25 }else{
26 extern(C):
27 // Python-header-file: Include/cStringIO.h:
28 
29 /// Availability: 2.*
30 PycStringIO_CAPI* PycStringIO = null;
31 
32 /// Availability: 2.*
33 PycStringIO_CAPI* PycString_IMPORT()() {
34     if (PycStringIO == null) {
35         PycStringIO = cast(PycStringIO_CAPI *)
36             PyCObject_Import("cStringIO", "cStringIO_CAPI");
37     }
38     return PycStringIO;
39 }
40 
41 /** Basic functions to manipulate cStringIO objects from C */
42 /// Availability: 2.*
43 struct PycStringIO_CAPI {
44     /** Read a string from an input object.  If the last argument
45     is -1, the remainder will be read.
46     */
47     int function(PyObject*, char**, Py_ssize_t) cread;
48     /** Read a line from an input object.  Returns the length of the read
49     line as an int and a pointer inside the object buffer as char** (so
50     the caller doesn't have to provide its own buffer as destination).
51     */
52     int function(PyObject*, char**) creadline;
53     /** Write a string to an output object*/
54     int function(PyObject*, const(char)*, Py_ssize_t) cwrite;
55     /** Get the output object as a Python string (returns new reference). */
56     PyObject* function(PyObject*) cgetvalue;
57     /** Create a new output object */
58     PyObject* function(int) NewOutput;
59     /** Create an input object from a Python string
60      (copies the Python string reference).
61      */
62     PyObject* function(PyObject*) NewInput;
63 
64     /** The Python types for cStringIO input and output objects.
65      Note that you can do input on an output object.
66      */
67     PyTypeObject* InputType;
68     /// ditto
69     PyTypeObject* OutputType;
70 }
71 
72 // D translations of C macros:
73 /// Availability: 2.*
74 int PycStringIO_InputCheck()(PyObject* o) {
75     return Py_TYPE(o) == PycStringIO.InputType;
76 }
77 /// Availability: 2.*
78 int PycStringIO_OutputCheck()(PyObject* o) {
79     return Py_TYPE(o) == PycStringIO.OutputType;
80 }
81 
82 
83 }