Expose all per-error exception objects.
This commit is contained in:
parent
0e1c0b8204
commit
40dcb628c6
@ -984,7 +984,7 @@ static PyMethodDef PylibMC_functions[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC init_pylibmc(void) {
|
PyMODINIT_FUNC init_pylibmc(void) {
|
||||||
PyObject *module;
|
PyObject *module, *exc_objs;
|
||||||
PylibMC_Behavior *b;
|
PylibMC_Behavior *b;
|
||||||
PylibMC_McErr *err;
|
PylibMC_McErr *err;
|
||||||
char name[128];
|
char name[128];
|
||||||
@ -1024,14 +1024,22 @@ Oh, and: plankton.\n");
|
|||||||
PyModule_AddObject(module, "MemcachedError",
|
PyModule_AddObject(module, "MemcachedError",
|
||||||
(PyObject *)PylibMCExc_MemcachedError);
|
(PyObject *)PylibMCExc_MemcachedError);
|
||||||
|
|
||||||
|
exc_objs = PyList_New(0);
|
||||||
|
PyList_Append(exc_objs,
|
||||||
|
Py_BuildValue("sO", "Error", (PyObject *)PylibMCExc_MemcachedError));
|
||||||
|
|
||||||
for (err = PylibMCExc_mc_errs; err->name != NULL; err++) {
|
for (err = PylibMCExc_mc_errs; err->name != NULL; err++) {
|
||||||
char excnam[64];
|
char excnam[64];
|
||||||
strncpy(excnam, "_pylibmc.", 64);
|
strncpy(excnam, "_pylibmc.", 64);
|
||||||
strncat(excnam, err->name, 64);
|
strncat(excnam, err->name, 64);
|
||||||
err->exc = PyErr_NewException(excnam, PylibMCExc_MemcachedError, NULL);
|
err->exc = PyErr_NewException(excnam, PylibMCExc_MemcachedError, NULL);
|
||||||
PyModule_AddObject(module, err->name, (PyObject *)err->exc);
|
PyModule_AddObject(module, err->name, (PyObject *)err->exc);
|
||||||
|
PyList_Append(exc_objs,
|
||||||
|
Py_BuildValue("sO", err->name, (PyObject *)err->exc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyModule_AddObject(module, "exceptions", exc_objs);
|
||||||
|
|
||||||
Py_INCREF(&PylibMC_ClientType);
|
Py_INCREF(&PylibMC_ClientType);
|
||||||
PyModule_AddObject(module, "client", (PyObject *)&PylibMC_ClientType);
|
PyModule_AddObject(module, "client", (PyObject *)&PylibMC_ClientType);
|
||||||
|
|
||||||
|
@ -27,6 +27,14 @@ import _pylibmc
|
|||||||
__all__ = ["hashers", "distributions", "Client"]
|
__all__ = ["hashers", "distributions", "Client"]
|
||||||
__version__ = _pylibmc.__version__
|
__version__ = _pylibmc.__version__
|
||||||
|
|
||||||
|
errors = tuple(e for (n, e) in _pylibmc.exceptions)
|
||||||
|
# *Cough* Uhm, not the prettiest of things but this unpacks all exception
|
||||||
|
# objects and sets them on the very module object currently constructed.
|
||||||
|
import sys
|
||||||
|
modself = sys.modules[__name__]
|
||||||
|
for name, exc in _pylibmc.exceptions:
|
||||||
|
setattr(modself, name, exc)
|
||||||
|
|
||||||
hashers, hashers_rvs = {}, {}
|
hashers, hashers_rvs = {}, {}
|
||||||
distributions, distributions_rvs = {}, {}
|
distributions, distributions_rvs = {}, {}
|
||||||
# Not the prettiest way of doing things, but works well.
|
# Not the prettiest way of doing things, but works well.
|
||||||
|
Reference in New Issue
Block a user