本文整理汇总了C++中PyErr_NewException函数的典型用法代码示例。如果您正苦于以下问题:C++ PyErr_NewException函数的具体用法?C++ PyErr_NewException怎么用?C++ PyErr_NewException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyErr_NewException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyInit__gdbm
PyMODINIT_FUNC
PyInit__gdbm(void) {
PyObject *m, *d, *s;
if (PyType_Ready(&Dbmtype) < 0)
return NULL;
m = PyModule_Create(&_gdbmmodule);
if (m == NULL)
return NULL;
d = PyModule_GetDict(m);
DbmError = PyErr_NewException("_gdbm.error", PyExc_IOError, NULL);
if (DbmError != NULL) {
PyDict_SetItemString(d, "error", DbmError);
s = PyUnicode_FromString(dbmmodule_open_flags);
PyDict_SetItemString(d, "open_flags", s);
Py_DECREF(s);
}
return m;
}
示例2: initumemcache
PyMODINIT_FUNC
initumemcache(void)
{
PyObject* m;
m = Py_InitModule3("umemcache", methods, "");
if (m == NULL)
return;
ClientType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ClientType) < 0)
return;
Py_INCREF(&ClientType);
PyModule_AddObject(m, "Client", (PyObject *)&ClientType);
umemcache_MemcachedError = PyErr_NewException("umemcache.MemcachedError",
PyExc_RuntimeError, NULL);
PyModule_AddObject(m, "MemcachedError", (PyObject *)umemcache_MemcachedError);
}
示例3: initVmMngr
PyMODINIT_FUNC
initVmMngr(void)
{
PyObject *m;
if (PyType_Ready(&VmMngrType) < 0)
return;
m = Py_InitModule("VmMngr", VmMngr_Methods);
if (m == NULL)
return;
Vm_Mngr_Error = PyErr_NewException("VmMngr.error", NULL, NULL);
Py_INCREF(Vm_Mngr_Error);
PyModule_AddObject(m, "error", Vm_Mngr_Error);
Py_INCREF(&VmMngrType);
PyModule_AddObject(m, "Vm", (PyObject *)&VmMngrType);
}
示例4: PyModule_Create
PyObject *PyInit__minpack(void)
{
PyObject *m, *d, *s;
m = PyModule_Create(&moduledef);
import_array();
d = PyModule_GetDict(m);
s = PyUnicode_FromString(" 1.10 ");
PyDict_SetItemString(d, "__version__", s);
Py_DECREF(s);
minpack_error = PyErr_NewException ("minpack.error", NULL, NULL);
PyDict_SetItemString(d, "error", minpack_error);
if (PyErr_Occurred())
Py_FatalError("can't initialize module minpack");
return m;
}
示例5: initpyhook
PyMODINIT_FUNC
initpyhook(void) {
PyObject *m;
pyhook_StreetAddressLookupType.tp_members = StreetAddressLookup_members;
if (PyType_Ready(&pyhook_StreetAddressLookupType) < 0)
return;
m = Py_InitModule("pyhook", PyhookMethods);
if (m == NULL)
return;
PyhookError = PyErr_NewException("pyhook.error", NULL, NULL);
Py_INCREF(PyhookError);
PyModule_AddObject(m, "error", PyhookError);
Py_INCREF(&pyhook_StreetAddressLookupType);
PyModule_AddObject(m, "StreetAddressLookup", StreetAddressLookup_new(&pyhook_StreetAddressLookupType, NULL, NULL));
}
示例6: initrtaudio
PyMODINIT_FUNC
initrtaudio(void)
{
PyEval_InitThreads();
if (PyType_Ready(&RtAudio_type) < 0)
return;
PyObject* module = Py_InitModule3("rtaudio", NULL, "RtAudio wrapper.");
if (module == NULL)
return;
Py_INCREF(&RtAudio_type);
PyModule_AddObject(module, "RtAudio", (PyObject *)&RtAudio_type);
RtAudioError = PyErr_NewException("rtaudio.RtError", NULL, NULL);
Py_INCREF(RtAudioError);
PyModule_AddObject(module, "RtError", RtAudioError);
}
示例7: initrrdtool
/* Initialization function for the module */
void initrrdtool(
void)
{
PyObject *m, *d, *t;
/* Create the module and add the functions */
m = Py_InitModule("rrdtool", _rrdtool_methods);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
SET_STRCONSTANT(d, __version__);
ErrorObject = PyErr_NewException("rrdtool.error", NULL, NULL);
PyDict_SetItemString(d, "error", ErrorObject);
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize the rrdtool module");
}
示例8: initlibmtp
PyMODINIT_FUNC
initlibmtp(void) {
PyObject *m;
DeviceType.tp_new = PyType_GenericNew;
if (PyType_Ready(&DeviceType) < 0)
return;
m = Py_InitModule3("libmtp", libmtp_methods, "Interface to libmtp.");
if (m == NULL) return;
MTPError = PyErr_NewException("libmtp.MTPError", NULL, NULL);
if (MTPError == NULL) return;
PyModule_AddObject(m, "MTPError", MTPError);
// Redirect stdout to get rid of the annoying message about mtpz. Really,
// who designs a library without anyway to control/redirect the debugging
// output, and hardcoded paths that cannot be changed? Compiling libmtp without the crypt use flag disables mtpz support in libmtp
/* int bak, new; */
/* fprintf(stdout, "\n"); // This is needed, without it, for some odd reason the code below causes stdout to buffer all output after it is restored, rather than using line buffering, and setlinebuf does not work. */
/* fflush(stdout); */
/* bak = dup(STDOUT_FILENO); */
/* new = open("/dev/null", O_WRONLY); */
/* dup2(new, STDOUT_FILENO); */
/* close(new); */
LIBMTP_Init();
/* fflush(stdout); */
/* dup2(bak, STDOUT_FILENO); */
/* close(bak); */
LIBMTP_Set_Debug(LIBMTP_DEBUG_NONE);
Py_INCREF(&DeviceType);
PyModule_AddObject(m, "Device", (PyObject *)&DeviceType);
PyModule_AddStringMacro(m, LIBMTP_VERSION_STRING);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_NONE);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_PTP);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_PLST);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_USB);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_DATA);
PyModule_AddIntMacro(m, LIBMTP_DEBUG_ALL);
}
示例9: init_sophia
PyMODINIT_FUNC
init_sophia(void)
#endif
{
static char *sophia_constant_names[] = {"SPGT", "SPGTE", "SPLT", "SPLTE",
"SPCMP", "SPPAGE", "SPMERGEWM", "SPGC", "SPMERGE", "SPGCF", "SPGROW", NULL};
static int sophia_constant_values[] = {SPGT, SPGTE, SPLT, SPLTE,
SPCMP, SPPAGE, SPMERGEWM, SPGC, SPMERGE, SPGCF, SPGROW, 0};
if (PyType_Ready(&SophiaDBType) == -1)
return PSP_NOTHING;
SophiaError = PyErr_NewException("sophia.Error", NULL, NULL);
if (!SophiaError)
return PSP_NOTHING;
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&_sophiamodule);
#else
PyObject *module = Py_InitModule("_sophia", NULL);
#endif
if (!module)
return PSP_NOTHING;
char **names = sophia_constant_names;
int *values = sophia_constant_values;
while (*names) {
if (PyModule_AddIntConstant(module, *names++, *values++) == -1)
return PSP_NOTHING;
}
Py_INCREF(&SophiaDBType);
Py_INCREF(SophiaError);
if (PyModule_AddObject(module, "Database", (PyObject *)&SophiaDBType) == -1 ||
PyModule_AddObject(module, "Error", SophiaError) == -1)
return PSP_NOTHING;
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}
示例10: psyco_errors_init
static int
psyco_errors_init(void)
{
/* the names of the exceptions here reflect the organization of the
psycopg2 module and not the fact the the original error objects
live in _psycopg */
int i;
PyObject *dict = NULL;
PyObject *str = NULL;
int rv = -1;
/* 'Error' has been defined elsewhere: only init the other classes */
Error = (PyObject *)&errorType;
for (i = 1; exctable[i].name; i++) {
if (!(dict = PyDict_New())) { goto exit; }
if (exctable[i].docstr) {
if (!(str = Text_FromUTF8(exctable[i].docstr))) { goto exit; }
if (0 != PyDict_SetItemString(dict, "__doc__", str)) { goto exit; }
Py_CLEAR(str);
}
/* can't put PyExc_StandardError in the static exctable:
* windows build will fail */
if (!(*exctable[i].exc = PyErr_NewException(
exctable[i].name,
exctable[i].base ? *exctable[i].base : PyExc_StandardError,
dict))) {
goto exit;
}
Py_CLEAR(dict);
}
rv = 0;
exit:
Py_XDECREF(str);
Py_XDECREF(dict);
return rv;
}
示例11: initsound
initsound(void)
{
Py_Initialize();
PyObject *m= Py_InitModule(MODULE_NAME, pysound_methods);
// Initialize tables
PyModule_AddStringConstant(m, "__doc__", PYMODULEDOC );
PyModule_AddStringConstant(m, "version", PYSNDVERSION );
PyModule_AddIntConstant(m, "build", PYSNDBUILD );
_EXPORT_INT(m, AFMT_MU_LAW);
_EXPORT_INT(m, AFMT_A_LAW);
_EXPORT_INT(m, AFMT_IMA_ADPCM);
_EXPORT_INT(m, AFMT_U8);
_EXPORT_INT(m, AFMT_S16_LE);
_EXPORT_INT(m, AFMT_S16_BE);
_EXPORT_INT(m, AFMT_S8);
_EXPORT_INT(m, AFMT_U16_LE);
_EXPORT_INT(m, AFMT_U16_BE);
_EXPORT_INT(m, AFMT_MPEG);
_EXPORT_INT(m, AFMT_AC3);
_EXPORT_INT(m, AFMT_S16_NE);
g_cErr = PyErr_NewException(MODULE_NAME".SoundError", NULL, NULL);
if( g_cErr != NULL)
PyModule_AddObject(m, "SoundError", g_cErr );
PyISoundType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&PyISoundType);
PyModule_AddObject(m, INPUT_NAME, (PyObject *)&PyISoundType);
PySoundType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&PySoundType);
PyModule_AddObject(m, OUTPUT_NAME, (PyObject *)&PySoundType);
ResamplerType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&ResamplerType);
PyModule_AddObject(m, RESAMPLER_NAME, (PyObject *)&ResamplerType);
AnalyzerType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&AnalyzerType);
PyModule_AddObject(m, ANALYZER_NAME, (PyObject *)&AnalyzerType);
MixerType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&MixerType);
PyModule_AddObject(m, MIXER_NAME, (PyObject *)&MixerType);
}
示例12: PyInit_zlib
PyMODINIT_FUNC
PyInit_zlib(void)
{
PyObject *m, *ver;
Comptype.ob_type = &PyType_Type;
Decomptype.ob_type = &PyType_Type;
m = Py_InitModule4("zlib", zlib_methods,
zlib_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
if (m == NULL)
return;
ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (ZlibError != NULL) {
Py_INCREF(ZlibError);
PyModule_AddObject(m, "error", ZlibError);
}
PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS);
PyModule_AddIntConstant(m, "DEFLATED", DEFLATED);
PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL);
PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED);
PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION);
PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION);
PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED);
PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY);
PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY);
PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH);
PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH);
PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH);
PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH);
ver = PyString_FromString(ZLIB_VERSION);
if (ver != NULL)
PyModule_AddObject(m, "ZLIB_VERSION", ver);
PyModule_AddStringConstant(m, "__version__", "1.0");
#ifdef WITH_THREAD
zlib_lock = PyThread_allocate_lock();
#endif /* WITH_THREAD */
}
示例13: PyInit_cstuff
PyMODINIT_FUNC PyInit_cstuff(void) {
PyObject *module;
module = PyModule_Create(&cstuff_module);
if (module == NULL) {
return NULL;
}
if (PyType_Ready(&cstuff_DirectionMapType) < 0) {
return NULL;
}
CStuffError = PyErr_NewException("cstuff.CStuffError", NULL, NULL);
Py_INCREF(CStuffError);
PyModule_AddObject(module, "CStuffError", CStuffError);
Py_INCREF(&cstuff_DirectionMapType);
PyModule_AddObject(module, "DirectionMap", (PyObject *)&cstuff_DirectionMapType);
return module;
}
示例14: PyInit__simpleaudio
PyMODINIT_FUNC
PyInit__simpleaudio(void)
{
PyObject *m;
m = PyModule_Create(&_simpleaudio_module);
if (m == NULL)
return NULL;
sa_python_error = PyErr_NewException("_simpleaudio.SimpleaudioError", NULL, NULL);
Py_INCREF(sa_python_error);
PyModule_AddObject(m, "SimpleaudioError", sa_python_error);
/* initialize the list head mutex */
play_list_head.mutex = create_mutex();
dbg1("init'd list head at %p\n", &play_list_head);
return m;
}
示例15: initcd
initcd(void)
{
Py_Initialize();
g_iMaxCDROMIndex= -1;
PyObject *m = Py_InitModule("cd", pycd_methods);
PyModule_AddStringConstant( m, "__doc__", (char*)PYDOC );
PyModule_AddStringConstant( m, "version", (char*)PYCDVERSION );
PyModule_AddIntConstant( m, "build", PYCDBUILD );
INT_CONSTANT( SEEK_SET );
INT_CONSTANT( SEEK_END );
INT_CONSTANT( SEEK_CUR );
g_cErr = PyErr_NewException(MODULE_NAME".CDError", NULL, NULL);
if( g_cErr != NULL)
PyModule_AddObject(m, "CDError", g_cErr );
PyCDType.ob_type = &PyType_Type;
Py_INCREF((PyObject *)&PyCDType);
PyModule_AddObject(m, "CD", (PyObject *)&PyCDType);
}