[Python-checkins] CVS: python/dist/src/Modules pyexpat.c,2.7,2.8

Fred L. Drake python-dev@python.org
Tue, 4 Jul 2000 16:51:33 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv13050

Modified Files:
	pyexpat.c 
Log Message:

pyexpat.errors is a *strange* module!

It gets initialized when pyexpat is imported, and is only accessible as an
attribute of pyexpat; it cannot be imported itself.  This allows it to at
least be importable after pyexpat itself has been imported by adding it
to sys.modules, so it is not quite as strange.

This arrangement needs to be better thought out.



Index: pyexpat.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pyexpat.c,v
retrieving revision 2.7
retrieving revision 2.8
diff -C2 -r2.7 -r2.8
*** pyexpat.c	2000/07/04 14:53:43	2.7
--- pyexpat.c	2000/07/04 23:51:31	2.8
***************
*** 841,853 ****
  initpyexpat(){
  	PyObject *m, *d;
!         char *rev="$Revision$";
  	PyObject *errors_module, *errors_dict;
  
! 	Xmlparsetype.ob_type = &PyType_Type;
  
  	/* Create the module and add the functions */
  	m = Py_InitModule4("pyexpat", pyexpat_methods,
! 		pyexpat_module_documentation,
! 		(PyObject*)NULL,PYTHON_API_VERSION);
  
  	/* Add some symbolic constants to the module */
--- 841,854 ----
  initpyexpat(){
  	PyObject *m, *d;
! 	char *rev = "$Revision$";
  	PyObject *errors_module, *errors_dict;
+ 	PyObject *sys_modules;
  
!         Xmlparsetype.ob_type = &PyType_Type;
  
  	/* Create the module and add the functions */
  	m = Py_InitModule4("pyexpat", pyexpat_methods,
! 			   pyexpat_module_documentation,
! 			   (PyObject*)NULL, PYTHON_API_VERSION);
  
  	/* Add some symbolic constants to the module */
***************
*** 856,865 ****
  	PyDict_SetItemString(d, "error", ErrorObject);
  
! 	PyDict_SetItemString(d,"__version__",
  			     PyString_FromStringAndSize(rev+11,
  							strlen(rev+11)-2));
  
! 	errors_module=PyModule_New( "errors" );
! 	PyDict_SetItemString(d,"errors", errors_module );
  
  	/* XXX When Expat supports some way of figuring out how it was
--- 857,868 ----
  	PyDict_SetItemString(d, "error", ErrorObject);
  
! 	PyDict_SetItemString(d, "__version__",
  			     PyString_FromStringAndSize(rev+11,
  							strlen(rev+11)-2));
  
! 	sys_modules = PySys_GetObject("modules");
! 	errors_module = PyModule_New("pyexpat.errors");
! 	PyDict_SetItemString(d, "errors", errors_module);
! 	PyDict_SetItemString(sys_modules, "pyexpat.errors", errors_module);
  
  	/* XXX When Expat supports some way of figuring out how it was
***************
*** 868,879 ****
  	*/
  	PyDict_SetItemString(d, "native_encoding", 
! 			     PyString_FromString("UTF-8") );
! 			     
! 	errors_dict=PyModule_GetDict( errors_module );
  
  #define MYCONST(name) \
  	PyDict_SetItemString(errors_dict, #name,  \
! 				PyString_FromString( XML_ErrorString(name)))
! 		
  	MYCONST(XML_ERROR_NO_MEMORY);
  	MYCONST(XML_ERROR_SYNTAX);
--- 871,881 ----
  	*/
  	PyDict_SetItemString(d, "native_encoding", 
! 			     PyString_FromString("UTF-8"));
! 	errors_dict = PyModule_GetDict(errors_module);
  
  #define MYCONST(name) \
  	PyDict_SetItemString(errors_dict, #name,  \
! 			     PyString_FromString(XML_ErrorString(name)))
! 
  	MYCONST(XML_ERROR_NO_MEMORY);
  	MYCONST(XML_ERROR_SYNTAX);
***************
*** 895,899 ****
  	MYCONST(XML_ERROR_UNKNOWN_ENCODING);
  	MYCONST(XML_ERROR_INCORRECT_ENCODING);
! 	
  	/* Check for errors */
  	if (PyErr_Occurred())
--- 897,901 ----
  	MYCONST(XML_ERROR_UNKNOWN_ENCODING);
  	MYCONST(XML_ERROR_INCORRECT_ENCODING);
! 
  	/* Check for errors */
  	if (PyErr_Occurred())
***************
*** 1031,1033 ****
  {NULL, NULL, NULL } /* sentinel */
  };
- 
--- 1033,1034 ----