Change the name of the exception from "pyexpat.error" to

"xml.parsers.expat.error", so it will reflect the public name of the
exception rather than the internal name.

Also change some of the initialization to use the new PyModule_Add*()
convenience functions.
This commit is contained in:
Fred Drake 2000-09-23 04:55:48 +00:00
parent 96ea196ea8
commit 93adb6918c

View File

@ -796,7 +796,7 @@ static char pyexpat_module_documentation[] =
/* Initialization function for the module */ /* Initialization function for the module */
DL_EXPORT(void) initpyexpat(void); /* supply a prototype */ void initpyexpat(void); /* avoid compiler warnings */
DL_EXPORT(void) DL_EXPORT(void)
initpyexpat(void) initpyexpat(void)
@ -818,29 +818,29 @@ initpyexpat(void)
(PyObject*)NULL, PYTHON_API_VERSION); (PyObject*)NULL, PYTHON_API_VERSION);
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
if (ErrorObject == NULL) if (ErrorObject == NULL)
ErrorObject = PyErr_NewException("pyexpat.error", NULL, NULL); ErrorObject = PyErr_NewException("xml.parsers.expat.error",
PyDict_SetItemString(d, "error", ErrorObject); NULL, NULL);
PyModule_AddObject(m, "error", ErrorObject);
PyDict_SetItemString(d, "__version__", PyModule_AddObject(m, "__version__",
PyString_FromStringAndSize(rev+11, PyString_FromStringAndSize(rev+11, strlen(rev+11)-2));
strlen(rev+11)-2));
/* XXX When Expat supports some way of figuring out how it was /* XXX When Expat supports some way of figuring out how it was
compiled, this should check and set native_encoding compiled, this should check and set native_encoding
appropriately. appropriately.
*/ */
PyDict_SetItemString(d, "native_encoding", PyModule_AddStringConstant(m, "native_encoding", "UTF-8");
PyString_FromString("UTF-8"));
d = PyModule_GetDict(m);
errors_module = PyDict_GetItem(d, errmod_name); errors_module = PyDict_GetItem(d, errmod_name);
if (errors_module == NULL) { if (errors_module == NULL) {
errors_module = PyModule_New("pyexpat.errors"); errors_module = PyModule_New("pyexpat.errors");
if (errors_module != NULL) { if (errors_module != NULL) {
sys_modules = PySys_GetObject("modules"); sys_modules = PySys_GetObject("modules");
PyDict_SetItemString(d, "errors", errors_module);
PyDict_SetItem(sys_modules, errmod_name, errors_module); PyDict_SetItem(sys_modules, errmod_name, errors_module);
/* gives away the reference to errors_module */
PyModule_AddObject(m, "errors", errors_module);
} }
} }
Py_DECREF(errmod_name); Py_DECREF(errmod_name);
@ -851,8 +851,8 @@ initpyexpat(void)
errors_dict = PyModule_GetDict(errors_module); errors_dict = PyModule_GetDict(errors_module);
#define MYCONST(name) \ #define MYCONST(name) \
PyDict_SetItemString(errors_dict, #name, \ PyModule_AddStringConstant(errors_module, #name, \
PyString_FromString(XML_ErrorString(name))) (char*)XML_ErrorString(name))
MYCONST(XML_ERROR_NO_MEMORY); MYCONST(XML_ERROR_NO_MEMORY);
MYCONST(XML_ERROR_SYNTAX); MYCONST(XML_ERROR_SYNTAX);
@ -873,6 +873,7 @@ initpyexpat(void)
MYCONST(XML_ERROR_MISPLACED_XML_PI); MYCONST(XML_ERROR_MISPLACED_XML_PI);
MYCONST(XML_ERROR_UNKNOWN_ENCODING); MYCONST(XML_ERROR_UNKNOWN_ENCODING);
MYCONST(XML_ERROR_INCORRECT_ENCODING); MYCONST(XML_ERROR_INCORRECT_ENCODING);
#undef MYCONST
} }
static void static void