summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/pyexpat.h45
-rw-r--r--Modules/pyexpat.c31
2 files changed, 76 insertions, 0 deletions
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
new file mode 100644
index 0000000..e54b16f
--- /dev/null
+++ b/Include/pyexpat.h
@@ -0,0 +1,45 @@
+/* Stuff to export relevant 'expat' entry points from pyexpat to other
+ * parser modules, such as cElementTree. */
+
+/* note: you must import expat.h before importing this module! */
+
+#define PyExpat_DISPATCH_MAGIC "pyexpat.dispatch 1.0"
+
+struct PyExpat_Dispatch
+{
+ int size; /* set to sizeof(struct PyExpat_Dispatch) */
+ int MAJOR_VERSION; /* XXX: use the ExpatVersionInfo instead? */
+ int MINOR_VERSION;
+ int MICRO_VERSION;
+ /* pointers to selected expat functions. add new functions at
+ the end, if needed */
+ const XML_LChar * (*ErrorString)(enum XML_Error code);
+ int (*GetCurrentColumnNumber)(XML_Parser parser);
+ int (*GetCurrentLineNumber)(XML_Parser parser);
+ enum XML_Status (*Parse)(
+ XML_Parser parser, const char *s, int len, int isFinal);
+ XML_Parser (*ParserCreate_MM)(
+ const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite,
+ const XML_Char *namespaceSeparator);
+ void (*ParserFree)(XML_Parser parser);
+ void (*SetCharacterDataHandler)(
+ XML_Parser parser, XML_CharacterDataHandler handler);
+ void (*SetCommentHandler)(
+ XML_Parser parser, XML_CommentHandler handler);
+ void (*SetDefaultHandlerExpand)(
+ XML_Parser parser, XML_DefaultHandler handler);
+ void (*SetElementHandler)(
+ XML_Parser parser, XML_StartElementHandler start,
+ XML_EndElementHandler end);
+ void (*SetNamespaceDeclHandler)(
+ XML_Parser parser, XML_StartNamespaceDeclHandler start,
+ XML_EndNamespaceDeclHandler end);
+ void (*SetProcessingInstructionHandler)(
+ XML_Parser parser, XML_ProcessingInstructionHandler handler);
+ void (*SetUnknownEncodingHandler)(
+ XML_Parser parser, XML_UnknownEncodingHandler handler,
+ void *encodingHandlerData);
+ void (*SetUserData)(XML_Parser parser, void *userData);
+ /* always add new stuff to the end! */
+};
+
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index d1def24..b59a51d 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -4,6 +4,8 @@
#include "frameobject.h"
#include "expat.h"
+#include "pyexpat.h"
+
#define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)
#ifndef PyDoc_STRVAR
@@ -1838,6 +1840,8 @@ MODULE_INITFUNC(void)
PyObject *modelmod_name;
PyObject *model_module;
PyObject *sys_modules;
+ static struct PyExpat_Dispatch dispatch;
+ PyObject* dispatch_object;
if (errmod_name == NULL)
return;
@@ -2011,6 +2015,33 @@ MODULE_INITFUNC(void)
MYCONST(XML_CQUANT_REP);
MYCONST(XML_CQUANT_PLUS);
#undef MYCONST
+
+ /* initialize pyexpat dispatch table */
+ dispatch.size = sizeof(dispatch);
+ dispatch.MAJOR_VERSION = XML_MAJOR_VERSION;
+ dispatch.MINOR_VERSION = XML_MINOR_VERSION;
+ dispatch.MICRO_VERSION = XML_MICRO_VERSION;
+ dispatch.ErrorString = XML_ErrorString;
+ dispatch.GetCurrentColumnNumber = XML_GetCurrentColumnNumber;
+ dispatch.GetCurrentLineNumber = XML_GetCurrentLineNumber;
+ dispatch.Parse = XML_Parse;
+ dispatch.ParserCreate_MM = XML_ParserCreate_MM;
+ dispatch.ParserFree = XML_ParserFree;
+ dispatch.SetCharacterDataHandler = XML_SetCharacterDataHandler;
+ dispatch.SetCommentHandler = XML_SetCommentHandler;
+ dispatch.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand;
+ dispatch.SetElementHandler = XML_SetElementHandler;
+ dispatch.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler;
+ dispatch.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler;
+ dispatch.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler;
+ dispatch.SetUserData = XML_SetUserData;
+
+ /* export as cobject */
+ dispatch_object = PyCObject_FromVoidPtrAndDesc(
+ &dispatch, PyExpat_DISPATCH_MAGIC, NULL
+ );
+ if (dispatch_object)
+ PyModule_AddObject(m, "dispatch", dispatch_object);
}
static void