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