66
77#include "compile.h"
88#include "frameobject.h"
9- #ifdef HAVE_EXPAT_H
109#include "expat.h"
11- #ifdef XML_MAJOR_VERSION
12- #define EXPAT_VERSION (0x10000 * XML_MAJOR_VERSION \
13- + 0x100 * XML_MINOR_VERSION \
14- + XML_MICRO_VERSION)
15- #else
16- /* Assume the oldest Expat that used expat.h and did not have version info */
17- #define EXPAT_VERSION 0x015f00
18- #endif
19- #else /* !defined(HAVE_EXPAT_H) */
20- #include "xmlparse.h"
21- /* Assume Expat 1.1 unless told otherwise */
22- #ifndef EXPAT_VERSION
23- #define EXPAT_VERSION 0x010100
24- #endif
25- #endif /* !defined(HAVE_EXPAT_H) */
2610
2711#ifndef PyGC_HEAD_SIZE
2812#define PyGC_HEAD_SIZE 0
@@ -52,20 +36,12 @@ enum HandlerTypes {
5236 DefaultHandlerExpand ,
5337 NotStandalone ,
5438 ExternalEntityRef ,
55- #if EXPAT_VERSION >= 0x010200
5639 StartDoctypeDecl ,
5740 EndDoctypeDecl ,
58- #endif
59- #if EXPAT_VERSION == 0x010200
60- ExternalParsedEntityDecl ,
61- InternalParsedEntityDecl ,
62- #endif
63- #if EXPAT_VERSION >= 0x015f00
6441 EntityDecl ,
6542 XmlDecl ,
6643 ElementDecl ,
6744 AttlistDecl ,
68- #endif
6945 _DummyDecl
7046};
7147
@@ -142,94 +118,7 @@ set_error(xmlparseobject *self)
142118}
143119
144120
145- #if EXPAT_VERSION == 0x010200
146- /* Convert an array of attributes and their values into a Python dict */
147-
148- static PyObject *
149- conv_atts_using_string (XML_Char * * atts )
150- {
151- PyObject * attrs_obj = NULL ;
152- XML_Char * * attrs_p , * * attrs_k = NULL ;
153- int attrs_len ;
154- PyObject * rv ;
155-
156- if ((attrs_obj = PyDict_New ()) == NULL )
157- goto finally ;
158- for (attrs_len = 0 , attrs_p = atts ;
159- * attrs_p ;
160- attrs_p ++ , attrs_len ++ ) {
161- if (attrs_len % 2 ) {
162- rv = PyString_FromString (* attrs_p );
163- if (!rv ) {
164- Py_DECREF (attrs_obj );
165- attrs_obj = NULL ;
166- goto finally ;
167- }
168- if (PyDict_SetItemString (attrs_obj ,
169- (char * )* attrs_k , rv ) < 0 ) {
170- Py_DECREF (attrs_obj );
171- attrs_obj = NULL ;
172- goto finally ;
173- }
174- Py_DECREF (rv );
175- }
176- else
177- attrs_k = attrs_p ;
178- }
179- finally :
180- return attrs_obj ;
181- }
182- #endif
183-
184121#ifdef Py_USING_UNICODE
185- #if EXPAT_VERSION == 0x010200
186- static PyObject *
187- conv_atts_using_unicode (XML_Char * * atts )
188- {
189- PyObject * attrs_obj ;
190- XML_Char * * attrs_p , * * attrs_k = NULL ;
191- int attrs_len ;
192-
193- if ((attrs_obj = PyDict_New ()) == NULL )
194- goto finally ;
195- for (attrs_len = 0 , attrs_p = atts ;
196- * attrs_p ;
197- attrs_p ++ , attrs_len ++ ) {
198- if (attrs_len % 2 ) {
199- PyObject * attr_str , * value_str ;
200- const char * p = (const char * ) (* attrs_k );
201- attr_str = PyUnicode_DecodeUTF8 (p , strlen (p ), "strict" );
202- if (!attr_str ) {
203- Py_DECREF (attrs_obj );
204- attrs_obj = NULL ;
205- goto finally ;
206- }
207- p = (const char * ) * attrs_p ;
208- value_str = PyUnicode_DecodeUTF8 (p , strlen (p ), "strict" );
209- if (!value_str ) {
210- Py_DECREF (attrs_obj );
211- Py_DECREF (attr_str );
212- attrs_obj = NULL ;
213- goto finally ;
214- }
215- if (PyDict_SetItem (attrs_obj , attr_str , value_str ) < 0 ) {
216- Py_DECREF (attrs_obj );
217- Py_DECREF (attr_str );
218- Py_DECREF (value_str );
219- attrs_obj = NULL ;
220- goto finally ;
221- }
222- Py_DECREF (attr_str );
223- Py_DECREF (value_str );
224- }
225- else
226- attrs_k = attrs_p ;
227- }
228- finally :
229- return attrs_obj ;
230- }
231- #endif
232-
233122/* Convert a string of XML_Chars into a Unicode string.
234123 Returns None if str is a null pointer. */
235124
@@ -537,7 +426,6 @@ VOID_HANDLER(UnparsedEntityDecl,
537426 STRING_CONV_FUNC ,systemId , STRING_CONV_FUNC ,publicId ,
538427 STRING_CONV_FUNC ,notationName ))
539428
540- #if EXPAT_VERSION >= 0x015f00
541429#ifndef Py_USING_UNICODE
542430VOID_HANDLER (EntityDecl ,
543431 (void * userData ,
@@ -650,7 +538,6 @@ VOID_HANDLER(AttlistDecl,
650538 STRING_CONV_FUNC ,elname , STRING_CONV_FUNC ,attname ,
651539 STRING_CONV_FUNC ,att_type , STRING_CONV_FUNC ,dflt ,
652540 isrequired ))
653- #endif
654541
655542VOID_HANDLER (NotationDecl ,
656543 (void * userData ,
@@ -726,41 +613,15 @@ RC_HANDLER(int, ExternalEntityRef,
726613
727614/* XXX UnknownEncodingHandler */
728615
729- #if EXPAT_VERSION == 0x010200
730- VOID_HANDLER (StartDoctypeDecl ,
731- (void * userData , const XML_Char * doctypeName ),
732- ("(O&OOi)" , STRING_CONV_FUNC ,doctypeName ,
733- Py_None , Py_None , -1 ))
734- #elif EXPAT_VERSION >= 0x015f00
735616VOID_HANDLER (StartDoctypeDecl ,
736617 (void * userData , const XML_Char * doctypeName ,
737618 const XML_Char * sysid , const XML_Char * pubid ,
738619 int has_internal_subset ),
739620 ("(O&O&O&i)" , STRING_CONV_FUNC ,doctypeName ,
740621 STRING_CONV_FUNC ,sysid , STRING_CONV_FUNC ,pubid ,
741622 has_internal_subset ))
742- #endif
743623
744- #if EXPAT_VERSION >= 0x010200
745624VOID_HANDLER (EndDoctypeDecl , (void * userData ), ("()" ))
746- #endif
747-
748- #if EXPAT_VERSION == 0x010200
749- VOID_HANDLER (ExternalParsedEntityDecl ,
750- (void * userData , const XML_Char * entityName ,
751- const XML_Char * base , const XML_Char * systemId ,
752- const XML_Char * publicId ),
753- ("(O&O&O&O&)" , STRING_CONV_FUNC , entityName ,
754- STRING_CONV_FUNC , base , STRING_CONV_FUNC , systemId ,
755- STRING_CONV_FUNC , publicId ))
756-
757- VOID_HANDLER (InternalParsedEntityDecl ,
758- (void * userData , const XML_Char * entityName ,
759- const XML_Char * replacementText , int replacementTextLength ),
760- ("(O&O&i)" , STRING_CONV_FUNC , entityName ,
761- STRING_CONV_FUNC , replacementText , replacementTextLength ))
762-
763- #endif /* Expat version 1.2 & better */
764625
765626/* ---------------------------------------------------------------- */
766627
@@ -924,7 +785,6 @@ xmlparse_GetBase(xmlparseobject *self, PyObject *args)
924785 return Py_BuildValue ("z" , XML_GetBase (self -> itself ));
925786}
926787
927- #if EXPAT_VERSION >= 0x015f00
928788static char xmlparse_GetInputContext__doc__ [] =
929789"GetInputContext() -> string\n\
930790Return the untranslated text of the input that caused the current event.\n\
@@ -956,7 +816,6 @@ xmlparse_GetInputContext(xmlparseobject *self, PyObject *args)
956816 }
957817 return result ;
958818}
959- #endif
960819
961820static char xmlparse_ExternalEntityParserCreate__doc__ [] =
962821"ExternalEntityParserCreate(context[, encoding])\n\
@@ -1033,8 +892,6 @@ xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args)
1033892 return (PyObject * )new_parser ;
1034893}
1035894
1036- #if EXPAT_VERSION >= 0x010200
1037-
1038895static char xmlparse_SetParamEntityParsing__doc__ [] =
1039896"SetParamEntityParsing(flag) -> success\n\
1040897Controls parsing of parameter entities (including the external DTD\n\
@@ -1053,8 +910,6 @@ xmlparse_SetParamEntityParsing(xmlparseobject *p, PyObject* args)
1053910 return PyInt_FromLong (flag );
1054911}
1055912
1056- #endif /* Expat version 1.2 or better */
1057-
1058913static struct PyMethodDef xmlparse_methods [] = {
1059914 {"Parse" , (PyCFunction )xmlparse_Parse ,
1060915 METH_VARARGS , xmlparse_Parse__doc__ },
@@ -1066,14 +921,10 @@ static struct PyMethodDef xmlparse_methods[] = {
1066921 METH_VARARGS , xmlparse_GetBase__doc__ },
1067922 {"ExternalEntityParserCreate" , (PyCFunction )xmlparse_ExternalEntityParserCreate ,
1068923 METH_VARARGS , xmlparse_ExternalEntityParserCreate__doc__ },
1069- #if EXPAT_VERSION >= 0x010200
1070924 {"SetParamEntityParsing" , (PyCFunction )xmlparse_SetParamEntityParsing ,
1071925 METH_VARARGS , xmlparse_SetParamEntityParsing__doc__ },
1072- #endif
1073- #if EXPAT_VERSION >= 0x015f00
1074926 {"GetInputContext" , (PyCFunction )xmlparse_GetInputContext ,
1075927 METH_VARARGS , xmlparse_GetInputContext__doc__ },
1076- #endif
1077928 {NULL , NULL } /* sentinel */
1078929};
1079930
@@ -1572,7 +1423,6 @@ MODULE_INITFUNC(void)
15721423 PyModule_AddObject (m , "XMLParserType" , (PyObject * ) & Xmlparsetype );
15731424
15741425 PyModule_AddObject (m , "__version__" , get_version_string ());
1575- #if EXPAT_VERSION >= 0x015f02
15761426 PyModule_AddStringConstant (m , "EXPAT_VERSION" ,
15771427 (char * ) XML_ExpatVersion ());
15781428 {
@@ -1581,7 +1431,6 @@ MODULE_INITFUNC(void)
15811431 Py_BuildValue ("(iii)" , info .major ,
15821432 info .minor , info .micro ));
15831433 }
1584- #endif
15851434#ifdef Py_USING_UNICODE
15861435 init_template_buffer ();
15871436#endif
@@ -1649,15 +1498,12 @@ MODULE_INITFUNC(void)
16491498
16501499#undef MYCONST
16511500
1652- #if EXPAT_VERSION >= 0x010200
16531501#define MYCONST (c ) PyModule_AddIntConstant(m, #c, c)
16541502 MYCONST (XML_PARAM_ENTITY_PARSING_NEVER );
16551503 MYCONST (XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE );
16561504 MYCONST (XML_PARAM_ENTITY_PARSING_ALWAYS );
16571505#undef MYCONST
1658- #endif
16591506
1660- #if EXPAT_VERSION >= 0x015f00
16611507#define MYCONST (c ) PyModule_AddIntConstant(model_module, #c, c)
16621508 PyModule_AddStringConstant (model_module , "__doc__" ,
16631509 "Constants used to interpret content model information." );
@@ -1674,7 +1520,6 @@ MODULE_INITFUNC(void)
16741520 MYCONST (XML_CQUANT_REP );
16751521 MYCONST (XML_CQUANT_PLUS );
16761522#undef MYCONST
1677- #endif
16781523}
16791524
16801525static void
@@ -1765,8 +1610,6 @@ pyxml_SetEndCdataSection(XML_Parser *parser, void *junk)
17651610 (pairsetter )XML_SetCdataSectionHandler );
17661611}
17671612
1768- #if EXPAT_VERSION >= 0x010200
1769-
17701613static void
17711614pyxml_SetStartDoctypeDeclHandler (XML_Parser * parser , void * junk )
17721615{
@@ -1783,8 +1626,6 @@ pyxml_SetEndDoctypeDeclHandler(XML_Parser *parser, void *junk)
17831626 (pairsetter )XML_SetDoctypeDeclHandler );
17841627}
17851628
1786- #endif
1787-
17881629statichere struct HandlerInfo handler_info [] = {
17891630 {"StartElementHandler" ,
17901631 pyxml_SetStartElementHandler ,
@@ -1831,23 +1672,12 @@ statichere struct HandlerInfo handler_info[] = {
18311672 {"ExternalEntityRefHandler" ,
18321673 (xmlhandlersetter )XML_SetExternalEntityRefHandler ,
18331674 (xmlhandler )my_ExternalEntityRefHandler },
1834- #if EXPAT_VERSION >= 0x010200
18351675 {"StartDoctypeDeclHandler" ,
18361676 pyxml_SetStartDoctypeDeclHandler ,
18371677 (xmlhandler )my_StartDoctypeDeclHandler },
18381678 {"EndDoctypeDeclHandler" ,
18391679 pyxml_SetEndDoctypeDeclHandler ,
18401680 (xmlhandler )my_EndDoctypeDeclHandler },
1841- #endif
1842- #if EXPAT_VERSION == 0x010200
1843- {"ExternalParsedEntityDeclHandler" ,
1844- (xmlhandlersetter )XML_SetExternalParsedEntityDeclHandler ,
1845- (xmlhandler )my_ExternalParsedEntityDeclHandler },
1846- {"InternalParsedEntityDeclHandler" ,
1847- (xmlhandlersetter )XML_SetInternalParsedEntityDeclHandler ,
1848- (xmlhandler )my_InternalParsedEntityDeclHandler },
1849- #endif
1850- #if EXPAT_VERSION >= 0x015f00
18511681 {"EntityDeclHandler" ,
18521682 (xmlhandlersetter )XML_SetEntityDeclHandler ,
18531683 (xmlhandler )my_EntityDeclHandler },
@@ -1860,7 +1690,6 @@ statichere struct HandlerInfo handler_info[] = {
18601690 {"AttlistDeclHandler" ,
18611691 (xmlhandlersetter )XML_SetAttlistDeclHandler ,
18621692 (xmlhandler )my_AttlistDeclHandler },
1863- #endif /* Expat version 1.95 or better */
18641693
18651694 {NULL , NULL , NULL } /* sentinel */
18661695};
0 commit comments