1 /**
2   Mirror _bytesobject.h
3 
4   Note _bytesobject.h did not exist before python 2.6; however
5   for python 2, it simply provides aliases to contents of stringobject.h,
6   so we provide them anyways to make it easier to write portable extension
7   modules.
8   */
9 module deimos.python.bytesobject;
10 
11 import deimos.python.pyport;
12 import deimos.python.object;
13 import deimos.python.stringobject;
14 import core.stdc.stdarg;
15 
16 version(Python_3_0_Or_Later) {
17         /** 
18          * subclass of PyVarObject.
19          *
20          * Invariants:
21          *     ob_sval contains space for 'ob_size+1' elements.
22          *     ob_sval[ob_size] == 0.
23          *     ob_shash is the hash of the string or -1 if not computed yet.
24          * 
25          */
26     extern(C):
27     struct PyBytesObject{
28         mixin PyObject_VAR_HEAD;
29         /// _
30         Py_hash_t ob_shash;
31         char[1] _ob_sval;
32         /// _
33         @property char* ob_sval()() {
34             return _ob_sval.ptr;
35         }
36 
37     } 
38 
39     /// 
40     mixin(PyAPI_DATA!"PyTypeObject PyBytes_Type");
41     /// 
42     mixin(PyAPI_DATA!"PyTypeObject PyBytesIter_Type");
43     // D translation of C macro:
44     /// 
45     int PyBytes_Check()(PyObject* op) {
46         return PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS);
47     }
48     /// 
49     int PyBytes_CheckExact()(PyObject* op) {
50         return Py_TYPE(op) is &PyBytes_Type;
51     }
52 
53     /// 
54     PyObject* PyBytes_FromStringAndSize(const(char)*, Py_ssize_t);
55     /// 
56     PyObject* PyBytes_FromString(const(char)*);
57     /// 
58     PyObject* PyBytes_FromObject(PyObject*);
59     /// 
60     PyObject* PyBytes_FromFormatV(const(char)*, va_list);
61     /// 
62     PyObject* PyBytes_FromFormat(const(char)*, ...);
63     /// 
64     Py_ssize_t PyBytes_Size(PyObject*);
65     /// 
66     const(char)* PyBytes_AsString(PyObject*);
67     /// 
68     PyObject* PyBytes_Repr(PyObject*, int);
69     /// 
70     void PyBytes_Concat(PyObject**, PyObject*);
71     /// 
72     void PyBytes_ConcatAndDel(PyObject**, PyObject*);
73     /// 
74     int _PyBytes_Resize(PyObject**, Py_ssize_t);
75     /// 
76     PyObject* _PyBytes_FormatLong(PyObject*, int, int,
77             int, char**, int*);
78     /// 
79     PyObject* PyBytes_DecodeEscape(const(char)*, Py_ssize_t,
80             const(char)*, Py_ssize_t,
81             const(char)*);
82     // D translation of C macro:
83     /// 
84     const(char)* PyBytes_AS_STRING()(PyObject* op) {
85         assert(PyBytes_Check(op));
86         return (cast(PyBytesObject*) op).ob_sval;
87 
88 
89     }
90     /// 
91     auto PyBytes_GET_SIZE()(PyObject* op) {
92         assert(PyBytes_Check(op));
93         return Py_SIZE(op);
94     }
95     /// 
96     PyObject* _PyBytes_Join(PyObject* sep, PyObject* x);
97     /**
98 Params:
99 obj = string or Unicode object 
100 s = pointer to buffer variable 
101 len = pointer to length variable or NULL (only possible for 0-terminated
102                                    strings)
103      */
104     int PyBytes_AsStringAndSize(
105             PyObject* obj,	
106             char** s,		
107             Py_ssize_t* len	
108             );
109     /// 
110     Py_ssize_t _PyBytes_InsertThousandsGroupingLocale(
111             char* buffer,
112             Py_ssize_t n_buffer,
113             char* digits,
114             Py_ssize_t n_digits,
115             Py_ssize_t min_width);
116 
117     /** Using explicit passed-in values, insert the thousands grouping
118        into the string pointed to by buffer.  For the argument descriptions,
119        see Objects/stringlib/localeutil.h */
120     Py_ssize_t _PyBytes_InsertThousandsGrouping(
121             char* buffer,
122             Py_ssize_t n_buffer,
123             char* digits,
124             Py_ssize_t n_digits,
125             Py_ssize_t min_width,
126             const(char)* grouping,
127             const char* thousands_sep);
128 
129     /// 
130 enum F_LJUST =      (1<<0);
131     /// 
132 enum F_SIGN =       (1<<1);
133     /// 
134 enum F_BLANK =      (1<<2);
135     /// 
136 enum F_ALT =        (1<<3);
137     /// 
138 enum F_ZERO =       (1<<4);
139 
140 }else {
141     /// 
142     alias PyStringObject PyBytesObject;
143     /// 
144     alias PyString_Type PyBytes_Type;
145     /// 
146     alias PyString_Check PyBytes_Check;
147     /// 
148     alias PyString_CheckExact PyBytes_CheckExact; 
149     /// 
150     alias PyString_CHECK_INTERNED PyBytes_CHECK_INTERNED;
151     /// 
152     alias PyString_AS_STRING PyBytes_AS_STRING;
153     /// 
154     alias PyString_GET_SIZE PyBytes_GET_SIZE;
155     version(Python_2_6_Or_Later) {
156     /// Availability: >= 2.6
157     alias Py_TPFLAGS_STRING_SUBCLASS Py_TPFLAGS_BYTES_SUBCLASS;
158     }
159     /// 
160     alias PyString_FromStringAndSize PyBytes_FromStringAndSize;
161     /// 
162     alias PyString_FromString PyBytes_FromString;
163     /// 
164     alias PyString_FromFormatV PyBytes_FromFormatV;
165     /// 
166     alias PyString_FromFormat PyBytes_FromFormat;
167     /// 
168     alias PyString_Size PyBytes_Size;
169     /// 
170     alias PyString_AsString PyBytes_AsString;
171     /// 
172     alias PyString_Repr PyBytes_Repr;
173     /// 
174     alias PyString_Concat PyBytes_Concat;
175     /// 
176     alias PyString_ConcatAndDel PyBytes_ConcatAndDel;
177     /// 
178     alias _PyString_Resize _PyBytes_Resize;
179     /// 
180     alias _PyString_Eq _PyBytes_Eq;
181     /// 
182     alias PyString_Format PyBytes_Format;
183     /// 
184     alias _PyString_FormatLong _PyBytes_FormatLong;
185     /// 
186     alias PyString_DecodeEscape PyBytes_DecodeEscape;
187     /// 
188     alias _PyString_Join _PyBytes_Join;
189     version(Python_2_7_Or_Later) {
190         // went away in python 2.7
191     }else {
192         /// Availability: <= 2.6
193         alias PyString_Decode PyBytes_Decode;
194         /// Availability: <= 2.6
195         alias PyString_Encode PyBytes_Encode;
196         /// Availability: <= 2.6
197         alias PyString_AsEncodedObject PyBytes_AsEncodedObject;
198         /// Availability: <= 2.6
199         alias PyString_AsDecodedObject PyBytes_AsDecodedObject;
200         /*
201         alias PyString_AsEncodedString PyBytes_AsEncodedString;
202         alias PyString_AsDecodedString PyBytes_AsDecodedString;
203         */
204     }
205     /// 
206     alias PyString_AsStringAndSize PyBytes_AsStringAndSize;
207     version(Python_2_6_Or_Later) {
208     /// Availability: >= 2.6
209     alias _PyString_InsertThousandsGrouping _PyBytes_InsertThousandsGrouping;
210     }
211 }