forked from go-python/cpy3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.go
126 lines (111 loc) · 5.52 KB
/
exceptions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
/*
#include "Python.h"
*/
import "C"
import (
"unsafe"
)
/*
All standard Python exceptions are available as global variables whose names are PyExc_ followed by the Python exception name.
These have the type PyObject*; they are all class objects.
*/
var (
PyExc_BaseException = togo(C.PyExc_BaseException)
PyExc_Exception = togo(C.PyExc_Exception)
PyExc_ArithmeticError = togo(C.PyExc_ArithmeticError)
PyExc_AssertionError = togo(C.PyExc_AssertionError)
PyExc_AttributeError = togo(C.PyExc_AttributeError)
PyExc_BlockingIOError = togo(C.PyExc_BlockingIOError)
PyExc_BrokenPipeError = togo(C.PyExc_BrokenPipeError)
PyExc_BufferError = togo(C.PyExc_BufferError)
PyExc_ChildProcessError = togo(C.PyExc_ChildProcessError)
PyExc_ConnectionAbortedError = togo(C.PyExc_ConnectionAbortedError)
PyExc_ConnectionError = togo(C.PyExc_ConnectionError)
PyExc_ConnectionRefusedError = togo(C.PyExc_ConnectionRefusedError)
PyExc_ConnectcionResetError = togo(C.PyExc_ConnectionResetError)
PyExc_EOFError = togo(C.PyExc_EOFError)
PyExc_FileExistsError = togo(C.PyExc_FileExistsError)
PyExc_FileNotFoundError = togo(C.PyExc_FileNotFoundError)
PyExc_FloatingPointError = togo(C.PyExc_FloatingPointError)
PyExc_GeneratorExit = togo(C.PyExc_GeneratorExit)
PyExc_ImportError = togo(C.PyExc_ImportError)
PyExc_IndentationError = togo(C.PyExc_IndentationError)
PyExc_IndexError = togo(C.PyExc_IndexError)
PyExc_InterruptedError = togo(C.PyExc_InterruptedError)
PyExc_IsADirectoryError = togo(C.PyExc_IsADirectoryError)
PyExc_KeyError = togo(C.PyExc_KeyError)
PyExc_KeyboardInterrupt = togo(C.PyExc_KeyboardInterrupt)
PyExc_LookupError = togo(C.PyExc_LookupError)
PyExc_MemoryError = togo(C.PyExc_MemoryError)
PyExc_ModuleNotFoundError = togo(C.PyExc_ModuleNotFoundError)
PyExc_NameError = togo(C.PyExc_NameError)
PyExc_NotADirectoryError = togo(C.PyExc_NotADirectoryError)
PyExc_NotImplementedError = togo(C.PyExc_NotImplementedError)
PyExc_OSError = togo(C.PyExc_OSError)
PyExc_OverflowError = togo(C.PyExc_OverflowError)
PyExc_PermissionError = togo(C.PyExc_PermissionError)
PyExc_ProcessLookupError = togo(C.PyExc_ProcessLookupError)
PyExc_RecursionError = togo(C.PyExc_RecursionError)
PyExc_ReferenceError = togo(C.PyExc_ReferenceError)
PyExc_RuntimeError = togo(C.PyExc_RuntimeError)
PyExc_StopAsyncIteration = togo(C.PyExc_StopAsyncIteration)
PyExc_StopIteration = togo(C.PyExc_StopIteration)
PyExc_SyntaxError = togo(C.PyExc_SyntaxError)
PyExc_SystemError = togo(C.PyExc_SystemError)
PyExc_SystemExit = togo(C.PyExc_SystemExit)
PyExc_TabError = togo(C.PyExc_TabError)
PyExc_TimeoutError = togo(C.PyExc_TimeoutError)
PyExc_TypeError = togo(C.PyExc_TypeError)
PyExc_UnboundLocalError = togo(C.PyExc_UnboundLocalError)
PyExc_UnicodeDecodeError = togo(C.PyExc_UnicodeDecodeError)
PyExc_UnicodeEncodeError = togo(C.PyExc_UnicodeEncodeError)
PyExc_UnicodeError = togo(C.PyExc_UnicodeError)
PyExc_UnicodeTranslateError = togo(C.PyExc_UnicodeTranslateError)
PyExc_ValueError = togo(C.PyExc_ValueError)
PyExc_ZeroDivisionError = togo(C.PyExc_ZeroDivisionError)
)
//PyErr_NewException : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NewException
func PyErr_NewException(name string, base, dict *PyObject) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PyErr_NewException(cname, toc(base), toc(dict)))
}
//PyErr_NewExceptionWithDoc : https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NewExceptionWithDoc
func PyErr_NewExceptionWithDoc(name, doc string, base, dict *PyObject) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cdoc := C.CString(doc)
defer C.free(unsafe.Pointer(cdoc))
return togo(C.PyErr_NewExceptionWithDoc(cname, cdoc, toc(base), toc(dict)))
}
//PyException_GetTraceback : https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetTraceback
func PyException_GetTraceback(ex *PyObject) *PyObject {
return togo(C.PyException_GetTraceback(toc(ex)))
}
//PyException_SetTraceback : https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetTraceback
func PyException_SetTraceback(ex, tb *PyObject) int {
return int(C.PyException_SetTraceback(toc(ex), toc(tb)))
}
//PyException_GetContext : https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetContext
func PyException_GetContext(ex *PyObject) *PyObject {
return togo(C.PyException_GetContext(toc(ex)))
}
//PyException_SetContext : https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetContext
func PyException_SetContext(ex, ctx *PyObject) {
C.PyException_SetContext(toc(ex), toc(ctx))
}
//PyException_GetCause : https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetCause
func PyException_GetCause(ex *PyObject) *PyObject {
return togo(C.PyException_GetCause(toc(ex)))
}
//PyException_SetCause : https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetCause
func PyException_SetCause(ex, cause *PyObject) {
C.PyException_SetCause(toc(ex), toc(cause))
}