Debian Codegraph @

src/main/c/jpy_verboseexcept.c

raw symbols SCIP
1 /*
2 * Copyright 2015 Brockmann Consult GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * This file was modified by Deephaven Data Labs.
17 *
18 */
19
20 #include <Python.h>
21 #include "jpy_verboseexcept.h"
22
23 int JPy_VerboseExceptions = 0;
24
25 PyObject* VerboseExceptions_New(void)
26 {
27 return PyObject_New(PyObject, &VerboseExceptions_Type);
28 }
29
30
31 PyObject* VerboseExceptions_getattro(PyObject* self, PyObject *attr_name)
32 {
33 if (strcmp(JPy_AS_UTF8(attr_name), "enabled") == 0) {
34 return PyBool_FromLong(JPy_VerboseExceptions);
35 } else {
36 return PyObject_GenericGetAttr(self, attr_name);
37 }
38 }
39
40
41 int VerboseExceptions_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
42 {
43 if (strcmp(JPy_AS_UTF8(attr_name), "enabled") == 0) {
44 if (PyBool_Check(v)) {
45 JPy_VerboseExceptions = v == Py_True;
46 } else {
47 PyErr_SetString(PyExc_ValueError, "value for 'flags' must be a boolean");
48 return -1;
49 }
50 return 0;
51 } else {
52 return PyObject_GenericSetAttr(self, attr_name, v);
53 }
54 }
55
56
57 PyTypeObject VerboseExceptions_Type =
58 {
59 PyVarObject_HEAD_INIT(NULL, 0)
60 "jpy.VerboseExceptions", /* tp_name */
61 sizeof (VerboseExceptions_Type), /* tp_basicsize */
62 0, /* tp_itemsize */
63 NULL, /* tp_dealloc */
64 0, /* tp_print */
65 NULL, /* tp_getattr */
66 NULL, /* tp_setattr */
67 NULL, /* tp_reserved */
68 NULL, /* tp_repr */
69 NULL, /* tp_as_number */
70 NULL, /* tp_as_sequence */
71 NULL, /* tp_as_mapping */
72 NULL, /* tp_hash */
73 NULL, /* tp_call */
74 NULL, /* tp_str */
75 (getattrofunc) VerboseExceptions_getattro, /* tp_getattro */
76 (setattrofunc) VerboseExceptions_setattro, /* tp_setattro */
77 NULL, /* tp_as_buffer */
78 Py_TPFLAGS_DEFAULT, /* tp_flags */
79 "Controls python exception verbosity", /* tp_doc */
80 NULL, /* tp_traverse */
81 NULL, /* tp_clear */
82 NULL, /* tp_richcompare */
83 0, /* tp_weaklistoffset */
84 NULL, /* tp_iter */
85 NULL, /* tp_iternext */
86 NULL, /* tp_methods */
87 NULL, /* tp_members */
88 NULL, /* tp_getset */
89 NULL, /* tp_base */
90 NULL, /* tp_dict */
91 NULL, /* tp_descr_get */
92 NULL, /* tp_descr_set */
93 0, /* tp_dictoffset */
94 (initproc) NULL, /* tp_init */
95 NULL, /* tp_alloc */
96 NULL, /* tp_new */
97 };