1 /**
2   Mirror _pyerrors.h
3   */
4 module deimos.python.pyerrors;
5 
6 import core.stdc.stdarg;
7 import deimos.python.pyport;
8 import deimos.python.object;
9 import deimos.python.unicodeobject;
10 
11 extern(C):
12 // Python-header-file: Include/pyerrors.h:
13 
14 version(Python_3_0_Or_Later) {
15     /// _
16     mixin template PyException_HEAD() {
17         mixin PyObject_HEAD;
18         /// _
19         PyObject* dict;
20         /// _
21         PyObject* args;
22         /// _
23         PyObject* traceback;
24         /// _
25         PyObject* context;
26         /// _
27         PyObject* cause;
28     }
29 }else version(Python_2_5_Or_Later) {
30     /// _
31     mixin template PyException_HEAD() {
32         mixin PyObject_HEAD;
33         /// _
34         PyObject* dict;
35         /// _
36         PyObject* args;
37         /// _
38         PyObject* message;
39     }
40 }
41 
42 version(Python_2_5_Or_Later) {
43     /* Error objects */
44 
45     /// Availability: >= 2.5
46     struct PyBaseExceptionObject {
47         mixin PyException_HEAD;
48     }
49 
50     /// subclass of PyBaseExceptionObject
51     /// Availability: >= 2.5
52     struct PySyntaxErrorObject {
53         mixin PyException_HEAD;
54         /// _
55         PyObject* msg;
56         /// _
57         PyObject* filename;
58         /// _
59         PyObject* lineno;
60         /// _
61         PyObject* offset;
62         /// _
63         PyObject* text;
64         /// _
65         PyObject* print_file_and_line;
66     }
67 
68     /// subclass of PyBaseExceptionObject
69     /// Availability: >= 2.5
70     struct PyUnicodeErrorObject {
71         mixin PyException_HEAD;
72         /// _
73         PyObject* encoding;
74         /// _
75         PyObject* object;
76         version(Python_2_6_Or_Later){
77             /// Availability: >= 2.6
78             Py_ssize_t start;
79             /// Availability: >= 2.6
80             Py_ssize_t end;
81         }else{
82             /// Availability: <= 2.5
83             PyObject* start;
84             /// Availability: <= 2.5
85             PyObject* end;
86         }
87         /// _
88         PyObject* reason;
89     }
90 
91     /// subclass of PyBaseExceptionObject
92     /// Availability: >= 2.5
93     struct PySystemExitObject {
94         mixin PyException_HEAD;
95         /// _
96         PyObject* code;
97     }
98 
99     /// subclass of PyBaseExceptionObject
100     /// Availability: >= 2.5
101     struct PyEnvironmentErrorObject {
102         mixin PyException_HEAD;
103         /// _
104         PyObject* myerrno;
105         /// _
106         PyObject* strerror;
107         /// _
108         PyObject* filename;
109     }
110 
111     version(Windows) {
112         /// subclass of PyBaseExceptionObject
113         /// Availability: >= 2.5, Windows only
114         struct PyWindowsErrorObject {
115             mixin PyException_HEAD;
116             /// _
117             PyObject* myerrno;
118             /// _
119             PyObject* strerror;
120             /// _
121             PyObject* filename;
122             /// _
123             PyObject* winerror;
124         }
125     }
126 }
127 
128 /// _
129 void PyErr_SetNone(PyObject*);
130 /// _
131 void PyErr_SetObject(PyObject*, PyObject*);
132 /// _
133 void PyErr_SetString(PyObject* exception, const(char)* string);
134 /// _
135 PyObject* PyErr_Occurred();
136 /// _
137 void PyErr_Clear();
138 /// _
139 void PyErr_Fetch(PyObject**, PyObject**, PyObject**);
140 /// _
141 void PyErr_Restore(PyObject*, PyObject*, PyObject*);
142 version(Python_3_0_Or_Later) {
143     /// Availability: 3.*
144     void Py_FatalError(const(char)* message);
145 }
146 
147 /// _
148 int PyErr_GivenExceptionMatches(PyObject*, PyObject*);
149 /// _
150 int PyErr_ExceptionMatches(PyObject*);
151 /// _
152 void PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
153 version(Python_2_5_Or_Later) {
154     /// Availability: >= 2.5
155     int PyExceptionClass_Check()(PyObject* x) {
156         version(Python_3_0_Or_Later) {
157             return (PyType_Check((x)) &&
158                     PyType_FastSubclass(cast(PyTypeObject*)x,
159                         Py_TPFLAGS_BASE_EXC_SUBCLASS));
160         }else version(Python_2_6_Or_Later) {
161             return (PyClass_Check(x) || (PyType_Check(x) &&
162                         PyType_FastSubclass(cast(PyTypeObject*)x,
163                             Py_TPFLAGS_BASE_EXC_SUBCLASS)));
164         }else{
165             return (PyClass_Check(x) || (PyType_Check(x) &&
166                         PyType_IsSubtype(cast(PyTypeObject*)x,
167                             cast(PyTypeObject*) PyExc_BaseException)));
168         }
169     }
170 
171     /// Availability: >= 2.5
172     int PyExceptionInstance_Check()(PyObject* x) {
173         version(Python_3_0_Or_Later) {
174             return PyType_FastSubclass(x.ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS);
175         }else version(Python_2_6_Or_Later) {
176             return (PyInstance_Check(x) ||
177                     PyType_FastSubclass(x.ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS));
178         }else{
179             return (PyInstance_Check(x) ||
180                     PyType_IsSubtype(x.ob_type,
181                         cast(PyTypeObject*) PyExc_BaseException));
182         }
183     }
184 
185     /// Availability: >= 2.5
186     int PyExceptionClass_Name()(PyObject* x) {
187         version(Python_3_0_Or_Later) {
188             return cast(char*)((cast(PyTypeObject*)x).tp_name);
189         }else {
190             return (PyClass_Check(x)
191                     ? PyString_AS_STRING((cast(PyClassObject*)x).cl_name)
192                     : cast(char*)(cast(PyTypeObject*)x).tp_name);
193         }
194     }
195 
196     /// Availability: >= 2.5
197     int PyExceptionInstance_Class()(PyObject* x) {
198         version(Python_3_0_Or_Later) {
199             return cast(PyObject*)(x.ob_type);
200         }else{
201             return ((PyInstance_Check(x)
202                         ? cast(PyObject*)(cast(PyInstanceObject*)x).in_class
203                         : cast(PyObject*)(x.ob_type)));
204         }
205     }
206 }
207 
208 
209 /* Predefined exceptions */
210 
211 version(Python_2_5_Or_Later) {
212     /// Availability: >= 2.5
213     mixin(PyAPI_DATA!"PyObject* PyExc_BaseException");
214 }
215 /// _
216 mixin(PyAPI_DATA!"PyObject* PyExc_Exception");
217 version(Python_3_5_Or_Later) {
218     /// _
219     mixin(PyAPI_DATA!"PyObject* PyExc_StopAsyncIteration");
220 }
221 /// _
222 mixin(PyAPI_DATA!"PyObject* PyExc_StopIteration");
223 version(Python_2_5_Or_Later) {
224     /// Availability: >= 2.5
225     mixin(PyAPI_DATA!"PyObject* PyExc_GeneratorExit");
226 }
227 version(Python_3_0_Or_Later) {
228 }else{
229     /// Availability: 2.*
230     mixin(PyAPI_DATA!"PyObject* PyExc_StandardError");
231 }
232 /// _
233 mixin(PyAPI_DATA!"PyObject* PyExc_ArithmeticError");
234 /// _
235 mixin(PyAPI_DATA!"PyObject* PyExc_LookupError");
236 
237 /// _
238 mixin(PyAPI_DATA!"PyObject* PyExc_AssertionError");
239 /// _
240 mixin(PyAPI_DATA!"PyObject* PyExc_AttributeError");
241 /// _
242 mixin(PyAPI_DATA!"PyObject* PyExc_EOFError");
243 /// _
244 mixin(PyAPI_DATA!"PyObject* PyExc_FloatingPointError");
245 /// _
246 mixin(PyAPI_DATA!"PyObject* PyExc_EnvironmentError");
247 /// _
248 mixin(PyAPI_DATA!"PyObject* PyExc_IOError");
249 /// _
250 mixin(PyAPI_DATA!"PyObject* PyExc_OSError");
251 /// _
252 mixin(PyAPI_DATA!"PyObject* PyExc_ImportError");
253 
254 version(Python_3_6_Or_Later) {
255     /// _
256     mixin(PyAPI_DATA!"PyObject* PyExc_ModuleNotFoundError");
257 }
258 /// _
259 mixin(PyAPI_DATA!"PyObject* PyExc_IndexError");
260 /// _
261 mixin(PyAPI_DATA!"PyObject* PyExc_KeyError");
262 /// _
263 mixin(PyAPI_DATA!"PyObject* PyExc_KeyboardInterrupt");
264 /// _
265 mixin(PyAPI_DATA!"PyObject* PyExc_MemoryError");
266 /// _
267 mixin(PyAPI_DATA!"PyObject* PyExc_NameError");
268 /// _
269 mixin(PyAPI_DATA!"PyObject* PyExc_OverflowError");
270 /// _
271 mixin(PyAPI_DATA!"PyObject* PyExc_RuntimeError");
272 version(Python_3_5_Or_Later) {
273     /// _
274     mixin(PyAPI_DATA!"PyObject* PyExc_RecursionError;");
275 }
276 /// _
277 mixin(PyAPI_DATA!"PyObject* PyExc_NotImplementedError");
278 /// _
279 mixin(PyAPI_DATA!"PyObject* PyExc_SyntaxError");
280 /// _
281 mixin(PyAPI_DATA!"PyObject* PyExc_IndentationError");
282 /// _
283 mixin(PyAPI_DATA!"PyObject* PyExc_TabError");
284 /// _
285 mixin(PyAPI_DATA!"PyObject* PyExc_ReferenceError");
286 /// _
287 mixin(PyAPI_DATA!"PyObject* PyExc_SystemError");
288 /// _
289 mixin(PyAPI_DATA!"PyObject* PyExc_SystemExit");
290 /// _
291 mixin(PyAPI_DATA!"PyObject* PyExc_TypeError");
292 /// _
293 mixin(PyAPI_DATA!"PyObject* PyExc_UnboundLocalError");
294 /// _
295 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeError");
296 /// _
297 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeEncodeError");
298 /// _
299 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeDecodeError");
300 /// _
301 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeTranslateError");
302 /// _
303 mixin(PyAPI_DATA!"PyObject* PyExc_ValueError");
304 /// _
305 mixin(PyAPI_DATA!"PyObject* PyExc_ZeroDivisionError");
306 version(Windows) {
307     /// Availability: Windows only
308     mixin(PyAPI_DATA!"PyObject* PyExc_WindowsError");
309 }
310 // ??!
311 version(VMS) {
312     /// Availability: VMS only
313     mixin(PyAPI_DATA!"PyObject* PyExc_VMSError");
314 }
315 version(Python_2_6_Or_Later) {
316     /// Availability: >= 2.6
317     mixin(PyAPI_DATA!"PyObject* PyExc_BufferError");
318 }
319 
320 version(Python_3_0_Or_Later) {
321 }else{
322     /// Availability: 2.*
323     mixin(PyAPI_DATA!"PyObject* PyExc_MemoryErrorInst");
324 }
325 version(Python_2_6_Or_Later) {
326     /// Availability: >= 2.6
327     mixin(PyAPI_DATA!"PyObject* PyExc_RecursionErrorInst");
328 }
329 
330 /** Predefined warning categories */
331 mixin(PyAPI_DATA!"PyObject* PyExc_Warning");
332 /// ditto
333 mixin(PyAPI_DATA!"PyObject* PyExc_UserWarning");
334 /// ditto
335 mixin(PyAPI_DATA!"PyObject* PyExc_DeprecationWarning");
336 /// ditto
337 mixin(PyAPI_DATA!"PyObject* PyExc_PendingDeprecationWarning");
338 /// ditto
339 mixin(PyAPI_DATA!"PyObject* PyExc_SyntaxWarning");
340 /* PyExc_OverflowWarning will go away for Python 2.5 */
341 version(Python_2_5_Or_Later) {
342 }else{
343     /// Availability: 2.4
344     mixin(PyAPI_DATA!"PyObject* PyExc_OverflowWarning");
345 }
346 /// _
347 mixin(PyAPI_DATA!"PyObject* PyExc_RuntimeWarning");
348 /// _
349 mixin(PyAPI_DATA!"PyObject* PyExc_FutureWarning");
350 version(Python_2_5_Or_Later) {
351     /// Availability: >= 2.5
352     mixin(PyAPI_DATA!"PyObject* PyExc_ImportWarning");
353     /// Availability: >= 2.5
354     mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeWarning");
355 }
356 version(Python_2_6_Or_Later) {
357     /// Availability: >= 2.6
358     mixin(PyAPI_DATA!"PyObject* PyExc_BytesWarning");
359 }
360 
361 version(Python_3_0_Or_Later) {
362     /// Availability: 3.*
363     mixin(PyAPI_DATA!"PyObject* PyExc_ResourceWarning");
364 
365     /** Traceback manipulation (PEP 3134) */
366     int PyException_SetTraceback(PyObject*, PyObject*);
367     /// ditto
368     PyObject* PyException_GetTraceback(PyObject*);
369 
370     /** Cause manipulation (PEP 3134) */
371     PyObject* PyException_GetCause(PyObject*);
372     /// ditto
373     void PyException_SetCause(PyObject*, PyObject*);
374 
375     /** Context manipulation (PEP 3134) */
376     PyObject* PyException_GetContext(PyObject*);
377     /// ditto
378     void PyException_SetContext(PyObject*, PyObject*);
379 }
380 
381 /// _
382 int PyErr_BadArgument();
383 /// _
384 PyObject* PyErr_NoMemory();
385 /// _
386 PyObject* PyErr_SetFromErrno(PyObject*);
387 /// _
388 PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject*, PyObject*);
389 /// _
390 PyObject* PyErr_SetFromErrnoWithFilename(PyObject* exc, char* filename);
391 /// _
392 PyObject* PyErr_SetFromErrnoWithUnicodeFilename(PyObject*, Py_UNICODE*);
393 
394 /// _
395 PyObject* PyErr_Format(PyObject* exception, const(char)* format, ...);
396 
397 version (Windows) {
398     /// Availability: Windows only
399     PyObject* PyErr_SetFromWindowsErrWithFilenameObject(int, const(char)*);
400     /// Availability: Windows only
401     PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const(char)* filename);
402     /// Availability: Windows only
403     PyObject* PyErr_SetFromWindowsErrWithUnicodeFilename(int, Py_UNICODE*);
404     /// Availability: Windows only
405     PyObject* PyErr_SetFromWindowsErr(int);
406     /// Availability: Windows only
407     PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject*, int, PyObject*);
408     /// Availability: Windows only
409     PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject* exc, int ierr, const(char)* filename);
410     /// Availability: Windows only
411     PyObject* PyErr_SetExcFromWindowsErrWithUnicodeFilename(PyObject*, int, Py_UNICODE*);
412     /// Availability: Windows only
413     PyObject* PyErr_SetExcFromWindowsErr(PyObject*, int);
414 }
415 
416 version(Python_3_6_Or_Later) {
417     PyObject* PyErr_SetImportErrorSubclass(PyObject*, PyObject*, PyObject*, PyObject*);
418 }
419 
420 version(Python_3_5_Or_Later) {
421     PyObject* PyErr_SetImportError(PyObject*, PyObject*, PyObject*);
422 }
423 
424 // PyErr_BadInternalCall and friends purposely omitted.
425 /// _
426 void PyErr_BadInternalall();
427 /// _
428 void _PyErr_BadInternalCall(const(char)* filename, int lineno);
429 
430 /// _
431 PyObject* PyErr_NewException(const(char)* name, PyObject* base, PyObject* dict);
432 version(Python_2_7_Or_Later) {
433     /// Availability: >= 2.7
434     PyObject* PyErr_NewExceptionWithDoc(
435             const(char)* name, const(char)* doc, PyObject* base, PyObject* dict);
436 }
437 /// _
438 void PyErr_WriteUnraisable(PyObject*);
439 
440 version(Python_2_5_Or_Later){
441     /// Availability: >= 2.5
442     int PyErr_WarnEx(PyObject*, char*, Py_ssize_t);
443 }else{
444     /// Availability: 2.4
445     int PyErr_Warn(PyObject*, char*);
446 }
447 /// _
448 int PyErr_WarnExplicit(PyObject*, const(char)*, const(char)*, int, const(char)*, PyObject*);
449 
450 /// _
451 int PyErr_CheckSignals();
452 /// _
453 void PyErr_SetInterrupt();
454 
455 /// _
456 void PyErr_SyntaxLocation(const(char)* filename, int lineno);
457 version(Python_3_0_Or_Later) {
458     /// Availability: 3.*
459     void PyErr_SyntaxLocationEx(
460             const(char)* filename,
461             int lineno,
462             int col_offset);
463 }
464 /// _
465 PyObject* PyErr_ProgramText(const(char)* filename, int lineno);
466 
467 //-//////////////////////////////////////////////////////////////////////////
468 // UNICODE ENCODING ERROR HANDLING INTERFACE
469 //-//////////////////////////////////////////////////////////////////////////
470 /** create a UnicodeDecodeError object */
471 PyObject* PyUnicodeDecodeError_Create(
472         const(char)* encoding,
473         const(char)* object,
474         Py_ssize_t length,
475         Py_ssize_t start,
476         Py_ssize_t end,
477         const(char)* reason);
478 
479 /** create a UnicodeEncodeError object */
480 PyObject* PyUnicodeEncodeError_Create(
481         const(char)* encoding,
482         Py_UNICODE* object,
483         Py_ssize_t length,
484         Py_ssize_t start,
485         Py_ssize_t end,
486         const(char)* reason);
487 
488 /** create a UnicodeTranslateError object */
489 PyObject* PyUnicodeTranslateError_Create(
490         Py_UNICODE* object,
491         Py_ssize_t length,
492         Py_ssize_t start,
493         Py_ssize_t end,
494         const(char)* reason);
495 
496 /** get the encoding attribute */
497 PyObject* PyUnicodeEncodeError_GetEncoding(PyObject*);
498 /// ditto
499 PyObject* PyUnicodeDecodeError_GetEncoding(PyObject*);
500 
501 /** get the object attribute */
502 PyObject* PyUnicodeEncodeError_GetObject(PyObject*);
503 /// ditto
504 PyObject* PyUnicodeDecodeError_GetObject(PyObject*);
505 /// ditto
506 PyObject* PyUnicodeTranslateError_GetObject(PyObject*);
507 
508 /** get the value of the start attribute (the int * may not be NULL)
509    return 0 on success, -1 on failure */
510 int PyUnicodeEncodeError_GetStart(PyObject*, Py_ssize_t*);
511 /// ditto
512 int PyUnicodeDecodeError_GetStart(PyObject*, Py_ssize_t*);
513 /// ditto
514 int PyUnicodeTranslateError_GetStart(PyObject*, Py_ssize_t*);
515 
516 /** assign a new value to the start attribute
517    return 0 on success, -1 on failure */
518 int PyUnicodeEncodeError_SetStart(PyObject*, Py_ssize_t);
519 /// ditto
520 int PyUnicodeDecodeError_SetStart(PyObject*, Py_ssize_t);
521 /// ditto
522 int PyUnicodeTranslateError_SetStart(PyObject* , Py_ssize_t);
523 
524 /** get the value of the end attribute (the int *may not be NULL)
525  return 0 on success, -1 on failure */
526 int PyUnicodeEncodeError_GetEnd(PyObject*, Py_ssize_t*);
527 /// ditto
528 int PyUnicodeDecodeError_GetEnd(PyObject*, Py_ssize_t*);
529 /// ditto
530 int PyUnicodeTranslateError_GetEnd(PyObject* , Py_ssize_t*);
531 
532 /** assign a new value to the end attribute
533    return 0 on success, -1 on failure */
534 int PyUnicodeEncodeError_SetEnd(PyObject*, Py_ssize_t);
535 /// ditto
536 int PyUnicodeDecodeError_SetEnd(PyObject*, Py_ssize_t);
537 /// ditto
538 int PyUnicodeTranslateError_SetEnd(PyObject*, Py_ssize_t);
539 
540 /** get the value of the reason attribute */
541 PyObject* PyUnicodeEncodeError_GetReason(PyObject*);
542 /// ditto
543 PyObject* PyUnicodeDecodeError_GetReason(PyObject*);
544 /// ditto
545 PyObject* PyUnicodeTranslateError_GetReason(PyObject*);
546 
547 /** assign a new value to the reason attribute
548    return 0 on success, -1 on failure */
549 int PyUnicodeEncodeError_SetReason(PyObject* exc, const(char)* reason);
550 /// ditto
551 int PyUnicodeDecodeError_SetReason(PyObject* exc, const(char)* reason);
552 /// ditto
553 int PyUnicodeTranslateError_SetReason(PyObject* exc, const(char)* reason);
554 
555 /// _
556 int PyOS_snprintf(char* str, size_t size, const(char)* format, ...);
557 /// _
558 int PyOS_vsnprintf(char* str, size_t size, const(char)* format, va_list va);
559 
560