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 /// _ 218 mixin(PyAPI_DATA!"PyObject* PyExc_StopIteration"); 219 version(Python_2_5_Or_Later) { 220 /// Availability: >= 2.5 221 mixin(PyAPI_DATA!"PyObject* PyExc_GeneratorExit"); 222 } 223 version(Python_3_0_Or_Later) { 224 }else{ 225 /// Availability: 2.* 226 mixin(PyAPI_DATA!"PyObject* PyExc_StandardError"); 227 } 228 /// _ 229 mixin(PyAPI_DATA!"PyObject* PyExc_ArithmeticError"); 230 /// _ 231 mixin(PyAPI_DATA!"PyObject* PyExc_LookupError"); 232 233 /// _ 234 mixin(PyAPI_DATA!"PyObject* PyExc_AssertionError"); 235 /// _ 236 mixin(PyAPI_DATA!"PyObject* PyExc_AttributeError"); 237 /// _ 238 mixin(PyAPI_DATA!"PyObject* PyExc_EOFError"); 239 /// _ 240 mixin(PyAPI_DATA!"PyObject* PyExc_FloatingPointError"); 241 /// _ 242 mixin(PyAPI_DATA!"PyObject* PyExc_EnvironmentError"); 243 /// _ 244 mixin(PyAPI_DATA!"PyObject* PyExc_IOError"); 245 /// _ 246 mixin(PyAPI_DATA!"PyObject* PyExc_OSError"); 247 /// _ 248 mixin(PyAPI_DATA!"PyObject* PyExc_ImportError"); 249 /// _ 250 mixin(PyAPI_DATA!"PyObject* PyExc_IndexError"); 251 /// _ 252 mixin(PyAPI_DATA!"PyObject* PyExc_KeyError"); 253 /// _ 254 mixin(PyAPI_DATA!"PyObject* PyExc_KeyboardInterrupt"); 255 /// _ 256 mixin(PyAPI_DATA!"PyObject* PyExc_MemoryError"); 257 /// _ 258 mixin(PyAPI_DATA!"PyObject* PyExc_NameError"); 259 /// _ 260 mixin(PyAPI_DATA!"PyObject* PyExc_OverflowError"); 261 /// _ 262 mixin(PyAPI_DATA!"PyObject* PyExc_RuntimeError"); 263 /// _ 264 mixin(PyAPI_DATA!"PyObject* PyExc_NotImplementedError"); 265 /// _ 266 mixin(PyAPI_DATA!"PyObject* PyExc_SyntaxError"); 267 /// _ 268 mixin(PyAPI_DATA!"PyObject* PyExc_IndentationError"); 269 /// _ 270 mixin(PyAPI_DATA!"PyObject* PyExc_TabError"); 271 /// _ 272 mixin(PyAPI_DATA!"PyObject* PyExc_ReferenceError"); 273 /// _ 274 mixin(PyAPI_DATA!"PyObject* PyExc_SystemError"); 275 /// _ 276 mixin(PyAPI_DATA!"PyObject* PyExc_SystemExit"); 277 /// _ 278 mixin(PyAPI_DATA!"PyObject* PyExc_TypeError"); 279 /// _ 280 mixin(PyAPI_DATA!"PyObject* PyExc_UnboundLocalError"); 281 /// _ 282 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeError"); 283 /// _ 284 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeEncodeError"); 285 /// _ 286 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeDecodeError"); 287 /// _ 288 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeTranslateError"); 289 /// _ 290 mixin(PyAPI_DATA!"PyObject* PyExc_ValueError"); 291 /// _ 292 mixin(PyAPI_DATA!"PyObject* PyExc_ZeroDivisionError"); 293 version(Windows) { 294 /// Availability: Windows only 295 mixin(PyAPI_DATA!"PyObject* PyExc_WindowsError"); 296 } 297 // ??! 298 version(VMS) { 299 /// Availability: VMS only 300 mixin(PyAPI_DATA!"PyObject* PyExc_VMSError"); 301 } 302 version(Python_2_6_Or_Later) { 303 /// Availability: >= 2.6 304 mixin(PyAPI_DATA!"PyObject* PyExc_BufferError"); 305 } 306 307 version(Python_3_0_Or_Later) { 308 }else{ 309 /// Availability: 2.* 310 mixin(PyAPI_DATA!"PyObject* PyExc_MemoryErrorInst"); 311 } 312 version(Python_2_6_Or_Later) { 313 /// Availability: >= 2.6 314 mixin(PyAPI_DATA!"PyObject* PyExc_RecursionErrorInst"); 315 } 316 317 /** Predefined warning categories */ 318 mixin(PyAPI_DATA!"PyObject* PyExc_Warning"); 319 /// ditto 320 mixin(PyAPI_DATA!"PyObject* PyExc_UserWarning"); 321 /// ditto 322 mixin(PyAPI_DATA!"PyObject* PyExc_DeprecationWarning"); 323 /// ditto 324 mixin(PyAPI_DATA!"PyObject* PyExc_PendingDeprecationWarning"); 325 /// ditto 326 mixin(PyAPI_DATA!"PyObject* PyExc_SyntaxWarning"); 327 /* PyExc_OverflowWarning will go away for Python 2.5 */ 328 version(Python_2_5_Or_Later) { 329 }else{ 330 /// Availability: 2.4 331 mixin(PyAPI_DATA!"PyObject* PyExc_OverflowWarning"); 332 } 333 /// _ 334 mixin(PyAPI_DATA!"PyObject* PyExc_RuntimeWarning"); 335 /// _ 336 mixin(PyAPI_DATA!"PyObject* PyExc_FutureWarning"); 337 version(Python_2_5_Or_Later) { 338 /// Availability: >= 2.5 339 mixin(PyAPI_DATA!"PyObject* PyExc_ImportWarning"); 340 /// Availability: >= 2.5 341 mixin(PyAPI_DATA!"PyObject* PyExc_UnicodeWarning"); 342 } 343 version(Python_2_6_Or_Later) { 344 /// Availability: >= 2.6 345 mixin(PyAPI_DATA!"PyObject* PyExc_BytesWarning"); 346 } 347 348 version(Python_3_0_Or_Later) { 349 /// Availability: 3.* 350 mixin(PyAPI_DATA!"PyObject* PyExc_ResourceWarning"); 351 352 /** Traceback manipulation (PEP 3134) */ 353 int PyException_SetTraceback(PyObject*, PyObject*); 354 /// ditto 355 PyObject* PyException_GetTraceback(PyObject*); 356 357 /** Cause manipulation (PEP 3134) */ 358 PyObject* PyException_GetCause(PyObject*); 359 /// ditto 360 void PyException_SetCause(PyObject*, PyObject*); 361 362 /** Context manipulation (PEP 3134) */ 363 PyObject* PyException_GetContext(PyObject*); 364 /// ditto 365 void PyException_SetContext(PyObject*, PyObject*); 366 } 367 368 /// _ 369 int PyErr_BadArgument(); 370 /// _ 371 PyObject* PyErr_NoMemory(); 372 /// _ 373 PyObject* PyErr_SetFromErrno(PyObject*); 374 /// _ 375 PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject*, PyObject*); 376 /// _ 377 PyObject* PyErr_SetFromErrnoWithFilename(PyObject* exc, char* filename); 378 /// _ 379 PyObject* PyErr_SetFromErrnoWithUnicodeFilename(PyObject*, Py_UNICODE*); 380 381 /// _ 382 PyObject* PyErr_Format(PyObject* exception, const(char)* format, ...); 383 384 version (Windows) { 385 /// Availability: Windows only 386 PyObject* PyErr_SetFromWindowsErrWithFilenameObject(int, const(char)*); 387 /// Availability: Windows only 388 PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const(char)* filename); 389 /// Availability: Windows only 390 PyObject* PyErr_SetFromWindowsErrWithUnicodeFilename(int, Py_UNICODE*); 391 /// Availability: Windows only 392 PyObject* PyErr_SetFromWindowsErr(int); 393 /// Availability: Windows only 394 PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject*, int, PyObject*); 395 /// Availability: Windows only 396 PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject* exc, int ierr, const(char)* filename); 397 /// Availability: Windows only 398 PyObject* PyErr_SetExcFromWindowsErrWithUnicodeFilename(PyObject*, int, Py_UNICODE*); 399 /// Availability: Windows only 400 PyObject* PyErr_SetExcFromWindowsErr(PyObject*, int); 401 } 402 403 // PyErr_BadInternalCall and friends purposely omitted. 404 /// _ 405 void PyErr_BadInternalall(); 406 /// _ 407 void _PyErr_BadInternalCall(const(char)* filename, int lineno); 408 409 /// _ 410 PyObject* PyErr_NewException(const(char)* name, PyObject* base, PyObject* dict); 411 version(Python_2_7_Or_Later) { 412 /// Availability: >= 2.7 413 PyObject* PyErr_NewExceptionWithDoc( 414 const(char)* name, const(char)* doc, PyObject* base, PyObject* dict); 415 } 416 /// _ 417 void PyErr_WriteUnraisable(PyObject*); 418 419 version(Python_2_5_Or_Later){ 420 /// Availability: >= 2.5 421 int PyErr_WarnEx(PyObject*, char*, Py_ssize_t); 422 }else{ 423 /// Availability: 2.4 424 int PyErr_Warn(PyObject*, char*); 425 } 426 /// _ 427 int PyErr_WarnExplicit(PyObject*, const(char)*, const(char)*, int, const(char)*, PyObject*); 428 429 /// _ 430 int PyErr_CheckSignals(); 431 /// _ 432 void PyErr_SetInterrupt(); 433 434 /// _ 435 void PyErr_SyntaxLocation(const(char)* filename, int lineno); 436 version(Python_3_0_Or_Later) { 437 /// Availability: 3.* 438 void PyErr_SyntaxLocationEx( 439 const(char)* filename, 440 int lineno, 441 int col_offset); 442 } 443 /// _ 444 PyObject* PyErr_ProgramText(const(char)* filename, int lineno); 445 446 //-////////////////////////////////////////////////////////////////////////// 447 // UNICODE ENCODING ERROR HANDLING INTERFACE 448 //-////////////////////////////////////////////////////////////////////////// 449 /** create a UnicodeDecodeError object */ 450 PyObject* PyUnicodeDecodeError_Create( 451 const(char)* encoding, 452 const(char)* object, 453 Py_ssize_t length, 454 Py_ssize_t start, 455 Py_ssize_t end, 456 const(char)* reason); 457 458 /** create a UnicodeEncodeError object */ 459 PyObject* PyUnicodeEncodeError_Create( 460 const(char)* encoding, 461 Py_UNICODE* object, 462 Py_ssize_t length, 463 Py_ssize_t start, 464 Py_ssize_t end, 465 const(char)* reason); 466 467 /** create a UnicodeTranslateError object */ 468 PyObject* PyUnicodeTranslateError_Create( 469 Py_UNICODE* object, 470 Py_ssize_t length, 471 Py_ssize_t start, 472 Py_ssize_t end, 473 const(char)* reason); 474 475 /** get the encoding attribute */ 476 PyObject* PyUnicodeEncodeError_GetEncoding(PyObject*); 477 /// ditto 478 PyObject* PyUnicodeDecodeError_GetEncoding(PyObject*); 479 480 /** get the object attribute */ 481 PyObject* PyUnicodeEncodeError_GetObject(PyObject*); 482 /// ditto 483 PyObject* PyUnicodeDecodeError_GetObject(PyObject*); 484 /// ditto 485 PyObject* PyUnicodeTranslateError_GetObject(PyObject*); 486 487 /** get the value of the start attribute (the int * may not be NULL) 488 return 0 on success, -1 on failure */ 489 int PyUnicodeEncodeError_GetStart(PyObject*, Py_ssize_t*); 490 /// ditto 491 int PyUnicodeDecodeError_GetStart(PyObject*, Py_ssize_t*); 492 /// ditto 493 int PyUnicodeTranslateError_GetStart(PyObject*, Py_ssize_t*); 494 495 /** assign a new value to the start attribute 496 return 0 on success, -1 on failure */ 497 int PyUnicodeEncodeError_SetStart(PyObject*, Py_ssize_t); 498 /// ditto 499 int PyUnicodeDecodeError_SetStart(PyObject*, Py_ssize_t); 500 /// ditto 501 int PyUnicodeTranslateError_SetStart(PyObject* , Py_ssize_t); 502 503 /** get the value of the end attribute (the int *may not be NULL) 504 return 0 on success, -1 on failure */ 505 int PyUnicodeEncodeError_GetEnd(PyObject*, Py_ssize_t*); 506 /// ditto 507 int PyUnicodeDecodeError_GetEnd(PyObject*, Py_ssize_t*); 508 /// ditto 509 int PyUnicodeTranslateError_GetEnd(PyObject* , Py_ssize_t*); 510 511 /** assign a new value to the end attribute 512 return 0 on success, -1 on failure */ 513 int PyUnicodeEncodeError_SetEnd(PyObject*, Py_ssize_t); 514 /// ditto 515 int PyUnicodeDecodeError_SetEnd(PyObject*, Py_ssize_t); 516 /// ditto 517 int PyUnicodeTranslateError_SetEnd(PyObject*, Py_ssize_t); 518 519 /** get the value of the reason attribute */ 520 PyObject* PyUnicodeEncodeError_GetReason(PyObject*); 521 /// ditto 522 PyObject* PyUnicodeDecodeError_GetReason(PyObject*); 523 /// ditto 524 PyObject* PyUnicodeTranslateError_GetReason(PyObject*); 525 526 /** assign a new value to the reason attribute 527 return 0 on success, -1 on failure */ 528 int PyUnicodeEncodeError_SetReason(PyObject* exc, const(char)* reason); 529 /// ditto 530 int PyUnicodeDecodeError_SetReason(PyObject* exc, const(char)* reason); 531 /// ditto 532 int PyUnicodeTranslateError_SetReason(PyObject* exc, const(char)* reason); 533 534 /// _ 535 int PyOS_snprintf(char* str, size_t size, const(char)* format, ...); 536 /// _ 537 int PyOS_vsnprintf(char* str, size_t size, const(char)* format, va_list va); 538 539