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